For #22558 - Fix private theme bug in Tabs Tray
This commit is contained in:
parent
f03ee91ecb
commit
a77375a363
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue