Skip to content

Commit 9cd390c

Browse files
authored
Merge pull request #684 from MaximillianLeonov/feature-settings
Replace `if` condition with AnimatedVisibility component
2 parents 97ea7a7 + bea3661 commit 9cd390c

File tree

1 file changed

+19
-14
lines changed
  • feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings

1 file changed

+19
-14
lines changed

feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
package com.google.samples.apps.nowinandroid.feature.settings
1818

1919
import android.content.Intent
20+
import androidx.compose.animation.AnimatedVisibility
2021
import androidx.compose.foundation.clickable
2122
import androidx.compose.foundation.layout.Arrangement
2223
import androidx.compose.foundation.layout.Column
24+
import androidx.compose.foundation.layout.ColumnScope
2325
import androidx.compose.foundation.layout.ExperimentalLayoutApi
2426
import androidx.compose.foundation.layout.FlowRow
2527
import androidx.compose.foundation.layout.Row
@@ -149,8 +151,9 @@ fun SettingsDialog(
149151
)
150152
}
151153

154+
// [ColumnScope] is used for using the [ColumnScope.AnimatedVisibility] extension overload composable.
152155
@Composable
153-
private fun SettingsPanel(
156+
private fun ColumnScope.SettingsPanel(
154157
settings: UserEditableSettings,
155158
supportDynamicColor: Boolean,
156159
onChangeThemeBrand: (themeBrand: ThemeBrand) -> Unit,
@@ -170,19 +173,21 @@ private fun SettingsPanel(
170173
onClick = { onChangeThemeBrand(ANDROID) },
171174
)
172175
}
173-
if (settings.brand == DEFAULT && supportDynamicColor) {
174-
SettingsDialogSectionTitle(text = stringResource(R.string.dynamic_color_preference))
175-
Column(Modifier.selectableGroup()) {
176-
SettingsDialogThemeChooserRow(
177-
text = stringResource(string.dynamic_color_yes),
178-
selected = settings.useDynamicColor,
179-
onClick = { onChangeDynamicColorPreference(true) },
180-
)
181-
SettingsDialogThemeChooserRow(
182-
text = stringResource(string.dynamic_color_no),
183-
selected = !settings.useDynamicColor,
184-
onClick = { onChangeDynamicColorPreference(false) },
185-
)
176+
AnimatedVisibility(visible = settings.brand == DEFAULT && supportDynamicColor) {
177+
Column {
178+
SettingsDialogSectionTitle(text = stringResource(R.string.dynamic_color_preference))
179+
Column(Modifier.selectableGroup()) {
180+
SettingsDialogThemeChooserRow(
181+
text = stringResource(string.dynamic_color_yes),
182+
selected = settings.useDynamicColor,
183+
onClick = { onChangeDynamicColorPreference(true) },
184+
)
185+
SettingsDialogThemeChooserRow(
186+
text = stringResource(string.dynamic_color_no),
187+
selected = !settings.useDynamicColor,
188+
onClick = { onChangeDynamicColorPreference(false) },
189+
)
190+
}
186191
}
187192
}
188193
SettingsDialogSectionTitle(text = stringResource(R.string.dark_mode_preference))

0 commit comments

Comments
 (0)