Created
July 10, 2023 15:18
-
-
Save Syex/766028eecb56bdb3fcf9fb7a8b4f4911 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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