Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite SystemUiController to edgeToEdge #634

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
],
},
{
"groupName": "Compose & Accompanist",
"groupName": "Compose",
"matchPackageNames": [
"androidx.compose",
"com.google.accompanist",
],
},
{
Expand Down
2 changes: 1 addition & 1 deletion catalog/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ dependencies {
implementation(projects.catalog.semantics)

implementation(libs.androidx.core)
implementation(libs.androidx.appCompat)
implementation(libs.androidx.activityCompose)
implementation(libs.androidx.activityComposeCatalog)

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

implementation(libs.coil)
implementation(libs.accompanist.systemController)
implementation(libs.kiwi.navigationComposeTyped)

baselineProfile(projects.baselineprofile)
Expand Down
1 change: 1 addition & 0 deletions catalog/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<activity
android:name=".MainActivity"
android:exported="true"
android:configChanges="uiMode|density|locale"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.kiwi.navigationcompose.typed.composable
import com.kiwi.navigationcompose.typed.createRoutePattern
import com.kiwi.navigationcompose.typed.dialog
Expand Down Expand Up @@ -77,22 +74,16 @@ import kiwi.orbit.compose.catalog.screens.topAppBarNavigation
import kotlinx.serialization.ExperimentalSerializationApi

@Composable
fun CatalogApplication() {
val systemUiController = rememberSystemUiController()

fun CatalogApplication(activity: MainActivity) {
var isLightThemeUser by rememberSaveable { mutableStateOf<Boolean?>(null) }
val isLightThemeFinal = isLightThemeUser ?: !isSystemInDarkTheme()

SideEffect {
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = isLightThemeFinal,
)
}

AnimatedAppTheme(
isLightTheme = isLightThemeFinal,
onThemeToggle = { isLightThemeUser = it },
onThemeToggle = { isLight ->
isLightThemeUser = isLight
activity.setUiMode(isLight)
},
) { onThemeToggle ->
NavGraph(onThemeToggle = onThemeToggle)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
package kiwi.orbit.compose.catalog

import android.app.UiModeManager
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.core.view.WindowCompat
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.getSystemService

class MainActivity : ComponentActivity() {
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)

enableEdgeToEdge()
setContent {
CatalogApplication()
CatalogApplication(this)
}
}

internal fun setUiMode(isLight: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val uiModeManager = getSystemService<UiModeManager>()!!
uiModeManager.setApplicationNightMode(
if (isLight) UiModeManager.MODE_NIGHT_NO else UiModeManager.MODE_NIGHT_YES,
)
} else {
AppCompatDelegate.setDefaultNightMode(
if (isLight) AppCompatDelegate.MODE_NIGHT_NO else AppCompatDelegate.MODE_NIGHT_YES,
)
}
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(Color.TRANSPARENT, Color.TRANSPARENT) { !isLight },
navigationBarStyle = SystemBarStyle.auto(DefaultLightScrim, DefaultDarkScrim) { !isLight },
)
}

private val DefaultLightScrim = Color.argb(0xe6, 0xFF, 0xFF, 0xFF)
private val DefaultDarkScrim = Color.argb(0x80, 0x1b, 0x1b, 0x1b)
}
4 changes: 2 additions & 2 deletions catalog/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>

<style name="Theme.Catalog" parent="android:Theme.Material.NoActionBar" />
<style name="Theme.Catalog" parent="Theme.AppCompat.NoActionBar"/>

</resources>
2 changes: 1 addition & 1 deletion catalog/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>

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

</resources>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ android-sdkCommon = { module = "com.android.tools:sdk-common", version.ref = "an
android-lint-api = { module = "com.android.tools.lint:lint-api", version.ref = "android-lint" }
android-lint-impl = { module = "com.android.tools.lint:lint", version.ref = "android-lint" }
android-lint-tests = { module = "com.android.tools.lint:lint-tests", version.ref = "android-lint" }
androidx-appCompat = "androidx.appcompat:appcompat:1.6.1"
androidx-activityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" }
androidx-activityComposeCatalog = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityComposeCatalog" }
androidx-benchmark-macro = { module = "androidx.benchmark:benchmark-macro-junit4", version = "1.2.3" }
Expand All @@ -43,7 +44,6 @@ androidx-customView = { module = "androidx.customview:customview", version = "1.
androidx-customViewPoolingContainer = { module = "androidx.customview:customview-poolingcontainer", version = "1.0.0" }
androidx-test-runner = { module = "androidx.test:runner", version = "1.5.2" }
androidx-test-uiAutomator = { module = "androidx.test.uiautomator:uiautomator", version = "2.2.0" }
accompanist-systemController = "com.google.accompanist:accompanist-systemuicontroller:0.34.0"
coil = { module = "io.coil-kt:coil-compose", version = "2.5.0" }
compose-animation = { module = "androidx.compose.animation:animation" }
compose-animationGraphics = { module = "androidx.compose.animation:animation-graphics" }
Expand Down