For #22558 - Fix private theme bug in Tabs Tray

This commit is contained in:
Noah Bond 2022-08-08 14:52:28 -07:00 committed by mergify[bot]
parent f03ee91ecb
commit a77375a363
5 changed files with 24 additions and 7 deletions

View File

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import androidx.savedstate.SavedStateRegistryOwner
import androidx.savedstate.ViewTreeSavedStateRegistryOwner
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme
/**
* [RecyclerView.ViewHolder] used for Jetpack Compose UI content .
@ -31,12 +32,17 @@ abstract class ComposeViewHolder(
@Composable
abstract fun Content()
/**
* Optional override used to disable private browsing theming and only obey dark/light theming.
*/
open val allowPrivateTheme: Boolean = true
init {
composeView.setViewCompositionStrategy(
ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed
)
composeView.setContent {
FirefoxTheme {
FirefoxTheme(theme = Theme.getTheme(allowPrivateTheme = allowPrivateTheme)) {
Content()
}
}

View File

@ -80,6 +80,9 @@ class InactiveTabViewHolder(
}
}
override val allowPrivateTheme: Boolean
get() = false
private fun showConfirmationSnackbar() {
val context = composeView.context
val text = context.getString(R.string.inactive_tabs_auto_close_message_snackbar)

View File

@ -15,6 +15,7 @@ import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.tabstray.SelectableTabViewHolder
import org.mozilla.fenix.compose.ComposeViewHolder
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme
/**
* [RecyclerView.ViewHolder] used for Jetpack Compose UI content .
@ -24,7 +25,7 @@ import org.mozilla.fenix.theme.FirefoxTheme
*/
abstract class ComposeAbstractTabViewHolder(
private val composeView: ComposeView,
private val viewLifecycleOwner: LifecycleOwner
private val viewLifecycleOwner: LifecycleOwner,
) : SelectableTabViewHolder(composeView) {
/**
@ -38,7 +39,7 @@ abstract class ComposeAbstractTabViewHolder(
*/
fun bind(tab: TabSessionState) {
composeView.setContent {
FirefoxTheme {
FirefoxTheme(theme = Theme.getTheme(allowPrivateTheme = tab.content.private)) {
Content(tab)
}
}

View File

@ -10,10 +10,11 @@ import androidx.recyclerview.widget.RecyclerView
import mozilla.components.lib.state.ext.observeAsComposableState
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.tabstray.NavigationInteractor
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.TabsTrayState
import org.mozilla.fenix.tabstray.TabsTrayStore
import org.mozilla.fenix.tabstray.syncedtabs.SyncedTabsList
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.theme.Theme
/**
* Temporary ViewHolder to render [SyncedTabsList] until all of the Tabs Tray is written in Compose.
@ -31,7 +32,7 @@ class SyncedTabsPageViewHolder(
fun bind() {
composeView.setContent {
val tabs = tabsTrayStore.observeAsComposableState { state -> state.syncedTabs }.value
FirefoxTheme {
FirefoxTheme(theme = Theme.getTheme(allowPrivateTheme = false)) {
SyncedTabsList(
syncedTabs = tabs ?: emptyList(),
taskContinuityEnabled = composeView.context.settings().enableTaskContinuityEnhancements,

View File

@ -34,11 +34,17 @@ enum class Theme {
/**
* Returns the current [Theme] that is displayed.
*
* @param allowPrivateTheme Boolean used to control whether [Theme.Private] is an option
* for [FirefoxTheme] colors.
*
* @return the current [Theme] that is displayed.
*/
@Composable
fun getTheme() =
if (!inComposePreview && LocalContext.current.settings().lastKnownMode.isPrivate) {
fun getTheme(allowPrivateTheme: Boolean = true) =
if (allowPrivateTheme &&
!inComposePreview &&
LocalContext.current.settings().lastKnownMode.isPrivate
) {
Private
} else if (isSystemInDarkTheme()) {
Dark