Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #22558 - Fix private theme bug in Tabs Tray
Browse files Browse the repository at this point in the history
  • Loading branch information
MozillaNoah authored and mergify[bot] committed Aug 9, 2022
1 parent f03ee91 commit a77375a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand All @@ -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) {

/**
Expand All @@ -38,7 +39,7 @@ abstract class ComposeAbstractTabViewHolder(
*/
fun bind(tab: TabSessionState) {
composeView.setContent {
FirefoxTheme {
FirefoxTheme(theme = Theme.getTheme(allowPrivateTheme = tab.content.private)) {
Content(tab)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/org/mozilla/fenix/theme/FirefoxTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a77375a

Please sign in to comment.