Skip to content

Instantly share code, notes, and snippets.

@Syex
Created July 10, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Syex/766028eecb56bdb3fcf9fb7a8b4f4911 to your computer and use it in GitHub Desktop.
Save Syex/766028eecb56bdb3fcf9fb7a8b4f4911 to your computer and use it in GitHub Desktop.
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposePlaygroundTheme {
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
var name by remember { mutableStateOf<String?>("Hello World") }
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Greeting(name)
Button(onClick = {
name = if (name == null) "Hello World" else null
}) {
Text(text = "Change greeting")
}
}
}
}
}
}
}
@Composable
fun Greeting(name: String?) {
if (name != null) Text(text = name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment