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.togetherWith
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.window.Dialog
@ -70,6 +71,7 @@ fun NavigatorAdaptiveSheet(
*/
@Composable
fun AdaptiveSheet(
modifier: Modifier = Modifier,
tonalElevation: Dp = 1.dp,
enableSwipeDismiss: Boolean = true,
onDismissRequest: () -> Unit,
@ -82,6 +84,7 @@ fun AdaptiveSheet(
properties = dialogProperties,
) {
AdaptiveSheetImpl(
modifier = modifier,
isTabletUi = isTabletUi,
tonalElevation = tonalElevation,
enableSwipeDismiss = enableSwipeDismiss,

View file

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

View file

@ -1,6 +1,8 @@
package eu.kanade.presentation.reader.settings
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.rememberScrollState
@ -30,35 +32,38 @@ fun ReaderSettingsDialog(
)
val pagerState = rememberPagerState { tabTitles.size }
TabbedDialog(
onDismissRequest = {
onDismissRequest()
onShowMenus()
},
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)
BoxWithConstraints {
TabbedDialog(
modifier = Modifier.heightIn(max = maxHeight * 0.75f),
onDismissRequest = {
onDismissRequest()
onShowMenus()
}
}
},
tabTitles = tabTitles,
pagerState = pagerState,
) { page ->
val window = (LocalView.current.parent as? DialogWindowProvider)?.window
Column(
modifier = Modifier
.padding(vertical = TabbedDialogPaddings.Vertical)
.verticalScroll(rememberScrollState()),
) {
when (page) {
0 -> ReadingModePage(screenModel)
1 -> GeneralPage(screenModel)
2 -> ColorFilterPage(screenModel)
LaunchedEffect(pagerState.currentPage) {
if (pagerState.currentPage == 2) {
window?.setDimAmount(0f)
onHideMenus()
} else {
window?.setDimAmount(0.5f)
onShowMenus()
}
}
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
fun AdaptiveSheet(
modifier: Modifier = Modifier,
isTabletUi: Boolean,
tonalElevation: Dp,
enableSwipeDismiss: Boolean,
@ -97,7 +98,8 @@ fun AdaptiveSheet(
onClick = {},
)
.systemBarsPadding()
.padding(vertical = 16.dp),
.padding(vertical = 16.dp)
.then(modifier),
shape = MaterialTheme.shapes.extraLarge,
tonalElevation = tonalElevation,
content = {
@ -160,6 +162,7 @@ fun AdaptiveSheet(
Modifier
},
)
.then(modifier)
.offset {
IntOffset(
0,