diff options
| author | 2023-08-07 12:50:25 +0000 | |
|---|---|---|
| committer | 2023-08-07 12:50:25 +0000 | |
| commit | beeade432cc471ebb8d90742f78a5fb10e4a74d3 (patch) | |
| tree | adf1ff5707d2dead453fae0c1e95b3953cbfdf1b | |
| parent | 4d82ad52f095248a2b9288ee3086a1eab90ee920 (diff) | |
| parent | db3f1d595ffd9c8f1e05ee0a3b545eea78c20422 (diff) | |
Merge "Introduce EdgeToEdgeActivityContent" into udc-qpr-dev am: db3f1d595f
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24308960
Change-Id: I1ea5375f37a30df7fd61b0b26c98312d93170963
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SystemUI/compose/core/src/com/android/compose/activity/EdgeToEdgeActivitContent.kt | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/activity/EdgeToEdgeActivitContent.kt b/packages/SystemUI/compose/core/src/com/android/compose/activity/EdgeToEdgeActivitContent.kt new file mode 100644 index 000000000000..97c8076e910b --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/compose/activity/EdgeToEdgeActivitContent.kt @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.compose.activity + +import androidx.compose.foundation.background +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.material3.LocalContentColor +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.contentColorFor +import androidx.compose.runtime.Composable +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.DisposableEffect +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import com.android.compose.rememberSystemUiController +import com.android.compose.theme.PlatformTheme + +/** Scaffolding for an edge-to-edge activity content. */ +@Composable +fun EdgeToEdgeActivityContent( + modifier: Modifier = Modifier, + content: @Composable () -> Unit, +) { + // Make the status and navigation bars transparent, ensuring that the status bar icons are dark + // when the theme is light and vice-versa. + val systemUiController = rememberSystemUiController() + val isDarkTheme = isSystemInDarkTheme() + val useDarkIcons = !isDarkTheme + DisposableEffect(systemUiController, useDarkIcons) { + systemUiController.setSystemBarsColor( + color = Color.Transparent, + darkIcons = useDarkIcons, + ) + onDispose {} + } + + PlatformTheme(isDarkTheme) { + val backgroundColor = MaterialTheme.colorScheme.background + Box(modifier.fillMaxSize().background(backgroundColor)) { + CompositionLocalProvider(LocalContentColor provides contentColorFor(backgroundColor)) { + content() + } + } + } +} |