From 41de582ea5c135c687cb53555c5e26f91ea4669e Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Wed, 3 Aug 2022 14:16:42 -0700 Subject: [PATCH] Update SystemUiController to hoist is dark theme --- docs/systemuicontroller.md | 6 ++++-- .../sample/systemuicontroller/DocsSamples.kt | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/systemuicontroller.md b/docs/systemuicontroller.md index b6a278da6..9c891f3cc 100644 --- a/docs/systemuicontroller.md +++ b/docs/systemuicontroller.md @@ -12,9 +12,9 @@ In your layouts you can update the system bar colors like so: ``` kotlin // Remember a SystemUiController val systemUiController = rememberSystemUiController() -val useDarkIcons = MaterialTheme.colors.isLight +val useDarkIcons = !isSystemInDarkTheme() -SideEffect { +DisposableEffect(systemUiController, useDarkIcons) { // Update all of the system bar colors to be transparent, and use // dark icons if we're in light theme systemUiController.setSystemBarsColor( @@ -23,6 +23,8 @@ SideEffect { ) // setStatusBarColor() and setNavigationBarColor() also exist + + onDispose {} } ``` diff --git a/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DocsSamples.kt b/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DocsSamples.kt index 2da9523ed..ad51f9c5b 100644 --- a/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DocsSamples.kt +++ b/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DocsSamples.kt @@ -16,19 +16,19 @@ package com.google.accompanist.sample.systemuicontroller -import androidx.compose.material.MaterialTheme +import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.runtime.Composable -import androidx.compose.runtime.SideEffect +import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.graphics.Color import com.google.accompanist.systemuicontroller.rememberSystemUiController @Composable fun SystemUiControllerSample() { - // Get the current SystemUiController + // Remember a SystemUiController val systemUiController = rememberSystemUiController() - val useDarkIcons = MaterialTheme.colors.isLight + val useDarkIcons = !isSystemInDarkTheme() - SideEffect { + DisposableEffect(systemUiController, useDarkIcons) { // Update all of the system bar colors to be transparent, and use // dark icons if we're in light theme systemUiController.setSystemBarsColor( @@ -37,5 +37,6 @@ fun SystemUiControllerSample() { ) // setStatusBarColor() and setNavigationBarColor() also exist + onDispose {} } }