From a29ec774e800f1d3c3e627899461e975b029e7ec Mon Sep 17 00:00:00 2001 From: Diogo Date: Wed, 4 Sep 2024 12:12:43 +0100 Subject: [PATCH] improvements on status and nav color set --- .../main/java/chat/simplex/app/SimplexApp.kt | 27 +++++++++++++------ .../chat/simplex/common/platform/Platform.kt | 2 +- .../common/views/chatlist/UserPicker.kt | 21 +++++++++------ 3 files changed, 33 insertions(+), 17 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 340b3fcf98..297e7190bf 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 @@ -11,6 +11,7 @@ import android.content.pm.ActivityInfo import android.os.* import android.view.View import androidx.compose.animation.core.* +import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.graphics.Color @@ -277,18 +278,28 @@ class SimplexApp: Application(), LifecycleEventObserver { uiModeManager.setApplicationNightMode(mode) } - override fun androidSetStatusBarColor(isLight: Boolean, animatedColor: Animatable) { + override fun androidSetDrawerStatusAndNavBarColor( + isLight: Boolean, + drawerShadingColor: Animatable, + toolbarOnTop: Boolean, + changeNavBarColor: (originalColor: Color) -> Color, + ) { val window = mainActivity.get()?.window ?: return @Suppress("DEPRECATION") val windowInsetController = ViewCompat.getWindowInsetsController(window.decorView) - // Animate to the target color - //animatedColor.animateTo(targetColor, spec) - // Set the status bar color to the animated color - window.statusBarColor = CurrentColors.value.colors.background.mixWith(animatedColor.value.copy(1f), 1 - animatedColor.value.alpha).toArgb() - // Update light status bar appearance if necessary - if (windowInsetController?.isAppearanceLightStatusBars != isLight) { - windowInsetController?.isAppearanceLightStatusBars = isLight + // Blend status bar color to the animated color + 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() + + if (window.navigationBarColor != navBar) { + window.navigationBarColor = navBar + } + if (windowInsetController?.isAppearanceLightNavigationBars != isLight) { + windowInsetController?.isAppearanceLightNavigationBars = isLight } } 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 9897011fc7..cf1707feb3 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 androidSetStatusBarColor(isLight: Boolean, animatedColor: Animatable) {} + fun androidSetDrawerStatusAndNavBarColor(isLight: Boolean, drawerShadingColor: Animatable, toolbarOnTop: Boolean, changeNavBarColor: (originalColor: Color) -> 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 ecda8bd3dc..b80b82144e 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 @@ -379,6 +379,8 @@ fun UserPicker( ) } + val originalNavColor = mutableStateOf(null) + LaunchedEffect(Unit) { launch { userPickerState.collect { @@ -387,15 +389,18 @@ 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()) { - platform.androidSetStatusAndNavBarColors(colors.isLight, colors.surface, !appPrefs.oneHandUI.get(), false) - } else { - platform.androidSetStatusAndNavBarColors(colors.isLight, colors.background, !appPrefs.oneHandUI.get(), appPrefs.oneHandUI.get()) - } if (newChat.isVisible() || newChat.isHiding()) { - platform.androidSetStatusBarColor( - CurrentColors.value.colors.isLight, - animatedColor + platform.androidSetDrawerStatusAndNavBarColor( + isLight = CurrentColors.value.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) + }, ) } }