Skip to content

Commit

Permalink
Merge pull request #406 from android/fm/basics_new_ui
Browse files Browse the repository at this point in the history
[Basics] Update to use new AS UI. Fixing bugs
  • Loading branch information
florina-muntenescu authored Dec 21, 2023
2 parents 95c5bed + 970625d commit 9cf1f16
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions BasicsCodelab/app/src/main/java/com/codelab/basics/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
Expand All @@ -68,9 +67,10 @@ class MainActivity : ComponentActivity() {

@Composable
fun MyApp(modifier: Modifier = Modifier) {

var shouldShowOnboarding by rememberSaveable { mutableStateOf(true) }

Surface(modifier, color = MaterialTheme.colorScheme.background) {
Surface(modifier) {
if (shouldShowOnboarding) {
OnboardingScreen(onContinueClicked = { shouldShowOnboarding = false })
} else {
Expand All @@ -84,19 +84,22 @@ fun OnboardingScreen(
onContinueClicked: () -> Unit,
modifier: Modifier = Modifier
) {

Column(
modifier = modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Welcome to the Basics Codelab!")
Button(
modifier = Modifier.padding(vertical = 24.dp),
modifier = Modifier
.padding(vertical = 24.dp),
onClick = onContinueClicked
) {
Text("Continue")
}
}

}

@Composable
Expand All @@ -112,20 +115,20 @@ private fun Greetings(
}

@Composable
private fun Greeting(name: String) {
private fun Greeting(name: String, modifier: Modifier = Modifier) {
Card(
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primary
),
modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp)
modifier = modifier.padding(vertical = 4.dp, horizontal = 8.dp)
) {
CardContent(name)
}
}

@Composable
private fun CardContent(name: String) {
var expanded by remember { mutableStateOf(false) }
var expanded by rememberSaveable { mutableStateOf(false) }

Row(
modifier = Modifier
Expand All @@ -151,7 +154,7 @@ private fun CardContent(name: String) {
if (expanded) {
Text(
text = ("Composem ipsum color sit lazy, " +
"padding theme elit, sed do bouncy. ").repeat(4),
"padding theme elit, sed do bouncy. ").repeat(4),
)
}
}
Expand All @@ -168,27 +171,29 @@ private fun CardContent(name: String) {
}
}


@Preview(showBackground = true, widthDp = 320, heightDp = 320)
@Composable
fun OnboardingPreview() {
BasicsCodelabTheme {
OnboardingScreen(onContinueClicked = {}) // Do nothing on click.
}
}

@Preview(
showBackground = true,
widthDp = 320,
uiMode = UI_MODE_NIGHT_YES,
name = "DefaultPreviewDark"
name = "GreetingPreviewDark"
)
@Preview(showBackground = true, widthDp = 320)
@Composable
fun DefaultPreview() {
fun GreetingPreview() {
BasicsCodelabTheme {
Greetings()
}
}

@Preview(showBackground = true, widthDp = 320, heightDp = 320)
@Composable
fun OnboardingPreview() {
BasicsCodelabTheme {
OnboardingScreen(onContinueClicked = {})
}
}

@Preview
@Composable
Expand Down

0 comments on commit 9cf1f16

Please sign in to comment.