From 2e271076463ff7067a8ba71b40960f54ed46f896 Mon Sep 17 00:00:00 2001 From: Diogo Date: Wed, 4 Sep 2024 12:28:56 +0100 Subject: [PATCH] best case bars switching working --- .../main/java/chat/simplex/app/SimplexApp.kt | 8 +++--- .../chat/simplex/common/platform/Platform.kt | 2 +- .../common/views/chatlist/UserPicker.kt | 26 ++++++++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt index 297e7190bf..1c0502297c 100644 --- a/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt +++ b/apps/multiplatform/android/src/main/java/chat/simplex/app/SimplexApp.kt @@ -282,7 +282,7 @@ class SimplexApp: Application(), LifecycleEventObserver { isLight: Boolean, drawerShadingColor: Animatable, toolbarOnTop: Boolean, - changeNavBarColor: (originalColor: Color) -> Color, + navBarColor: Color, ) { val window = mainActivity.get()?.window ?: return @@ -292,16 +292,16 @@ class SimplexApp: Application(), LifecycleEventObserver { val colors = CurrentColors.value.colors val baseBackgroundColor = if (toolbarOnTop) colors.background.mixWith(colors.onBackground, 0.97f) else colors.background window.statusBarColor = baseBackgroundColor.mixWith(drawerShadingColor.value.copy(1f), 1 - drawerShadingColor.value.alpha).toArgb() - - val navBar = changeNavBarColor(Color(window.navigationBarColor)).toArgb() + val navBar = navBarColor.toArgb() if (window.navigationBarColor != navBar) { window.navigationBarColor = navBar } + if (windowInsetController?.isAppearanceLightNavigationBars != isLight) { windowInsetController?.isAppearanceLightNavigationBars = isLight } - } + } override fun androidSetStatusAndNavBarColors(isLight: Boolean, backgroundColor: Color, hasTop: Boolean, hasBottom: Boolean) { val window = mainActivity.get()?.window ?: return diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt index cf1707feb3..92bc4212cc 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/Platform.kt @@ -21,7 +21,7 @@ interface PlatformInterface { fun androidIsBackgroundCallAllowed(): Boolean = true fun androidSetNightModeIfSupported() {} fun androidSetStatusAndNavBarColors(isLight: Boolean, backgroundColor: Color, hasTop: Boolean, hasBottom: Boolean) {} - fun androidSetDrawerStatusAndNavBarColor(isLight: Boolean, drawerShadingColor: Animatable, toolbarOnTop: Boolean, changeNavBarColor: (originalColor: Color) -> Color) {} + fun androidSetDrawerStatusAndNavBarColor(isLight: Boolean, drawerShadingColor: Animatable, toolbarOnTop: Boolean, navBarColor: Color) {} fun androidStartCallActivity(acceptCall: Boolean, remoteHostId: Long? = null, chatId: ChatId? = null) {} fun androidPictureInPictureAllowed(): Boolean = true fun androidCallEnded() {} diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt index b80b82144e..b0db827ab9 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chatlist/UserPicker.kt @@ -35,6 +35,7 @@ import chat.simplex.common.views.helpers.* import chat.simplex.common.platform.* import chat.simplex.common.views.CreateProfile import chat.simplex.common.views.newchat.* +import chat.simplex.common.views.onboarding.OnboardingStage import chat.simplex.common.views.remote.* import chat.simplex.common.views.usersettings.* import chat.simplex.common.views.usersettings.AppearanceScope.ColorModeSwitcher @@ -389,18 +390,23 @@ fun UserPicker( val toColor = if (colors.isLight) colors.onSurface.copy(alpha = ScrimOpacity) else Color.Black.copy(0.64f) animatedColor.animateTo(if (newChat.isVisible()) toColor else Color.Transparent, newChatSheetAnimSpec()) { - if (newChat.isVisible() || newChat.isHiding()) { + if (newChat.isVisible()) { platform.androidSetDrawerStatusAndNavBarColor( - isLight = CurrentColors.value.colors.isLight, - drawerShadingColor = animatedColor, + isLight = colors.isLight, + drawerShadingColor = animatedColor, toolbarOnTop = !appPrefs.oneHandUI.get(), - changeNavBarColor = { c -> - val onc = originalNavColor.value - if (onc == null) { - originalNavColor.value = c - } - if (newChat.isVisible()) colors.surface else onc ?: colors.background.mixWith(colors.onBackground, 0.97f) - }, + navBarColor = colors.surface + ) + } else if (newChat.isHiding()) { + platform.androidSetDrawerStatusAndNavBarColor( + isLight = colors.isLight, + drawerShadingColor = animatedColor, + toolbarOnTop = !appPrefs.oneHandUI.get(), + navBarColor = (if (appPrefs.oneHandUI.get() && appPrefs.onboardingStage.get() == OnboardingStage.OnboardingComplete) { + colors.background.mixWith(CurrentColors.value.colors.onBackground, 0.97f) + } else { + colors.background + }) ) } }