Skip to content

Commit

Permalink
#1 - Reusing composables
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg3410 committed Jan 16, 2023
1 parent 54f0548 commit 35d2d9b
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
setContent {
BasicsCodelabTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
MyApp(modifier = Modifier.fillMaxSize())
}
}
}
}

@Composable
private fun MyApp(modifier: Modifier = Modifier) {
Surface(
modifier = modifier,
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}

@Composable
fun Greeting(name: String) {
Surface(color = MaterialTheme.colorScheme.primary) {
Surface(
color = MaterialTheme.colorScheme.primary
) {
Text(text = "Hello $name!", modifier = Modifier.padding(24.dp))
}
}
Expand All @@ -42,6 +48,6 @@ fun Greeting(name: String) {
@Composable
fun DefaultPreview() {
BasicsCodelabTheme {
Greeting("Android")
MyApp()
}
}

0 comments on commit 35d2d9b

Please sign in to comment.