google-developer-training / basic-android-kotlin-compose-training-tip-calculator

Apache License 2.0
61 stars 93 forks source link

Calculate a custom tip: Android Basics with Compose #230

Open BurtCrepeault opened 1 month ago

BurtCrepeault commented 1 month ago

[URL of codelab] (https://developer.android.com/codelabs/basic-android-kotlin-compose-calculate-tip)

In which task and step of the codelab can this issue be found? Step 6: Add a switch - Task #8

Describe the problem When strictly copied from the codelab, this step produces misaligned Text and Switch composables, even though their parent Row has a verticalAlignement argument. See Screenshot1.

This appears due to the modifier used in the Switch element, passed as an argument in the RoundTheTipRow() function. The modifier, which has a non-zero bottom padding value, is set in the call to the function inside TipTimeLayout().

Using a default modifier, like in the code below, fixes the problem:

Switch ( checked = roundUp, onCheckedChange = onRoundUpChanged, modifier = Modifier .fillMaxWidth() .wrapContentWidth(Alignment.End) )

Steps to reproduce? Follow the codelab up to step 6, task 12, and run the app in an emulator (same results can be seen in preview)

Versions Android Studio version: Android Studio Koala | 2024.1.1 Patch 2 API version of the emulator: Google Pixel 7 Android 14.0 ("UpsideDownCake")

Additional information Screenshot1

I did not check if the solution code provided is correct or contains the same mistake.