Added functionality for auto-switch theming of status bar for light/dark mode
This commit is contained in:
1 parent
0ef127a3b7
commit
45487abc09
2 files changed
+11
-9
No files matched your search
@@ -22,7 +22,7 @@ class MainActivity : ComponentActivity() {
|
||||
setContent {
|
||||
LiveWallpaperTheme (isDarkMode(), isDynamicTheming()) {
|
||||
Surface(elevation = 5.dp) {
|
||||
LiveWallpaperApp(settingsViewModel)
|
||||
LiveWallpaperApp(isDarkMode(), settingsViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
package com.anthonyla.livewallpaper.ui
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.navigation.compose.NavHost
|
||||
@@ -24,10 +22,15 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LiveWallpaperApp(settingsViewModel: SettingsViewModel, modifier: Modifier = Modifier) {
|
||||
fun LiveWallpaperApp(
|
||||
isDark: Boolean,
|
||||
settingsViewModel: SettingsViewModel,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val navController = rememberNavController()
|
||||
|
||||
SetTransparentSystemBars()
|
||||
// Transparent system bars
|
||||
SetTransparentSystemBars(isDark)
|
||||
|
||||
// Bottom navigation
|
||||
val bottomNavOptions = listOf(
|
||||
@@ -53,7 +56,7 @@ fun LiveWallpaperApp(settingsViewModel: SettingsViewModel, modifier: Modifier =
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SetTransparentSystemBars() {
|
||||
fun SetTransparentSystemBars(darkMode: Boolean) {
|
||||
val systemUiController = rememberSystemUiController()
|
||||
val view = LocalView.current
|
||||
SideEffect {
|
||||
@@ -61,8 +64,7 @@ fun SetTransparentSystemBars() {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
systemUiController.setSystemBarsColor(
|
||||
color = Color.Transparent,
|
||||
// check if app is in dark mode or not
|
||||
darkIcons = false
|
||||
darkIcons = !darkMode
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user