summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-08-07 13:32:43 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-08-07 13:32:43 +0000
commite9f30daed41745a7f1268445e41eb5781285f4d9 (patch)
treeaf9ecbb4ca7b7215e54386ba06fbdfef59fae6be
parentfb4225c1f0f902589d79d8231859d0e4df7b4e58 (diff)
parentbeeade432cc471ebb8d90742f78a5fb10e4a74d3 (diff)
Merge "Introduce EdgeToEdgeActivityContent" into udc-qpr-dev am: db3f1d595f am: beeade432c
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24308960 Change-Id: Idc2befee8150705a50713467d157e93cd2c80a06 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.kt61
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()
+ }
+ }
+ }
+}