Remove usage of deprecated accompanist SystemUiController

Co-authored-by: p
This commit is contained in:
AntsyLich 2024-10-12 06:22:34 +06:00
parent f84d9a08b4
commit 2ba3f0612c
No known key found for this signature in database
4 changed files with 41 additions and 43 deletions

View file

@ -164,7 +164,6 @@ dependencies {
debugImplementation(compose.ui.tooling) debugImplementation(compose.ui.tooling)
implementation(compose.ui.tooling.preview) implementation(compose.ui.tooling.preview)
implementation(compose.ui.util) implementation(compose.ui.util)
implementation(compose.accompanist.systemuicontroller)
implementation(androidx.interpolator) implementation(androidx.interpolator)

View file

@ -55,7 +55,10 @@ interface AssistContentScreen {
} }
@Composable @Composable
fun DefaultNavigatorScreenTransition(navigator: Navigator) { fun DefaultNavigatorScreenTransition(
navigator: Navigator,
modifier: Modifier = Modifier,
) {
val slideDistance = rememberSlideDistance() val slideDistance = rememberSlideDistance()
ScreenTransition( ScreenTransition(
navigator = navigator, navigator = navigator,
@ -65,6 +68,7 @@ fun DefaultNavigatorScreenTransition(navigator: Navigator) {
slideDistance = slideDistance, slideDistance = slideDistance,
) )
}, },
modifier = modifier,
) )
} }

View file

@ -10,20 +10,25 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.consumeWindowInsets import androidx.compose.foundation.layout.consumeWindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.layout.windowInsetsPadding import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.AlertDialog import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton import androidx.compose.material3.TextButton
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
@ -31,16 +36,16 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.luminance import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.animation.doOnEnd import androidx.core.animation.doOnEnd
import androidx.core.net.toUri import androidx.core.net.toUri
import androidx.core.splashscreen.SplashScreen import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.util.Consumer import androidx.core.util.Consumer
import androidx.core.view.WindowCompat
import androidx.interpolator.view.animation.FastOutSlowInInterpolator import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
@ -48,7 +53,6 @@ import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.Navigator import cafe.adriel.voyager.navigator.Navigator
import cafe.adriel.voyager.navigator.NavigatorDisposeBehavior import cafe.adriel.voyager.navigator.NavigatorDisposeBehavior
import cafe.adriel.voyager.navigator.currentOrThrow import cafe.adriel.voyager.navigator.currentOrThrow
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.base.BasePreferences
import eu.kanade.presentation.components.AppStateBanners import eu.kanade.presentation.components.AppStateBanners
import eu.kanade.presentation.components.DownloadedOnlyBannerBackgroundColor import eu.kanade.presentation.components.DownloadedOnlyBannerBackgroundColor
@ -97,7 +101,6 @@ import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.i18n.stringResource
import tachiyomi.presentation.core.util.collectAsState import tachiyomi.presentation.core.util.collectAsState
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import androidx.compose.ui.graphics.Color.Companion as ComposeColor
class MainActivity : BaseActivity() { class MainActivity : BaseActivity() {
@ -132,17 +135,13 @@ class MainActivity : BaseActivity() {
return return
} }
// Draw edge-to-edge
// TODO: replace with ComponentActivity#enableEdgeToEdge
WindowCompat.setDecorFitsSystemWindows(window, false)
setComposeContent { setComposeContent {
val context = LocalContext.current
val incognito by preferences.incognitoMode().collectAsState() val incognito by preferences.incognitoMode().collectAsState()
val downloadOnly by preferences.downloadedOnly().collectAsState() val downloadOnly by preferences.downloadedOnly().collectAsState()
val indexing by downloadCache.isInitializing.collectAsState() val indexing by downloadCache.isInitializing.collectAsState()
// Set status bar color considering the top app state banner
val systemUiController = rememberSystemUiController()
val isSystemInDarkTheme = isSystemInDarkTheme() val isSystemInDarkTheme = isSystemInDarkTheme()
val statusBarBackgroundColor = when { val statusBarBackgroundColor = when {
indexing -> IndexingBannerBackgroundColor indexing -> IndexingBannerBackgroundColor
@ -150,27 +149,13 @@ class MainActivity : BaseActivity() {
incognito -> IncognitoModeBannerBackgroundColor incognito -> IncognitoModeBannerBackgroundColor
else -> MaterialTheme.colorScheme.surface else -> MaterialTheme.colorScheme.surface
} }
LaunchedEffect(systemUiController, statusBarBackgroundColor) { LaunchedEffect(isSystemInDarkTheme, statusBarBackgroundColor) {
systemUiController.setStatusBarColor( // Draw edge-to-edge and set system bars color to transparent
color = ComposeColor.Transparent, val lightStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.BLACK)
darkIcons = statusBarBackgroundColor.luminance() > 0.5, val darkStyle = SystemBarStyle.dark(Color.TRANSPARENT)
transformColorForLightContent = { ComposeColor.Black }, enableEdgeToEdge(
) statusBarStyle = if (statusBarBackgroundColor.luminance() > 0.5) lightStyle else darkStyle,
} navigationBarStyle = if (isSystemInDarkTheme) darkStyle else lightStyle,
// Set navigation bar color
val context = LocalContext.current
val navbarScrimColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.dp)
LaunchedEffect(systemUiController, isSystemInDarkTheme, navbarScrimColor) {
systemUiController.setNavigationBarColor(
color = if (context.isNavigationBarNeedsScrim()) {
navbarScrimColor.copy(alpha = 0.7f)
} else {
ComposeColor.Transparent
},
darkIcons = !isSystemInDarkTheme,
navigationBarContrastEnforced = false,
transformColorForLightContent = { ComposeColor.Black },
) )
} }
@ -203,13 +188,26 @@ class MainActivity : BaseActivity() {
contentWindowInsets = scaffoldInsets, contentWindowInsets = scaffoldInsets,
) { contentPadding -> ) { contentPadding ->
// Consume insets already used by app state banners // Consume insets already used by app state banners
Box( Box {
modifier = Modifier
.padding(contentPadding)
.consumeWindowInsets(contentPadding),
) {
// Shows current screen // Shows current screen
DefaultNavigatorScreenTransition(navigator = navigator) DefaultNavigatorScreenTransition(
navigator = navigator,
modifier = Modifier
.padding(contentPadding)
.consumeWindowInsets(contentPadding),
)
// Draw navigation bar scrim when needed
if (remember { isNavigationBarNeedsScrim() }) {
Spacer(
modifier = Modifier
.align(Alignment.BottomCenter)
.fillMaxWidth()
.windowInsetsBottomHeight(WindowInsets.navigationBars)
.alpha(0.8f)
.background(MaterialTheme.colorScheme.surfaceContainer),
)
}
} }
} }

View file

@ -1,6 +1,5 @@
[versions] [versions]
compose-bom = "2024.09.03" compose-bom = "2024.09.03"
accompanist = "0.36.0"
[libraries] [libraries]
activity = "androidx.activity:activity-compose:1.9.2" activity = "androidx.activity:activity-compose:1.9.2"
@ -17,5 +16,3 @@ material3-core = { module = "androidx.compose.material3:material3" }
material-icons = { module = "androidx.compose.material:material-icons-extended" } material-icons = { module = "androidx.compose.material:material-icons-extended" }
glance = "androidx.glance:glance-appwidget:1.1.0" glance = "androidx.glance:glance-appwidget:1.1.0"
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }