Migrate accompanist/insets to androidx.compose.foundation
This commit is contained in:
parent
9c82890640
commit
8546f0f1ed
|
@ -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 }
|
||||
)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -103,7 +103,10 @@ fun FeedsPage(
|
|||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.background(MaterialTheme.colorScheme.surface),
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding(),
|
||||
topBar = {
|
||||
SmallTopAppBar(
|
||||
title = {},
|
||||
|
|
|
@ -107,7 +107,10 @@ fun FlowPage(
|
|||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.background(MaterialTheme.colorScheme.surface),
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.statusBarsPadding()
|
||||
.navigationBarsPadding(),
|
||||
topBar = {
|
||||
SmallTopAppBar(
|
||||
title = {},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -38,8 +38,9 @@ fun StartupPage(
|
|||
|
||||
Scaffold(
|
||||
modifier = Modifier
|
||||
.background(MaterialTheme.colorScheme.surface)
|
||||
.statusBarsPadding()
|
||||
.background(MaterialTheme.colorScheme.surface),
|
||||
.navigationBarsPadding(),
|
||||
topBar = {},
|
||||
content = {
|
||||
LazyColumn {
|
||||
|
|
Loading…
Reference in New Issue
Block a user