From 6c18b25d5d9c37c03ddb63230d7ed89c29c39fe0 Mon Sep 17 00:00:00 2001 From: Maximillian Leonov <91663102+MaximillianLeonov@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:31:57 +0400 Subject: [PATCH 1/2] Replace `if` condition with AnimatedVisibility component --- .../feature/settings/SettingsDialog.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt index 847493a83..504fee4fe 100644 --- a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt +++ b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt @@ -18,8 +18,10 @@ package com.google.samples.apps.nowinandroid.feature.settings import android.content.Intent import android.net.Uri +import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -149,7 +151,7 @@ fun SettingsDialog( } @Composable -private fun SettingsPanel( +private fun ColumnScope.SettingsPanel( settings: UserEditableSettings, supportDynamicColor: Boolean, onChangeThemeBrand: (themeBrand: ThemeBrand) -> Unit, @@ -169,19 +171,21 @@ private fun SettingsPanel( onClick = { onChangeThemeBrand(ANDROID) }, ) } - if (settings.brand == DEFAULT && supportDynamicColor) { - SettingsDialogSectionTitle(text = stringResource(R.string.dynamic_color_preference)) - Column(Modifier.selectableGroup()) { - SettingsDialogThemeChooserRow( - text = stringResource(string.dynamic_color_yes), - selected = settings.useDynamicColor, - onClick = { onChangeDynamicColorPreference(true) }, - ) - SettingsDialogThemeChooserRow( - text = stringResource(string.dynamic_color_no), - selected = !settings.useDynamicColor, - onClick = { onChangeDynamicColorPreference(false) }, - ) + AnimatedVisibility(visible = settings.brand == DEFAULT && supportDynamicColor) { + Column { + SettingsDialogSectionTitle(text = stringResource(R.string.dynamic_color_preference)) + Column(Modifier.selectableGroup()) { + SettingsDialogThemeChooserRow( + text = stringResource(string.dynamic_color_yes), + selected = settings.useDynamicColor, + onClick = { onChangeDynamicColorPreference(true) }, + ) + SettingsDialogThemeChooserRow( + text = stringResource(string.dynamic_color_no), + selected = !settings.useDynamicColor, + onClick = { onChangeDynamicColorPreference(false) }, + ) + } } } SettingsDialogSectionTitle(text = stringResource(R.string.dark_mode_preference)) From 7dadf033c153e1706bb48c839ef3149762e2d229 Mon Sep 17 00:00:00 2001 From: Maximillian Leonov Date: Thu, 1 Jun 2023 11:14:04 +0400 Subject: [PATCH 2/2] Add comment for ColumnScope usage --- .../samples/apps/nowinandroid/feature/settings/SettingsDialog.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt index 504fee4fe..959d17797 100644 --- a/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt +++ b/feature/settings/src/main/java/com/google/samples/apps/nowinandroid/feature/settings/SettingsDialog.kt @@ -150,6 +150,7 @@ fun SettingsDialog( ) } +// [ColumnScope] is used for using the [ColumnScope.AnimatedVisibility] extension overload composable. @Composable private fun ColumnScope.SettingsPanel( settings: UserEditableSettings,