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
|
package me.ash.reader.ui.component
|
||||||
|
|
||||||
import androidx.compose.animation.*
|
import androidx.compose.animation.*
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
import androidx.compose.foundation.layout.statusBars
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.unit.*
|
import androidx.compose.ui.unit.*
|
||||||
import androidx.compose.ui.window.Popup
|
import androidx.compose.ui.window.Popup
|
||||||
import androidx.compose.ui.window.PopupPositionProvider
|
import androidx.compose.ui.window.PopupPositionProvider
|
||||||
import androidx.compose.ui.window.PopupProperties
|
import androidx.compose.ui.window.PopupProperties
|
||||||
import com.google.accompanist.insets.LocalWindowInsets
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AnimatedPopup(
|
fun AnimatedPopup(
|
||||||
|
@ -18,7 +19,7 @@ fun AnimatedPopup(
|
||||||
content: @Composable () -> Unit = {},
|
content: @Composable () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
val insets = LocalWindowInsets.current
|
val statusBarsHeight = WindowInsets.statusBars.getTop(density)
|
||||||
|
|
||||||
Popup(
|
Popup(
|
||||||
properties = PopupProperties(focusable = visible),
|
properties = PopupProperties(focusable = visible),
|
||||||
|
@ -32,7 +33,7 @@ fun AnimatedPopup(
|
||||||
): IntOffset {
|
): IntOffset {
|
||||||
return IntOffset(
|
return IntOffset(
|
||||||
x = with(density) { (absoluteX).roundToPx() },
|
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
|
package me.ash.reader.ui.page.common
|
||||||
|
|
||||||
import androidx.compose.animation.ExperimentalAnimationApi
|
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.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
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.AnimatedNavHost
|
||||||
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||||
|
@ -33,42 +24,27 @@ fun HomeEntry() {
|
||||||
val useDarkTheme = LocalUseDarkTheme.current
|
val useDarkTheme = LocalUseDarkTheme.current
|
||||||
val navController = rememberAnimatedNavController()
|
val navController = rememberAnimatedNavController()
|
||||||
|
|
||||||
ProvideWindowInsets {
|
rememberSystemUiController().run {
|
||||||
rememberSystemUiController().run {
|
setStatusBarColor(Color.Transparent, !useDarkTheme)
|
||||||
setStatusBarColor(Color.Transparent, !useDarkTheme)
|
setSystemBarsColor(Color.Transparent, !useDarkTheme)
|
||||||
setSystemBarsColor(Color.Transparent, !useDarkTheme)
|
setNavigationBarColor(Color.Transparent, !useDarkTheme)
|
||||||
setNavigationBarColor(MaterialTheme.colorScheme.surface, !useDarkTheme)
|
}
|
||||||
|
|
||||||
|
AnimatedNavHost(
|
||||||
|
navController = navController,
|
||||||
|
startDestination = if (context.isFirstLaunch) RouteName.STARTUP else RouteName.HOME,
|
||||||
|
) {
|
||||||
|
animatedComposable(route = RouteName.STARTUP) {
|
||||||
|
StartupPage(navController)
|
||||||
}
|
}
|
||||||
Column {
|
animatedComposable(route = RouteName.HOME) {
|
||||||
Row(
|
HomePage(navController)
|
||||||
modifier = Modifier
|
}
|
||||||
.weight(1f)
|
animatedComposable(route = RouteName.SETTINGS) {
|
||||||
.background(MaterialTheme.colorScheme.surface),
|
SettingsPage(navController)
|
||||||
) {
|
}
|
||||||
AnimatedNavHost(
|
animatedComposable(route = RouteName.COLOR_AND_STYLE) {
|
||||||
navController = navController,
|
ColorAndStyle(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)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package me.ash.reader.ui.page.home
|
package me.ash.reader.ui.page.home
|
||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Column
|
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.*
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
@ -80,11 +77,7 @@ fun HomePage(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column{
|
||||||
modifier = Modifier
|
|
||||||
.background(MaterialTheme.colorScheme.surface)
|
|
||||||
.statusBarsPadding(),
|
|
||||||
) {
|
|
||||||
ViewPager(
|
ViewPager(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
state = viewState.pagerState,
|
state = viewState.pagerState,
|
||||||
|
|
|
@ -103,7 +103,10 @@ fun FeedsPage(
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.background(MaterialTheme.colorScheme.surface),
|
modifier = Modifier
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.statusBarsPadding()
|
||||||
|
.navigationBarsPadding(),
|
||||||
topBar = {
|
topBar = {
|
||||||
SmallTopAppBar(
|
SmallTopAppBar(
|
||||||
title = {},
|
title = {},
|
||||||
|
|
|
@ -107,7 +107,10 @@ fun FlowPage(
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.background(MaterialTheme.colorScheme.surface),
|
modifier = Modifier
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.statusBarsPadding()
|
||||||
|
.navigationBarsPadding(),
|
||||||
topBar = {
|
topBar = {
|
||||||
SmallTopAppBar(
|
SmallTopAppBar(
|
||||||
title = {},
|
title = {},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.ash.reader.ui.page.home.read
|
package me.ash.reader.ui.page.home.read
|
||||||
|
|
||||||
import android.view.HapticFeedbackConstants
|
import android.view.HapticFeedbackConstants
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.FiberManualRecord
|
import androidx.compose.material.icons.filled.FiberManualRecord
|
||||||
|
@ -39,6 +40,9 @@ fun ReadBar(
|
||||||
var fullContent by remember { mutableStateOf(isFullContent) }
|
var fullContent by remember { mutableStateOf(isFullContent) }
|
||||||
|
|
||||||
Surface(
|
Surface(
|
||||||
|
modifier = Modifier
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
|
.navigationBarsPadding(),
|
||||||
tonalElevation = 0.dp,
|
tonalElevation = 0.dp,
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
|
@ -53,7 +57,6 @@ fun ReadBar(
|
||||||
color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.24f)
|
color = MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.24f)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
horizontalArrangement = Arrangement.SpaceAround,
|
horizontalArrangement = Arrangement.SpaceAround,
|
||||||
|
|
|
@ -136,6 +136,7 @@ private fun TopBar(
|
||||||
exit = fadeOut() + shrinkVertically(),
|
exit = fadeOut() + shrinkVertically(),
|
||||||
) {
|
) {
|
||||||
SmallTopAppBar(
|
SmallTopAppBar(
|
||||||
|
modifier = Modifier.statusBarsPadding(),
|
||||||
colors = TopAppBarDefaults.smallTopAppBarColors(
|
colors = TopAppBarDefaults.smallTopAppBarColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surface,
|
containerColor = MaterialTheme.colorScheme.surface,
|
||||||
),
|
),
|
||||||
|
@ -182,7 +183,9 @@ private fun Content(
|
||||||
viewState: ReadViewState,
|
viewState: ReadViewState,
|
||||||
LazyListState: LazyListState = rememberLazyListState(),
|
LazyListState: LazyListState = rememberLazyListState(),
|
||||||
) {
|
) {
|
||||||
Column {
|
Column(
|
||||||
|
modifier = Modifier.statusBarsPadding(),
|
||||||
|
) {
|
||||||
if (articleWithFeed == null) {
|
if (articleWithFeed == null) {
|
||||||
Spacer(modifier = Modifier.height(64.dp))
|
Spacer(modifier = Modifier.height(64.dp))
|
||||||
// LottieAnimation(
|
// LottieAnimation(
|
||||||
|
|
|
@ -51,7 +51,8 @@ fun ColorAndStyle(
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface)
|
.background(MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface)
|
||||||
.statusBarsPadding(),
|
.statusBarsPadding()
|
||||||
|
.navigationBarsPadding(),
|
||||||
containerColor = MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface,
|
containerColor = MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface,
|
||||||
topBar = {
|
topBar = {
|
||||||
SmallTopAppBar(
|
SmallTopAppBar(
|
||||||
|
|
|
@ -3,6 +3,7 @@ package me.ash.reader.ui.page.settings
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.statusBarsPadding
|
import androidx.compose.foundation.layout.statusBarsPadding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
@ -30,7 +31,8 @@ fun SettingsPage(
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface)
|
.background(MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface)
|
||||||
.statusBarsPadding(),
|
.statusBarsPadding()
|
||||||
|
.navigationBarsPadding(),
|
||||||
containerColor = MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface,
|
containerColor = MaterialTheme.colorScheme.surface onLight MaterialTheme.colorScheme.inverseOnSurface,
|
||||||
topBar = {
|
topBar = {
|
||||||
SmallTopAppBar(
|
SmallTopAppBar(
|
||||||
|
|
|
@ -38,8 +38,9 @@ fun StartupPage(
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
.background(MaterialTheme.colorScheme.surface)
|
||||||
.statusBarsPadding()
|
.statusBarsPadding()
|
||||||
.background(MaterialTheme.colorScheme.surface),
|
.navigationBarsPadding(),
|
||||||
topBar = {},
|
topBar = {},
|
||||||
content = {
|
content = {
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user