diff --git a/sample-compose/app/build.gradle.kts b/sample-compose/app/build.gradle.kts index 1ddb5fd9e..38739b5d8 100644 --- a/sample-compose/app/build.gradle.kts +++ b/sample-compose/app/build.gradle.kts @@ -132,7 +132,8 @@ dependencies { implementation("androidx.compose.material:material") implementation("androidx.navigation:navigation-compose:${Versions.COMPOSE_NAVIGATION_VERSION}") - implementation("com.google.accompanist:accompanist-permissions:${Versions.ACCOMPANIST_PERMISSIONS_VERSION}") + implementation("com.google.accompanist:accompanist-permissions:${Versions.ACCOMPANIST_VERSION}") + implementation("com.google.accompanist:accompanist-systemuicontroller:${Versions.ACCOMPANIST_VERSION}") implementation("androidx.datastore:datastore-preferences:${Versions.ANDROIDX_DATASTORE_PREFERENCES_VERSION}") diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseScreen.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseScreen.kt new file mode 100644 index 000000000..e2255c0e3 --- /dev/null +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/base/BaseScreen.kt @@ -0,0 +1,21 @@ +package co.nimblehq.sample.compose.ui.base + +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.colorResource +import co.nimblehq.sample.compose.R +import co.nimblehq.sample.compose.util.setStatusBarColor + +@Composable +fun BaseScreen( + isDarkStatusBarIcons: Boolean? = null, + content: @Composable () -> Unit, +) { + if (isDarkStatusBarIcons != null) { + setStatusBarColor( + color = colorResource(id = R.color.statusBarColor), + darkIcons = isDarkStatusBarIcons, + ) + } + + content() +} diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/home/HomeScreen.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/home/HomeScreen.kt index 0bd05c0ee..77291b63c 100644 --- a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/home/HomeScreen.kt +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/home/HomeScreen.kt @@ -17,6 +17,7 @@ import co.nimblehq.sample.compose.extensions.showToast import co.nimblehq.sample.compose.lib.IsLoading import co.nimblehq.sample.compose.model.UiModel import co.nimblehq.sample.compose.ui.AppDestination +import co.nimblehq.sample.compose.ui.base.BaseScreen import co.nimblehq.sample.compose.ui.common.AppBar import co.nimblehq.sample.compose.ui.showToast import co.nimblehq.sample.compose.ui.theme.ComposeTheme @@ -27,6 +28,8 @@ import kotlinx.coroutines.flow.* fun HomeScreen( viewModel: HomeViewModel = hiltViewModel(), navigator: (destination: AppDestination) -> Unit, +) = BaseScreen( + isDarkStatusBarIcons = true, ) { val context = LocalContext.current viewModel.error.collectAsEffect { e -> e.showToast(context) } diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/second/SecondScreen.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/second/SecondScreen.kt index 596952901..957ec114a 100644 --- a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/second/SecondScreen.kt +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/second/SecondScreen.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.hilt.navigation.compose.hiltViewModel import co.nimblehq.sample.compose.R import co.nimblehq.sample.compose.ui.AppDestination +import co.nimblehq.sample.compose.ui.base.BaseScreen import co.nimblehq.sample.compose.ui.common.AppBar import co.nimblehq.sample.compose.ui.theme.ComposeTheme @@ -21,6 +22,8 @@ fun SecondScreen( viewModel: SecondViewModel = hiltViewModel(), navigator: (destination: AppDestination) -> Unit, id: String, +) = BaseScreen( + isDarkStatusBarIcons = false, ) { SecondScreenContent(id) } diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/third/ThirdScreen.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/third/ThirdScreen.kt index 6a5aad599..ab9db5b70 100644 --- a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/third/ThirdScreen.kt +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/ui/screens/main/third/ThirdScreen.kt @@ -15,6 +15,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import co.nimblehq.sample.compose.R import co.nimblehq.sample.compose.model.UiModel import co.nimblehq.sample.compose.ui.AppDestination +import co.nimblehq.sample.compose.ui.base.BaseScreen import co.nimblehq.sample.compose.ui.common.AppBar import co.nimblehq.sample.compose.ui.theme.ComposeTheme @@ -23,6 +24,8 @@ fun ThirdScreen( viewModel: ThirdViewModel = hiltViewModel(), navigator: (destination: AppDestination) -> Unit, model: UiModel?, +) = BaseScreen( + isDarkStatusBarIcons = true, ) { ThirdScreenContent(data = model) } diff --git a/sample-compose/app/src/main/java/co/nimblehq/sample/compose/util/ComposableUtil.kt b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/util/ComposableUtil.kt new file mode 100644 index 000000000..f4830423f --- /dev/null +++ b/sample-compose/app/src/main/java/co/nimblehq/sample/compose/util/ComposableUtil.kt @@ -0,0 +1,22 @@ +package co.nimblehq.sample.compose.util + +import android.annotation.SuppressLint +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.ui.graphics.Color +import com.google.accompanist.systemuicontroller.rememberSystemUiController + +@SuppressLint("ComposableNaming") +@Composable +fun setStatusBarColor( + color: Color, + darkIcons: Boolean, +) { + val systemUiController = rememberSystemUiController() + LaunchedEffect(key1 = darkIcons) { + systemUiController.setStatusBarColor( + color = color, + darkIcons = darkIcons, + ) + } +} diff --git a/sample-compose/app/src/main/res/values/colors.xml b/sample-compose/app/src/main/res/values/colors.xml index 764d6f58e..cd0fde27d 100644 --- a/sample-compose/app/src/main/res/values/colors.xml +++ b/sample-compose/app/src/main/res/values/colors.xml @@ -1,4 +1,4 @@ - #FF669900 + #FF669900 diff --git a/sample-compose/app/src/main/res/values/styles.xml b/sample-compose/app/src/main/res/values/styles.xml index c82a3c111..380abe9eb 100644 --- a/sample-compose/app/src/main/res/values/styles.xml +++ b/sample-compose/app/src/main/res/values/styles.xml @@ -1,6 +1,6 @@ diff --git a/sample-compose/buildSrc/src/main/java/Versions.kt b/sample-compose/buildSrc/src/main/java/Versions.kt index bbe6767ff..3c85347c2 100644 --- a/sample-compose/buildSrc/src/main/java/Versions.kt +++ b/sample-compose/buildSrc/src/main/java/Versions.kt @@ -9,7 +9,7 @@ object Versions { const val ANDROID_VERSION_NAME = "3.26.0" // Dependencies (Alphabet sorted) - const val ACCOMPANIST_PERMISSIONS_VERSION = "0.30.1" + const val ACCOMPANIST_VERSION = "0.30.1" const val ANDROID_COMMON_KTX_VERSION = "0.1.1" const val ANDROID_CRYPTO_VERSION = "1.0.0" const val ANDROIDX_CORE_KTX_VERSION = "1.10.1"