🚀 Disable gestures for bottom sheets with pager

* Disabled gestures for bottom sheets with pager (e.g. Reader Settings Bottom Sheet)
* Fixed jerky scrolling issues due to gestures

Resolves: #12
This commit is contained in:
Acclorite 2024-11-12 18:23:17 +02:00
parent 902b976bbe
commit fa73fbb732
7 changed files with 98 additions and 75 deletions

View file

@ -25,6 +25,7 @@ import androidx.compose.ui.graphics.Shape
* @param shape Shape. * @param shape Shape.
* @param containerColor Container color. * @param containerColor Container color.
* @param onDismissRequest OnDismiss callback. * @param onDismissRequest OnDismiss callback.
* @param sheetGesturesEnabled Whether bottom sheet gestures are enabled.
* @param dragHandle Drag Handle, pass null to disable. * @param dragHandle Drag Handle, pass null to disable.
* @param content Content inside [ModalBottomSheet]. * @param content Content inside [ModalBottomSheet].
*/ */
@ -37,6 +38,7 @@ fun ModalBottomSheet(
shape: Shape = BottomSheetDefaults.ExpandedShape, shape: Shape = BottomSheetDefaults.ExpandedShape,
containerColor: Color = MaterialTheme.colorScheme.surfaceContainerLow, containerColor: Color = MaterialTheme.colorScheme.surfaceContainerLow,
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
sheetGesturesEnabled: Boolean,
dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() }, dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() },
content: @Composable ColumnScope.() -> Unit content: @Composable ColumnScope.() -> Unit
) { ) {
@ -51,6 +53,7 @@ fun ModalBottomSheet(
) )
.fillMaxWidth() .fillMaxWidth()
.then(modifier), .then(modifier),
sheetGesturesEnabled = sheetGesturesEnabled,
onDismissRequest = { onDismissRequest = {
onDismissRequest() onDismissRequest()
}, },

View file

@ -25,9 +25,10 @@ fun NavigationBottomSheet(onDismissRequest: () -> Unit) {
ModalBottomSheet( ModalBottomSheet(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onDismissRequest = onDismissRequest onDismissRequest = onDismissRequest,
sheetGesturesEnabled = true
) { ) {
LazyColumn(Modifier.fillMaxWidth()) { LazyColumn(modifier = Modifier.fillMaxWidth()) {
item { item {
NavigationItem( NavigationItem(
title = stringResource(id = R.string.about_screen), title = stringResource(id = R.string.about_screen),

View file

@ -30,9 +30,10 @@ fun BookInfoMoreBottomSheet(snackbarState: SnackbarHostState) {
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onDismissRequest = { onDismissRequest = {
onEvent(BookInfoEvent.OnShowHideMoreBottomSheet(false)) onEvent(BookInfoEvent.OnShowHideMoreBottomSheet(false))
} },
sheetGesturesEnabled = true
) { ) {
LazyColumn(Modifier.fillMaxWidth()) { LazyColumn(modifier = Modifier.fillMaxWidth()) {
item { item {
NavigationItem( NavigationItem(
title = stringResource(id = R.string.details_book), title = stringResource(id = R.string.details_book),

View file

@ -66,9 +66,10 @@ fun BookInfoChangeCoverBottomSheet() {
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onDismissRequest = { onDismissRequest = {
onEvent(BookInfoEvent.OnShowHideChangeCoverBottomSheet) onEvent(BookInfoEvent.OnShowHideChangeCoverBottomSheet)
} },
sheetGesturesEnabled = true
) { ) {
LazyColumn(Modifier.fillMaxWidth()) { LazyColumn(modifier = Modifier.fillMaxWidth()) {
if (state.value.canResetCover) { if (state.value.canResetCover) {
item { item {
BookInfoChangeCoverBottomSheetItem( BookInfoChangeCoverBottomSheetItem(

View file

@ -1,8 +1,7 @@
package ua.acclorite.book_story.presentation.screens.book_info.components.details_bottom_sheet package ua.acclorite.book_story.presentation.screens.book_info.components.details_bottom_sheet
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -10,6 +9,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import ua.acclorite.book_story.R import ua.acclorite.book_story.R
import ua.acclorite.book_story.presentation.core.components.common.LazyColumnWithScrollbar
import ua.acclorite.book_story.presentation.core.components.modal_bottom_sheet.ModalBottomSheet import ua.acclorite.book_story.presentation.core.components.modal_bottom_sheet.ModalBottomSheet
import ua.acclorite.book_story.presentation.core.util.showToast import ua.acclorite.book_story.presentation.core.util.showToast
import ua.acclorite.book_story.presentation.screens.book_info.data.BookInfoEvent import ua.acclorite.book_story.presentation.screens.book_info.data.BookInfoEvent
@ -59,71 +59,86 @@ fun BookInfoDetailsBottomSheet() {
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
onDismissRequest = { onDismissRequest = {
onEvent(BookInfoEvent.OnShowHideDetailsBottomSheet) onEvent(BookInfoEvent.OnShowHideDetailsBottomSheet)
} },
sheetGesturesEnabled = true
) { ) {
BookInfoDetailsBottomSheetItem( LazyColumnWithScrollbar(
title = stringResource(id = R.string.file_name), modifier = Modifier.fillMaxWidth(),
description = state.value.book.filePath.substringAfterLast("/").trim() contentPadding = PaddingValues(bottom = 8.dp)
) { ) {
onEvent( item {
BookInfoEvent.OnCopyToClipboard( BookInfoDetailsBottomSheetItem(
context, title = stringResource(id = R.string.file_name),
state.value.book.filePath.substringAfterLast("/").trim(), description = state.value.book.filePath.substringAfterLast("/").trim()
success = { ) {
context.getString(R.string.copied) onEvent(
.showToast(context = context, longToast = false) BookInfoEvent.OnCopyToClipboard(
} context,
)) state.value.book.filePath.substringAfterLast("/").trim(),
} success = {
BookInfoDetailsBottomSheetItem( context.getString(R.string.copied)
title = stringResource(id = R.string.file_path), .showToast(context = context, longToast = false)
description = state.value.book.filePath.trim() }
) { ))
onEvent( }
BookInfoEvent.OnCopyToClipboard(
context,
state.value.book.filePath.trim(),
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
))
}
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_last_opened),
description = if (state.value.book.lastOpened != null) lastOpened
else stringResource(id = R.string.never)
) {
if (state.value.book.lastOpened != null) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
lastOpened,
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
))
} }
}
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_size),
description = fileSize.ifBlank { stringResource(id = R.string.unknown) }
) {
if (fileSize.isNotBlank()) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
fileSize,
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
)
)
}
}
Spacer(modifier = Modifier.height(8.dp)) item {
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_path),
description = state.value.book.filePath.trim()
) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
state.value.book.filePath.trim(),
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
))
}
}
item {
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_last_opened),
description = if (state.value.book.lastOpened != null) lastOpened
else stringResource(id = R.string.never)
) {
if (state.value.book.lastOpened != null) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
lastOpened,
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
))
}
}
}
item {
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_size),
description = fileSize.ifBlank { stringResource(id = R.string.unknown) }
) {
if (fileSize.isNotBlank()) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
fileSize,
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
)
)
}
}
}
}
} }
} }

View file

@ -45,7 +45,8 @@ fun BrowseFilterBottomSheet() {
dragHandle = {}, dragHandle = {},
onDismissRequest = { onDismissRequest = {
onEvent(BrowseEvent.OnShowHideFilterBottomSheet) onEvent(BrowseEvent.OnShowHideFilterBottomSheet)
} },
sheetGesturesEnabled = false
) { ) {
BrowseFilterBottomSheetTabRow( BrowseFilterBottomSheetTabRow(
onEvent = onEvent, onEvent = onEvent,
@ -55,7 +56,7 @@ fun BrowseFilterBottomSheet() {
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page -> HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
when (page) { when (page) {
0 -> { 0 -> {
LazyColumnWithScrollbar(Modifier.fillMaxSize()) { LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
BrowseGeneralSubcategory( BrowseGeneralSubcategory(
showTitle = false, showTitle = false,
showDivider = false, showDivider = false,
@ -66,7 +67,7 @@ fun BrowseFilterBottomSheet() {
} }
1 -> { 1 -> {
LazyColumnWithScrollbar(Modifier.fillMaxSize()) { LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
BrowseFilterSubcategory( BrowseFilterSubcategory(
showTitle = false, showTitle = false,
showDivider = false, showDivider = false,
@ -77,7 +78,7 @@ fun BrowseFilterBottomSheet() {
} }
2 -> { 2 -> {
LazyColumnWithScrollbar(Modifier.fillMaxSize()) { LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
BrowseSortSubcategory( BrowseSortSubcategory(
showTitle = false, showTitle = false,
showDivider = false, showDivider = false,

View file

@ -82,7 +82,8 @@ fun ReaderSettingsBottomSheet() {
dragHandle = {}, dragHandle = {},
onDismissRequest = { onDismissRequest = {
onEvent(ReaderEvent.OnShowHideSettingsBottomSheet(false)) onEvent(ReaderEvent.OnShowHideSettingsBottomSheet(false))
} },
sheetGesturesEnabled = false
) { ) {
ReaderSettingsBottomSheetTabRow(pagerState = pagerState) ReaderSettingsBottomSheetTabRow(pagerState = pagerState)