🛠️ Apply cutout padding for Tablet UI
* Applied cutout padding (if there is) to side padding while in Tablet UI mode
This commit is contained in:
parent
b432b7a3e5
commit
84d78caef5
2 changed files with 16 additions and 26 deletions
|
|
@ -2,11 +2,11 @@ package ua.acclorite.book_story.presentation.components.custom_navigation_rail
|
|||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.calculateStartPadding
|
||||
import androidx.compose.foundation.layout.displayCutout
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.padding
|
||||
|
|
@ -31,7 +31,7 @@ import ua.acclorite.book_story.presentation.data.LocalNavigator
|
|||
* Custom Navigation Rail. It is used to be shown on Tablets.
|
||||
*/
|
||||
@Composable
|
||||
fun BoxScope.CustomNavigationRail() {
|
||||
fun CustomNavigationRail() {
|
||||
var currentScreen: Route? by remember { mutableStateOf(null) }
|
||||
val navigator = LocalNavigator.current
|
||||
val layoutDirection = LocalLayoutDirection.current
|
||||
|
|
@ -50,14 +50,14 @@ fun BoxScope.CustomNavigationRail() {
|
|||
|
||||
NavigationRail(
|
||||
modifier = Modifier
|
||||
.align(
|
||||
Alignment.CenterStart
|
||||
)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainer)
|
||||
.padding(
|
||||
start = WindowInsets.navigationBars
|
||||
.asPaddingValues()
|
||||
.calculateStartPadding(layoutDirection)
|
||||
.calculateStartPadding(layoutDirection) +
|
||||
WindowInsets.displayCutout
|
||||
.asPaddingValues()
|
||||
.calculateStartPadding(layoutDirection)
|
||||
)
|
||||
.width(80.dp)
|
||||
.padding(horizontal = 12.dp),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import androidx.compose.animation.EnterTransition
|
|||
import androidx.compose.animation.ExitTransition
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.calculateEndPadding
|
||||
import androidx.compose.foundation.layout.calculateStartPadding
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
|
|
@ -32,7 +32,6 @@ import androidx.compose.ui.Modifier
|
|||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalLayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
|
|
@ -332,7 +331,7 @@ class Navigator @AssistedInject constructor(
|
|||
exitBarAnim: ExitTransition = Transitions.SlidingTransitionOut,
|
||||
backExitBarAnim: ExitTransition = Transitions.BackSlidingTransitionOut,
|
||||
bottomBar: @Composable () -> Unit,
|
||||
navigationRail: @Composable BoxScope.() -> Unit,
|
||||
navigationRail: @Composable () -> Unit,
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val activity = LocalContext.current as ComponentActivity
|
||||
|
|
@ -365,35 +364,26 @@ class Navigator @AssistedInject constructor(
|
|||
},
|
||||
containerColor = MaterialTheme.colorScheme.surface
|
||||
) {
|
||||
Box(
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
) {
|
||||
if (tabletUI) {
|
||||
navigationRail()
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxSize()
|
||||
.padding(
|
||||
end = it.calculateEndPadding(
|
||||
layoutDirection
|
||||
),
|
||||
end = it.calculateEndPadding(layoutDirection),
|
||||
bottom = it.calculateBottomPadding(),
|
||||
start = if (tabletUI) {
|
||||
80.dp + it.calculateStartPadding(
|
||||
layoutDirection
|
||||
)
|
||||
} else {
|
||||
it.calculateStartPadding(
|
||||
layoutDirection
|
||||
)
|
||||
},
|
||||
start = it.calculateStartPadding(layoutDirection)
|
||||
)
|
||||
) {
|
||||
content()
|
||||
}
|
||||
|
||||
if (tabletUI) {
|
||||
navigationRail()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue