Skip to content

Commit 55ae1f4

Browse files
author
Alex Matečný
authored
Merge pull request #634 from hrach/edge-to-edge
Rewrite SystemUiController to edgeToEdge
2 parents c104e1e + 47eb5c3 commit 55ae1f4

File tree

8 files changed

+43
-27
lines changed

8 files changed

+43
-27
lines changed

.github/renovate.json5

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232
],
3333
},
3434
{
35-
"groupName": "Compose & Accompanist",
35+
"groupName": "Compose",
3636
"matchPackageNames": [
3737
"androidx.compose",
38-
"com.google.accompanist",
3938
],
4039
},
4140
{

catalog/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ dependencies {
137137
implementation(projects.catalog.semantics)
138138

139139
implementation(libs.androidx.core)
140+
implementation(libs.androidx.appCompat)
140141
implementation(libs.androidx.activityCompose)
141142
implementation(libs.androidx.activityComposeCatalog)
142143

@@ -155,7 +156,6 @@ dependencies {
155156
implementation(libs.kotlin.stdlib)
156157

157158
implementation(libs.coil)
158-
implementation(libs.accompanist.systemController)
159159
implementation(libs.kiwi.navigationComposeTyped)
160160

161161
baselineProfile(projects.baselineprofile)

catalog/src/main/AndroidManifest.xml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<activity
1616
android:name=".MainActivity"
1717
android:exported="true"
18+
android:configChanges="uiMode|density|locale"
1819
android:windowSoftInputMode="adjustResize">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />

catalog/src/main/java/kiwi/orbit/compose/catalog/CatalogApplication.kt

+5-14
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@ import androidx.compose.animation.slideInHorizontally
1111
import androidx.compose.animation.slideOutHorizontally
1212
import androidx.compose.foundation.isSystemInDarkTheme
1313
import androidx.compose.runtime.Composable
14-
import androidx.compose.runtime.SideEffect
1514
import androidx.compose.runtime.getValue
1615
import androidx.compose.runtime.mutableStateOf
1716
import androidx.compose.runtime.saveable.rememberSaveable
1817
import androidx.compose.runtime.setValue
1918
import androidx.compose.ui.ExperimentalComposeUiApi
2019
import androidx.compose.ui.Modifier
2120
import androidx.compose.ui.geometry.Offset
22-
import androidx.compose.ui.graphics.Color
2321
import androidx.compose.ui.platform.LocalDensity
2422
import androidx.compose.ui.semantics.semantics
2523
import androidx.compose.ui.semantics.testTagsAsResourceId
2624
import androidx.compose.ui.unit.Density
2725
import androidx.compose.ui.unit.dp
2826
import androidx.navigation.compose.NavHost
2927
import androidx.navigation.compose.rememberNavController
30-
import com.google.accompanist.systemuicontroller.rememberSystemUiController
3128
import com.kiwi.navigationcompose.typed.composable
3229
import com.kiwi.navigationcompose.typed.createRoutePattern
3330
import com.kiwi.navigationcompose.typed.dialog
@@ -77,22 +74,16 @@ import kiwi.orbit.compose.catalog.screens.topAppBarNavigation
7774
import kotlinx.serialization.ExperimentalSerializationApi
7875

7976
@Composable
80-
fun CatalogApplication() {
81-
val systemUiController = rememberSystemUiController()
82-
77+
fun CatalogApplication(activity: MainActivity) {
8378
var isLightThemeUser by rememberSaveable { mutableStateOf<Boolean?>(null) }
8479
val isLightThemeFinal = isLightThemeUser ?: !isSystemInDarkTheme()
8580

86-
SideEffect {
87-
systemUiController.setSystemBarsColor(
88-
color = Color.Transparent,
89-
darkIcons = isLightThemeFinal,
90-
)
91-
}
92-
9381
AnimatedAppTheme(
9482
isLightTheme = isLightThemeFinal,
95-
onThemeToggle = { isLightThemeUser = it },
83+
onThemeToggle = { isLight ->
84+
isLightThemeUser = isLight
85+
activity.setUiMode(isLight)
86+
},
9687
) { onThemeToggle ->
9788
NavGraph(onThemeToggle = onThemeToggle)
9889
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
11
package kiwi.orbit.compose.catalog
22

3+
import android.app.UiModeManager
4+
import android.graphics.Color
5+
import android.os.Build
36
import android.os.Bundle
4-
import androidx.activity.ComponentActivity
7+
import androidx.activity.SystemBarStyle
58
import androidx.activity.compose.setContent
6-
import androidx.core.view.WindowCompat
9+
import androidx.activity.enableEdgeToEdge
10+
import androidx.appcompat.app.AppCompatActivity
11+
import androidx.appcompat.app.AppCompatDelegate
12+
import androidx.core.content.getSystemService
713

8-
class MainActivity : ComponentActivity() {
14+
class MainActivity : AppCompatActivity() {
915
override fun onCreate(savedInstanceState: Bundle?) {
1016
super.onCreate(savedInstanceState)
1117

12-
WindowCompat.setDecorFitsSystemWindows(window, false)
13-
18+
enableEdgeToEdge()
1419
setContent {
15-
CatalogApplication()
20+
CatalogApplication(this)
1621
}
1722
}
23+
24+
internal fun setUiMode(isLight: Boolean) {
25+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
26+
val uiModeManager = getSystemService<UiModeManager>()!!
27+
uiModeManager.setApplicationNightMode(
28+
if (isLight) UiModeManager.MODE_NIGHT_NO else UiModeManager.MODE_NIGHT_YES,
29+
)
30+
} else {
31+
AppCompatDelegate.setDefaultNightMode(
32+
if (isLight) AppCompatDelegate.MODE_NIGHT_NO else AppCompatDelegate.MODE_NIGHT_YES,
33+
)
34+
}
35+
enableEdgeToEdge(
36+
statusBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT) { !isLight },
37+
navigationBarStyle = SystemBarStyle.auto(DefaultLightScrim, DefaultDarkScrim) { !isLight },
38+
)
39+
}
40+
41+
private val DefaultLightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
42+
private val DefaultDarkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
1843
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
22

3-
<style name="Theme.Catalog" parent="android:Theme.Material.NoActionBar" />
4-
3+
<style name="Theme.Catalog" parent="Theme.AppCompat.NoActionBar"/>
4+
55
</resources>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<resources>
22

3-
<style name="Theme.Catalog" parent="android:Theme.Material.Light.NoActionBar" />
3+
<style name="Theme.Catalog" parent="Theme.AppCompat.Light.NoActionBar" />
44

55
</resources>

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ android-sdkCommon = { module = "com.android.tools:sdk-common", version.ref = "an
3434
android-lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "android-lint" }
3535
android-lint-impl = { module = "com.android.tools.lint:lint", version.ref = "android-lint" }
3636
android-lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref = "android-lint" }
37+
androidx-appCompat = "androidx.appcompat:appcompat:1.6.1"
3738
androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
3839
androidx-activityComposeCatalog = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityComposeCatalog" }
3940
androidx-benchmark-macro = { module = "androidx.benchmark:benchmark-macro-junit4", version = "1.2.3" }
@@ -43,7 +44,6 @@ androidx-customView = { module = "androidx.customview:customview", version = "1.
4344
androidx-customViewPoolingContainer = { module = "androidx.customview:customview-poolingcontainer", version = "1.0.0" }
4445
androidx-test-runner = { module = "androidx.test:runner", version = "1.5.2" }
4546
androidx-test-uiAutomator = { module = "androidx.test.uiautomator:uiautomator", version = "2.2.0" }
46-
accompanist-systemController = "com.google.accompanist:accompanist-systemuicontroller:0.34.0"
4747
coil = { module = "io.coil-kt:coil-compose", version = "2.5.0" }
4848
compose-animation = { module = "androidx.compose.animation:animation" }
4949
compose-animationGraphics = { module = "androidx.compose.animation:animation-graphics" }

0 commit comments

Comments
 (0)