Bug 1927882 - part 3 - Don't theme the system bars while in custom tabs if navbar is enabled r=android-reviewers,tchoh,harrisono

Needed to also add the default toolbar color as the default OS navigation bar color
to ensure that we have a proper default if system bars' backgrounds are not updated.

Differential Revision: https://phabricator.services.mozilla.com/D229495
This commit is contained in:
Mugurell 2024-11-20 08:37:26 +00:00
parent f4caf42c5f
commit 6979182bd9
4 changed files with 8 additions and 108 deletions

View File

@ -13,7 +13,6 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.appcompat.app.AppCompatDelegate.NightMode
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
@ -209,24 +208,16 @@ class CustomTabsToolbarFeature(
)
}
when (customTabsColorsConfig.updateStatusBarColor) {
true -> toolbarColor?.let { window?.setStatusBarTheme(it) }
false -> window?.setStatusBarTheme(getDefaultSystemBarsColor())
if (customTabsColorsConfig.updateStatusBarColor && toolbarColor != null) {
window?.setStatusBarTheme(toolbarColor)
}
when (customTabsColorsConfig.updateSystemNavigationBarColor) {
true -> {
// Update navigation bar colors with custom tabs specified ones or keep the current colors.
if (navigationBarColor != null || navigationBarDividerColor != null) {
window?.setNavigationBarTheme(navigationBarColor, navigationBarDividerColor)
}
}
false -> window?.setNavigationBarTheme(getDefaultSystemBarsColor())
val areNavigationBarColorsAvailable = navigationBarColor != null || navigationBarDividerColor != null
if (customTabsColorsConfig.updateSystemNavigationBarColor && areNavigationBarColorsAvailable) {
window?.setNavigationBarTheme(navigationBarColor, navigationBarDividerColor)
}
}
private fun getDefaultSystemBarsColor() = ContextCompat.getColor(context, android.R.color.black)
/**
* Display a close button at the start of the toolbar.
* When clicked, it calls [closeListener].

View File

@ -377,99 +377,6 @@ class CustomTabsToolbarFeatureTest {
}
}
@Ignore("Failures on SDK 35. Fix and re-enable in bug 1929237.")
@Suppress("DEPRECATION")
@Test
fun `GIVEN changing the system navigation bar color is enabled WHEN customizing the UI for a custom tab THEN change the system navigation bar color`() {
val tab = createCustomTab(
"https://www.mozilla.org",
id = "mozilla",
config = CustomTabConfig(
colorSchemes = ColorSchemes(
defaultColorSchemeParams = ColorSchemeParams(toolbarColor = Color.BLUE),
),
),
)
val store = BrowserStore(
BrowserState(
customTabs = listOf(tab),
),
)
val toolbar = BrowserToolbar(testContext)
val useCases = CustomTabsUseCases(
store = store,
loadUrlUseCase = SessionUseCases(store).loadUrl,
)
val window: Window = mock()
`when`(window.decorView).thenReturn(mock())
`when`(window.context).thenReturn(testContext)
`when`(window.insetsController).thenReturn(mock())
run {
val feature = CustomTabsToolbarFeature(
store,
toolbar,
sessionId = "mozilla",
useCases = useCases,
window = window,
customTabsColorsConfig = CustomTabsColorsConfig(
updateSystemNavigationBarColor = true,
),
) {}
feature.init(tab.config)
verify(window).navigationBarColor = Color.BLUE
}
}
@Suppress("DEPRECATION")
@Test
fun `GIVEN changing the system navigation bar color is disabled WHEN customizing the UI for a custom tab THEN don't change the system navigation bar color`() {
val tab = createCustomTab(
"https://www.mozilla.org",
id = "mozilla",
config = CustomTabConfig(
colorSchemes = ColorSchemes(
defaultColorSchemeParams = ColorSchemeParams(toolbarColor = Color.BLUE),
),
),
)
val store = BrowserStore(
BrowserState(
customTabs = listOf(tab),
),
)
val toolbar = BrowserToolbar(testContext)
val useCases = CustomTabsUseCases(
store = store,
loadUrlUseCase = SessionUseCases(store).loadUrl,
)
val window: Window = mock()
`when`(window.decorView).thenReturn(mock())
`when`(window.context).thenReturn(testContext)
`when`(window.insetsController).thenReturn(mock())
run {
val feature = CustomTabsToolbarFeature(
store,
toolbar,
sessionId = "mozilla",
useCases = useCases,
window = window,
customTabsColorsConfig = CustomTabsColorsConfig(
updateSystemNavigationBarColor = false,
),
) {}
feature.init(tab.config)
verify(window, never()).navigationBarColor = Color.BLUE
}
}
@Test
fun `adds close button`() {
val tab = createCustomTab("https://www.mozilla.org", id = "mozilla", config = CustomTabConfig())

View File

@ -151,7 +151,7 @@ class CustomTabsIntegration(
private fun getCustomTabsColorsConfig() = when (activity.settings().navigationToolbarEnabled) {
true -> CustomTabsColorsConfig(
updateStatusBarColor = !isPrivate,
updateStatusBarColor = false,
updateSystemNavigationBarColor = false,
updateToolbarsColor = false,
)

View File

@ -28,6 +28,8 @@
<item name="android:windowAnimationStyle">@style/WindowAnimationTransition</item>
<item name="android:progressBarStyleHorizontal">@style/progressBarStyleHorizontal</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">?attr/layer1</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:windowBackground">@color/fx_mobile_layer_color_1</item>
<item name="android:colorEdgeEffect">@color/accent_normal_theme</item>
<item name="android:colorAccent">@color/fx_mobile_text_color_primary</item>