Skip to content

Commit

Permalink
Replace systemuicontroller with enableEdgeToEdge(), add splash th…
Browse files Browse the repository at this point in the history
…eme.
  • Loading branch information
ychescale9 committed Aug 26, 2023
1 parent bde4469 commit e082e74
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
4 changes: 0 additions & 4 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ dependencies {
implementation(libs.androidx.coreSplashscreen)
implementation(libs.androidx.profileinstaller)

// TODO move to design module
// Compose companion libraries
implementation(libs.accompanist.systemUiController)

// Hilt
implementation(libs.hilt.android)
kapt(libs.hilt.compiler)
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.KS">
android:theme="@style/Theme.KS.Splash">

<profileable
android:shell="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@ package io.github.reactivecircus.kstreamlined.android
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.WindowCompat
import dagger.hilt.android.AndroidEntryPoint
import io.github.reactivecircus.kstreamlined.android.theme.KSTheme

@AndroidEntryPoint
class KSActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

installSplashScreen()

// configure edge-to-edge window insets
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)

enableEdgeToEdge()

setContent {
KSTheme {
val darkTheme = isSystemInDarkTheme()
val navigationBarColor = MaterialTheme.colorScheme.background.toArgb()
LaunchedEffect(darkTheme) {
window.navigationBarColor = navigationBarColor
}

Surface(
modifier = Modifier.fillMaxSize(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalInspectionMode
import com.google.accompanist.systemuicontroller.rememberSystemUiController

// TODO define color scheme

Expand Down Expand Up @@ -40,15 +37,4 @@ fun KSTheme(
colorScheme = colorScheme,
content = content,
)

if (!LocalInspectionMode.current) {
val useDarkIcons = !darkTheme
val systemUiController = rememberSystemUiController()
SideEffect {
systemUiController.apply {
setStatusBarColor(Color.Transparent, darkIcons = useDarkIcons)
setNavigationBarColor(colorScheme.background, darkIcons = useDarkIcons)
}
}
}
}
11 changes: 6 additions & 5 deletions android/app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<resources>
<!-- Base application theme. -->
<style name="KS" parent="android:Theme.Material.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.KS.Splash" parent="Theme.SplashScreen">
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">false</item>>
<item name="windowSplashScreenBackground">#070426</item>
<item name="postSplashScreenTheme">@style/Theme.KS</item>
</style>
</resources>
13 changes: 8 additions & 5 deletions android/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<resources>
<!-- Base application theme. -->
<style name="Theme.KS" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.KS" parent="android:Theme.Material.Light.NoActionBar"/>

<style name="Theme.KS.Splash" parent="Theme.SplashScreen">
<item name="android:windowLightStatusBar" >true</item>
<item name="android:windowLightNavigationBar" tools:targetApi="27">true</item>>
<item name="windowSplashScreenBackground">#E7DBFF</item>
<item name="postSplashScreenTheme">@style/Theme.KS</item>
</style>
</resources>
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ androidx-espresso-intents = { module = "androidx.test.espresso:espresso-intents"
accompanist-insetsUi = { module = "com.google.accompanist:accompanist-insets-ui", version.ref = "accompanist" }
accompanist-placeholder = { module = "com.google.accompanist:accompanist-placeholder-material", version.ref = "accompanist" }
accompanist-swipeRefresh = { module = "com.google.accompanist:accompanist-swiperefresh", version.ref = "accompanist" }
accompanist-systemUiController = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
accompanist-navigationAnimation = { module = "com.google.accompanist:accompanist-navigation-animation", version.ref = "accompanist" }
accompanist-navigationMaterial = { module = "com.google.accompanist:accompanist-navigation-material", version.ref = "accompanist" }
accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanist" }
Expand Down

0 comments on commit e082e74

Please sign in to comment.