mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Remove usage of deprecated accompanist SystemUiController
Co-authored-by: p
This commit is contained in:
parent
f84d9a08b4
commit
2ba3f0612c
4 changed files with 41 additions and 43 deletions
|
@ -164,7 +164,6 @@ dependencies {
|
|||
debugImplementation(compose.ui.tooling)
|
||||
implementation(compose.ui.tooling.preview)
|
||||
implementation(compose.ui.util)
|
||||
implementation(compose.accompanist.systemuicontroller)
|
||||
|
||||
implementation(androidx.interpolator)
|
||||
|
||||
|
|
|
@ -55,7 +55,10 @@ interface AssistContentScreen {
|
|||
}
|
||||
|
||||
@Composable
|
||||
fun DefaultNavigatorScreenTransition(navigator: Navigator) {
|
||||
fun DefaultNavigatorScreenTransition(
|
||||
navigator: Navigator,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val slideDistance = rememberSlideDistance()
|
||||
ScreenTransition(
|
||||
navigator = navigator,
|
||||
|
@ -65,6 +68,7 @@ fun DefaultNavigatorScreenTransition(navigator: Navigator) {
|
|||
slideDistance = slideDistance,
|
||||
)
|
||||
},
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -10,20 +10,25 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
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.layout.Box
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.WindowInsetsSides
|
||||
import androidx.compose.foundation.layout.consumeWindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.only
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.windowInsetsBottomHeight
|
||||
import androidx.compose.foundation.layout.windowInsetsPadding
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
|
@ -31,16 +36,16 @@ import androidx.compose.runtime.getValue
|
|||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.splashscreen.SplashScreen
|
||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||
import androidx.core.util.Consumer
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
|
||||
import androidx.interpolator.view.animation.LinearOutSlowInInterpolator
|
||||
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.NavigatorDisposeBehavior
|
||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
import eu.kanade.domain.base.BasePreferences
|
||||
import eu.kanade.presentation.components.AppStateBanners
|
||||
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.util.collectAsState
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import androidx.compose.ui.graphics.Color.Companion as ComposeColor
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
|
||||
|
@ -132,17 +135,13 @@ class MainActivity : BaseActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
// Draw edge-to-edge
|
||||
// TODO: replace with ComponentActivity#enableEdgeToEdge
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
|
||||
setComposeContent {
|
||||
val context = LocalContext.current
|
||||
|
||||
val incognito by preferences.incognitoMode().collectAsState()
|
||||
val downloadOnly by preferences.downloadedOnly().collectAsState()
|
||||
val indexing by downloadCache.isInitializing.collectAsState()
|
||||
|
||||
// Set status bar color considering the top app state banner
|
||||
val systemUiController = rememberSystemUiController()
|
||||
val isSystemInDarkTheme = isSystemInDarkTheme()
|
||||
val statusBarBackgroundColor = when {
|
||||
indexing -> IndexingBannerBackgroundColor
|
||||
|
@ -150,27 +149,13 @@ class MainActivity : BaseActivity() {
|
|||
incognito -> IncognitoModeBannerBackgroundColor
|
||||
else -> MaterialTheme.colorScheme.surface
|
||||
}
|
||||
LaunchedEffect(systemUiController, statusBarBackgroundColor) {
|
||||
systemUiController.setStatusBarColor(
|
||||
color = ComposeColor.Transparent,
|
||||
darkIcons = statusBarBackgroundColor.luminance() > 0.5,
|
||||
transformColorForLightContent = { ComposeColor.Black },
|
||||
)
|
||||
}
|
||||
|
||||
// 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 },
|
||||
LaunchedEffect(isSystemInDarkTheme, statusBarBackgroundColor) {
|
||||
// Draw edge-to-edge and set system bars color to transparent
|
||||
val lightStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.BLACK)
|
||||
val darkStyle = SystemBarStyle.dark(Color.TRANSPARENT)
|
||||
enableEdgeToEdge(
|
||||
statusBarStyle = if (statusBarBackgroundColor.luminance() > 0.5) lightStyle else darkStyle,
|
||||
navigationBarStyle = if (isSystemInDarkTheme) darkStyle else lightStyle,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -203,13 +188,26 @@ class MainActivity : BaseActivity() {
|
|||
contentWindowInsets = scaffoldInsets,
|
||||
) { contentPadding ->
|
||||
// Consume insets already used by app state banners
|
||||
Box(
|
||||
Box {
|
||||
// Shows current screen
|
||||
DefaultNavigatorScreenTransition(
|
||||
navigator = navigator,
|
||||
modifier = Modifier
|
||||
.padding(contentPadding)
|
||||
.consumeWindowInsets(contentPadding),
|
||||
) {
|
||||
// Shows current screen
|
||||
DefaultNavigatorScreenTransition(navigator = navigator)
|
||||
)
|
||||
|
||||
// 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),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[versions]
|
||||
compose-bom = "2024.09.03"
|
||||
accompanist = "0.36.0"
|
||||
|
||||
[libraries]
|
||||
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" }
|
||||
|
||||
glance = "androidx.glance:glance-appwidget:1.1.0"
|
||||
|
||||
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" }
|
||||
|
|
Loading…
Reference in a new issue