Constrain reader sheet to max 75% of height

This commit is contained in:
arkon 2023-07-16 09:59:17 -04:00
parent 22c6dbda3f
commit a3a3f44056
4 changed files with 41 additions and 28 deletions

View file

@ -6,6 +6,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith import androidx.compose.animation.togetherWith
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.Dialog
@ -70,6 +71,7 @@ fun NavigatorAdaptiveSheet(
*/ */
@Composable @Composable
fun AdaptiveSheet( fun AdaptiveSheet(
modifier: Modifier = Modifier,
tonalElevation: Dp = 1.dp, tonalElevation: Dp = 1.dp,
enableSwipeDismiss: Boolean = true, enableSwipeDismiss: Boolean = true,
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
@ -82,6 +84,7 @@ fun AdaptiveSheet(
properties = dialogProperties, properties = dialogProperties,
) { ) {
AdaptiveSheetImpl( AdaptiveSheetImpl(
modifier = modifier,
isTabletUi = isTabletUi, isTabletUi = isTabletUi,
tonalElevation = tonalElevation, tonalElevation = tonalElevation,
enableSwipeDismiss = enableSwipeDismiss, enableSwipeDismiss = enableSwipeDismiss,

View file

@ -40,6 +40,7 @@ object TabbedDialogPaddings {
@Composable @Composable
fun TabbedDialog( fun TabbedDialog(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
tabTitles: List<String>, tabTitles: List<String>,
tabOverflowMenuContent: (@Composable ColumnScope.(() -> Unit) -> Unit)? = null, tabOverflowMenuContent: (@Composable ColumnScope.(() -> Unit) -> Unit)? = null,
@ -47,6 +48,7 @@ fun TabbedDialog(
content: @Composable (Int) -> Unit, content: @Composable (Int) -> Unit,
) { ) {
AdaptiveSheet( AdaptiveSheet(
modifier = modifier,
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
) { ) {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()

View file

@ -1,6 +1,8 @@
package eu.kanade.presentation.reader.settings package eu.kanade.presentation.reader.settings
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
@ -30,35 +32,38 @@ fun ReaderSettingsDialog(
) )
val pagerState = rememberPagerState { tabTitles.size } val pagerState = rememberPagerState { tabTitles.size }
TabbedDialog( BoxWithConstraints {
onDismissRequest = { TabbedDialog(
onDismissRequest() modifier = Modifier.heightIn(max = maxHeight * 0.75f),
onShowMenus() onDismissRequest = {
}, onDismissRequest()
tabTitles = tabTitles,
pagerState = pagerState,
) { page ->
val window = (LocalView.current.parent as? DialogWindowProvider)?.window
LaunchedEffect(pagerState.currentPage) {
if (pagerState.currentPage == 2) {
window?.setDimAmount(0f)
onHideMenus()
} else {
window?.setDimAmount(0.5f)
onShowMenus() onShowMenus()
} },
} tabTitles = tabTitles,
pagerState = pagerState,
) { page ->
val window = (LocalView.current.parent as? DialogWindowProvider)?.window
Column( LaunchedEffect(pagerState.currentPage) {
modifier = Modifier if (pagerState.currentPage == 2) {
.padding(vertical = TabbedDialogPaddings.Vertical) window?.setDimAmount(0f)
.verticalScroll(rememberScrollState()), onHideMenus()
) { } else {
when (page) { window?.setDimAmount(0.5f)
0 -> ReadingModePage(screenModel) onShowMenus()
1 -> GeneralPage(screenModel) }
2 -> ColorFilterPage(screenModel) }
Column(
modifier = Modifier
.padding(vertical = TabbedDialogPaddings.Vertical)
.verticalScroll(rememberScrollState()),
) {
when (page) {
0 -> ReadingModePage(screenModel)
1 -> GeneralPage(screenModel)
2 -> ColorFilterPage(screenModel)
}
} }
} }
} }

View file

@ -56,6 +56,7 @@ private val sheetAnimationSpec = tween<Float>(durationMillis = 350)
@Composable @Composable
fun AdaptiveSheet( fun AdaptiveSheet(
modifier: Modifier = Modifier,
isTabletUi: Boolean, isTabletUi: Boolean,
tonalElevation: Dp, tonalElevation: Dp,
enableSwipeDismiss: Boolean, enableSwipeDismiss: Boolean,
@ -97,7 +98,8 @@ fun AdaptiveSheet(
onClick = {}, onClick = {},
) )
.systemBarsPadding() .systemBarsPadding()
.padding(vertical = 16.dp), .padding(vertical = 16.dp)
.then(modifier),
shape = MaterialTheme.shapes.extraLarge, shape = MaterialTheme.shapes.extraLarge,
tonalElevation = tonalElevation, tonalElevation = tonalElevation,
content = { content = {
@ -160,6 +162,7 @@ fun AdaptiveSheet(
Modifier Modifier
}, },
) )
.then(modifier)
.offset { .offset {
IntOffset( IntOffset(
0, 0,