Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/theming issues #1575

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class AppearanceSettingsViewModel @Inject constructor(private val prefs: TextSec
prefs.setAccentColorStyle(newAccentColorStyle)
// update UI state
_uiState.value = prefs.themeState()

// force compose to refresh its style reference
selectedTheme = null
}

fun setNewStyle(newThemeStyle: String) {
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/org/thoughtcrime/securesms/ui/theme/Themes.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.ui.theme

import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
Expand All @@ -20,7 +21,12 @@ import org.session.libsession.utilities.AppTextSecurePreferences
val LocalColors = compositionLocalOf <ThemeColors> { ClassicDark() }
val LocalType = compositionLocalOf { sessionTypography }

// Once the app is entirely in Compose we won't need these two properties since we'll have
// a single root composable which will get the theme as a state and update the app accordingly
// without having to keep track of these flags, which are sure to cause syncing issues...
// We can remove them once we have a unique Composable root or once we use the sharedPrefs as flows (PR in review)
var selectedTheme: ThemeColors? = null
var systemInDark: Boolean? = null

/**
* Apply a Material2 compose theme based on user selections in SharedPreferences.
Expand All @@ -29,14 +35,20 @@ var selectedTheme: ThemeColors? = null
fun SessionMaterialTheme(
content: @Composable () -> Unit
) {
val context = LocalContext.current
val preferences = AppTextSecurePreferences(context)

// set the theme data if it hasn't been done yet
if(selectedTheme == null) {
// or if the user has changed their light/dark system settings in the background
if(selectedTheme == null ||
(systemInDark != isSystemInDarkTheme()) && preferences.getFollowSystemSettings()) {
// Some values can be set from the preferences, and if not should fallback to a default value
val context = LocalContext.current
val preferences = AppTextSecurePreferences(context)
selectedTheme = preferences.getComposeTheme()
}

// keeping track of the current system light/dark setting
systemInDark = isSystemInDarkTheme()

SessionMaterialTheme(colors = selectedTheme ?: ClassicDark()) { content() }
}

Expand Down