From 8546f0f1ede5f16c07d0333107ee1cfddc8dd932 Mon Sep 17 00:00:00 2001 From: Ash Date: Thu, 21 Apr 2022 02:00:29 +0800 Subject: [PATCH] Migrate accompanist/insets to androidx.compose.foundation --- .../ash/reader/ui/component/AnimatedPopup.kt | 7 +- .../me/ash/reader/ui/page/common/HomeEntry.kt | 64 ++++++------------- .../me/ash/reader/ui/page/home/HomePage.kt | 9 +-- .../reader/ui/page/home/feeds/FeedsPage.kt | 5 +- .../ash/reader/ui/page/home/flow/FlowPage.kt | 5 +- .../ash/reader/ui/page/home/read/ReadBar.kt | 5 +- .../ash/reader/ui/page/home/read/ReadPage.kt | 5 +- .../reader/ui/page/settings/ColorAndStyle.kt | 3 +- .../reader/ui/page/settings/SettingsPage.kt | 4 +- .../ash/reader/ui/page/startup/StartupPage.kt | 3 +- 10 files changed, 48 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/me/ash/reader/ui/component/AnimatedPopup.kt b/app/src/main/java/me/ash/reader/ui/component/AnimatedPopup.kt index 6345a03..f294bf6 100644 --- a/app/src/main/java/me/ash/reader/ui/component/AnimatedPopup.kt +++ b/app/src/main/java/me/ash/reader/ui/component/AnimatedPopup.kt @@ -1,13 +1,14 @@ package me.ash.reader.ui.component import androidx.compose.animation.* +import androidx.compose.foundation.layout.WindowInsets +import androidx.compose.foundation.layout.statusBars import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.* import androidx.compose.ui.window.Popup import androidx.compose.ui.window.PopupPositionProvider import androidx.compose.ui.window.PopupProperties -import com.google.accompanist.insets.LocalWindowInsets @Composable fun AnimatedPopup( @@ -18,7 +19,7 @@ fun AnimatedPopup( content: @Composable () -> Unit = {}, ) { val density = LocalDensity.current - val insets = LocalWindowInsets.current + val statusBarsHeight = WindowInsets.statusBars.getTop(density) Popup( properties = PopupProperties(focusable = visible), @@ -32,7 +33,7 @@ fun AnimatedPopup( ): IntOffset { return IntOffset( x = with(density) { (absoluteX).roundToPx() }, - y = with(density) { (absoluteY).roundToPx() + insets.statusBars.top } + y = with(density) { (absoluteY).roundToPx() + statusBarsHeight } ) } }, diff --git a/app/src/main/java/me/ash/reader/ui/page/common/HomeEntry.kt b/app/src/main/java/me/ash/reader/ui/page/common/HomeEntry.kt index 2a88673..d8f1fb9 100644 --- a/app/src/main/java/me/ash/reader/ui/page/common/HomeEntry.kt +++ b/app/src/main/java/me/ash/reader/ui/page/common/HomeEntry.kt @@ -1,18 +1,9 @@ package me.ash.reader.ui.page.common import androidx.compose.animation.ExperimentalAnimationApi -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext -import com.google.accompanist.insets.ProvideWindowInsets -import com.google.accompanist.insets.navigationBarsHeight import com.google.accompanist.navigation.animation.AnimatedNavHost import com.google.accompanist.navigation.animation.rememberAnimatedNavController import com.google.accompanist.systemuicontroller.rememberSystemUiController @@ -33,42 +24,27 @@ fun HomeEntry() { val useDarkTheme = LocalUseDarkTheme.current val navController = rememberAnimatedNavController() - ProvideWindowInsets { - rememberSystemUiController().run { - setStatusBarColor(Color.Transparent, !useDarkTheme) - setSystemBarsColor(Color.Transparent, !useDarkTheme) - setNavigationBarColor(MaterialTheme.colorScheme.surface, !useDarkTheme) + rememberSystemUiController().run { + setStatusBarColor(Color.Transparent, !useDarkTheme) + setSystemBarsColor(Color.Transparent, !useDarkTheme) + setNavigationBarColor(Color.Transparent, !useDarkTheme) + } + + AnimatedNavHost( + navController = navController, + startDestination = if (context.isFirstLaunch) RouteName.STARTUP else RouteName.HOME, + ) { + animatedComposable(route = RouteName.STARTUP) { + StartupPage(navController) } - Column { - Row( - modifier = Modifier - .weight(1f) - .background(MaterialTheme.colorScheme.surface), - ) { - AnimatedNavHost( - navController = navController, - startDestination = if (context.isFirstLaunch) RouteName.STARTUP else RouteName.HOME, - ) { - animatedComposable(route = RouteName.STARTUP) { - StartupPage(navController) - } - animatedComposable(route = RouteName.HOME) { - HomePage(navController) - } - animatedComposable(route = RouteName.SETTINGS) { - SettingsPage(navController) - } - animatedComposable(route = RouteName.COLOR_AND_STYLE) { - ColorAndStyle(navController) - } - } - } - Spacer( - modifier = Modifier - .navigationBarsHeight() - .fillMaxWidth() - .background(MaterialTheme.colorScheme.surface) - ) + animatedComposable(route = RouteName.HOME) { + HomePage(navController) + } + animatedComposable(route = RouteName.SETTINGS) { + SettingsPage(navController) + } + animatedComposable(route = RouteName.COLOR_AND_STYLE) { + ColorAndStyle(navController) } } } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/HomePage.kt b/app/src/main/java/me/ash/reader/ui/page/home/HomePage.kt index ddac4d2..f3fbbff 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/HomePage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/HomePage.kt @@ -1,10 +1,7 @@ package me.ash.reader.ui.page.home import androidx.activity.compose.BackHandler -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.statusBarsPadding -import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier @@ -80,11 +77,7 @@ fun HomePage( ) } - Column( - modifier = Modifier - .background(MaterialTheme.colorScheme.surface) - .statusBarsPadding(), - ) { + Column{ ViewPager( modifier = Modifier.weight(1f), state = viewState.pagerState, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt index 2c0798b..3148f1a 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/FeedsPage.kt @@ -103,7 +103,10 @@ fun FeedsPage( } Scaffold( - modifier = Modifier.background(MaterialTheme.colorScheme.surface), + modifier = Modifier + .background(MaterialTheme.colorScheme.surface) + .statusBarsPadding() + .navigationBarsPadding(), topBar = { SmallTopAppBar( title = {}, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt index 990c17d..51d7b65 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt @@ -107,7 +107,10 @@ fun FlowPage( } Scaffold( - modifier = Modifier.background(MaterialTheme.colorScheme.surface), + modifier = Modifier + .background(MaterialTheme.colorScheme.surface) + .statusBarsPadding() + .navigationBarsPadding(), topBar = { SmallTopAppBar( title = {}, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/read/ReadBar.kt b/app/src/main/java/me/ash/reader/ui/page/home/read/ReadBar.kt index 184428f..8e51c6e 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/read/ReadBar.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/read/ReadBar.kt @@ -1,6 +1,7 @@ package me.ash.reader.ui.page.home.read import android.view.HapticFeedbackConstants +import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.FiberManualRecord @@ -39,6 +40,9 @@ fun ReadBar( var fullContent by remember { mutableStateOf(isFullContent) } Surface( + modifier = Modifier + .background(MaterialTheme.colorScheme.surface) + .navigationBarsPadding(), tonalElevation = 0.dp, ) { Box( @@ -53,7 +57,6 @@ fun ReadBar( color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.24f) ) } - Row( modifier = Modifier.fillMaxSize(), horizontalArrangement = Arrangement.SpaceAround, diff --git a/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt b/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt index f1962a0..48cab21 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/read/ReadPage.kt @@ -136,6 +136,7 @@ private fun TopBar( exit = fadeOut() + shrinkVertically(), ) { SmallTopAppBar( + modifier = Modifier.statusBarsPadding(), colors = TopAppBarDefaults.smallTopAppBarColors( containerColor = MaterialTheme.colorScheme.surface, ), @@ -182,7 +183,9 @@ private fun Content( viewState: ReadViewState, LazyListState: LazyListState = rememberLazyListState(), ) { - Column { + Column( + modifier = Modifier.statusBarsPadding(), + ) { if (articleWithFeed == null) { Spacer(modifier = Modifier.height(64.dp)) // LottieAnimation( diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/ColorAndStyle.kt b/app/src/main/java/me/ash/reader/ui/page/settings/ColorAndStyle.kt index 5220ddb..8b89719 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/ColorAndStyle.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/ColorAndStyle.kt @@ -51,7 +51,8 @@ fun ColorAndStyle( Scaffold( modifier = Modifier .background(MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface) - .statusBarsPadding(), + .statusBarsPadding() + .navigationBarsPadding(), containerColor = MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface, topBar = { SmallTopAppBar( diff --git a/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt b/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt index 0313cee..a9c565d 100644 --- a/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/settings/SettingsPage.kt @@ -3,6 +3,7 @@ package me.ash.reader.ui.page.settings import androidx.compose.foundation.background import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.statusBarsPadding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.icons.Icons @@ -30,7 +31,8 @@ fun SettingsPage( Scaffold( modifier = Modifier .background(MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface) - .statusBarsPadding(), + .statusBarsPadding() + .navigationBarsPadding(), containerColor = MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface, topBar = { SmallTopAppBar( diff --git a/app/src/main/java/me/ash/reader/ui/page/startup/StartupPage.kt b/app/src/main/java/me/ash/reader/ui/page/startup/StartupPage.kt index 4d8e46c..cde4063 100644 --- a/app/src/main/java/me/ash/reader/ui/page/startup/StartupPage.kt +++ b/app/src/main/java/me/ash/reader/ui/page/startup/StartupPage.kt @@ -38,8 +38,9 @@ fun StartupPage( Scaffold( modifier = Modifier + .background(MaterialTheme.colorScheme.surface) .statusBarsPadding() - .background(MaterialTheme.colorScheme.surface), + .navigationBarsPadding(), topBar = {}, content = { LazyColumn {