Skip to content

Commit

Permalink
πŸš€ Disable gestures for bottom sheets with pager
Browse files Browse the repository at this point in the history
* Disabled gestures for bottom sheets with pager (e.g. Reader Settings Bottom Sheet)
* Fixed jerky scrolling issues due to gestures

Resolves: #12
  • Loading branch information
Acclorite committed Nov 12, 2024
1 parent 902b976 commit fa73fbb
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.compose.ui.graphics.Shape
* @param shape Shape.
* @param containerColor Container color.
* @param onDismissRequest OnDismiss callback.
* @param sheetGesturesEnabled Whether bottom sheet gestures are enabled.
* @param dragHandle Drag Handle, pass null to disable.
* @param content Content inside [ModalBottomSheet].
*/
Expand All @@ -37,6 +38,7 @@ fun ModalBottomSheet(
shape: Shape = BottomSheetDefaults.ExpandedShape,
containerColor: Color = MaterialTheme.colorScheme.surfaceContainerLow,
onDismissRequest: () -> Unit,
sheetGesturesEnabled: Boolean,
dragHandle: @Composable (() -> Unit)? = { BottomSheetDefaults.DragHandle() },
content: @Composable ColumnScope.() -> Unit
) {
Expand All @@ -51,6 +53,7 @@ fun ModalBottomSheet(
)
.fillMaxWidth()
.then(modifier),
sheetGesturesEnabled = sheetGesturesEnabled,
onDismissRequest = {
onDismissRequest()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ fun NavigationBottomSheet(onDismissRequest: () -> Unit) {

ModalBottomSheet(
modifier = Modifier.fillMaxWidth(),
onDismissRequest = onDismissRequest
onDismissRequest = onDismissRequest,
sheetGesturesEnabled = true
) {
LazyColumn(Modifier.fillMaxWidth()) {
LazyColumn(modifier = Modifier.fillMaxWidth()) {
item {
NavigationItem(
title = stringResource(id = R.string.about_screen),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ fun BookInfoMoreBottomSheet(snackbarState: SnackbarHostState) {
modifier = Modifier.fillMaxWidth(),
onDismissRequest = {
onEvent(BookInfoEvent.OnShowHideMoreBottomSheet(false))
}
},
sheetGesturesEnabled = true
) {
LazyColumn(Modifier.fillMaxWidth()) {
LazyColumn(modifier = Modifier.fillMaxWidth()) {
item {
NavigationItem(
title = stringResource(id = R.string.details_book),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ fun BookInfoChangeCoverBottomSheet() {
modifier = Modifier.fillMaxWidth(),
onDismissRequest = {
onEvent(BookInfoEvent.OnShowHideChangeCoverBottomSheet)
}
},
sheetGesturesEnabled = true
) {
LazyColumn(Modifier.fillMaxWidth()) {
LazyColumn(modifier = Modifier.fillMaxWidth()) {
if (state.value.canResetCover) {
item {
BookInfoChangeCoverBottomSheetItem(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
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.util.showToast
import ua.acclorite.book_story.presentation.screens.book_info.data.BookInfoEvent
Expand Down Expand Up @@ -59,71 +59,86 @@ fun BookInfoDetailsBottomSheet() {
modifier = Modifier.fillMaxWidth(),
onDismissRequest = {
onEvent(BookInfoEvent.OnShowHideDetailsBottomSheet)
}
},
sheetGesturesEnabled = true
) {
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_name),
description = state.value.book.filePath.substringAfterLast("/").trim()
) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
state.value.book.filePath.substringAfterLast("/").trim(),
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
))
}
BookInfoDetailsBottomSheetItem(
title = stringResource(id = R.string.file_path),
description = state.value.book.filePath.trim()
LazyColumnWithScrollbar(
modifier = Modifier.fillMaxWidth(),
contentPadding = PaddingValues(bottom = 8.dp)
) {
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_name),
description = state.value.book.filePath.substringAfterLast("/").trim()
) {
onEvent(
BookInfoEvent.OnCopyToClipboard(
context,
state.value.book.filePath.substringAfterLast("/").trim(),
success = {
context.getString(R.string.copied)
.showToast(context = context, longToast = false)
}
))
}
}

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)
}
))
}
))
}
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)
}
)
)

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)
}
)
)
}
}
}
}

Spacer(modifier = Modifier.height(8.dp))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fun BrowseFilterBottomSheet() {
dragHandle = {},
onDismissRequest = {
onEvent(BrowseEvent.OnShowHideFilterBottomSheet)
}
},
sheetGesturesEnabled = false
) {
BrowseFilterBottomSheetTabRow(
onEvent = onEvent,
Expand All @@ -55,7 +56,7 @@ fun BrowseFilterBottomSheet() {
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
when (page) {
0 -> {
LazyColumnWithScrollbar(Modifier.fillMaxSize()) {
LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
BrowseGeneralSubcategory(
showTitle = false,
showDivider = false,
Expand All @@ -66,7 +67,7 @@ fun BrowseFilterBottomSheet() {
}

1 -> {
LazyColumnWithScrollbar(Modifier.fillMaxSize()) {
LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
BrowseFilterSubcategory(
showTitle = false,
showDivider = false,
Expand All @@ -77,7 +78,7 @@ fun BrowseFilterBottomSheet() {
}

2 -> {
LazyColumnWithScrollbar(Modifier.fillMaxSize()) {
LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) {
BrowseSortSubcategory(
showTitle = false,
showDivider = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ fun ReaderSettingsBottomSheet() {
dragHandle = {},
onDismissRequest = {
onEvent(ReaderEvent.OnShowHideSettingsBottomSheet(false))
}
},
sheetGesturesEnabled = false
) {
ReaderSettingsBottomSheetTabRow(pagerState = pagerState)

Expand Down

0 comments on commit fa73fbb

Please sign in to comment.