From 2ba3f0612c08c7021fed2f6d96cd538da2f34a13 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 12 Oct 2024 06:22:34 +0600 Subject: [PATCH] Remove usage of deprecated accompanist SystemUiController Co-authored-by: p --- app/build.gradle.kts | 1 - .../eu/kanade/presentation/util/Navigator.kt | 6 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 74 +++++++++---------- gradle/compose.versions.toml | 3 - 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6cb96d329..1bde7563f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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) diff --git a/app/src/main/java/eu/kanade/presentation/util/Navigator.kt b/app/src/main/java/eu/kanade/presentation/util/Navigator.kt index b033d4883..0c661f32e 100644 --- a/app/src/main/java/eu/kanade/presentation/util/Navigator.kt +++ b/app/src/main/java/eu/kanade/presentation/util/Navigator.kt @@ -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, ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 39c9dd5c7..0d668dc79 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -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( - modifier = Modifier - .padding(contentPadding) - .consumeWindowInsets(contentPadding), - ) { + Box { // 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), + ) + } } } diff --git a/gradle/compose.versions.toml b/gradle/compose.versions.toml index 7dec9fdf7..ce5e9777c 100644 --- a/gradle/compose.versions.toml +++ b/gradle/compose.versions.toml @@ -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" }