Skip to content

Commit

Permalink
Remove usage of deprecated accompanist SystemUiController
Browse files Browse the repository at this point in the history
Co-authored-by: p
  • Loading branch information
AntsyLich committed Oct 12, 2024
1 parent f84d9a0 commit 2ba3f06
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
1 change: 0 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/eu/kanade/presentation/util/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ interface AssistContentScreen {
}

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

Expand Down
74 changes: 36 additions & 38 deletions app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,49 @@ 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
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
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
Expand Down Expand Up @@ -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() {

Expand Down Expand Up @@ -132,45 +135,27 @@ 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
downloadOnly -> DownloadedOnlyBannerBackgroundColor
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,
)
}

Expand Down Expand Up @@ -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),
)
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions gradle/compose.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[versions]
compose-bom = "2024.09.03"
accompanist = "0.36.0"

[libraries]
activity = "androidx.activity:activity-compose:1.9.2"
Expand All @@ -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" }

0 comments on commit 2ba3f06

Please sign in to comment.