From fa73fbb7321ebf2eb916996cdb3d96159199b33b Mon Sep 17 00:00:00 2001 From: Acclorite <140836141+Acclorite@users.noreply.github.com> Date: Tue, 12 Nov 2024 18:23:17 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Disable=20gestures=20for=20botto?= =?UTF-8?q?m=20sheets=20with=20pager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Disabled gestures for bottom sheets with pager (e.g. Reader Settings Bottom Sheet) * Fixed jerky scrolling issues due to gestures Resolves: #12 --- .../modal_bottom_sheet/ModalBottomSheet.kt | 3 + .../core/navigation/NavigationBottomSheet.kt | 5 +- .../components/BookInfoMoreBottomSheet.kt | 5 +- .../BookInfoChangeCoverBottomSheet.kt | 5 +- .../BookInfoDetailsBottomSheet.kt | 139 ++++++++++-------- .../BrowseFilterBottomSheet.kt | 9 +- .../ReaderSettingsBottomSheet.kt | 3 +- 7 files changed, 96 insertions(+), 73 deletions(-) diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_bottom_sheet/ModalBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_bottom_sheet/ModalBottomSheet.kt index d737c1b2..73000ce5 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_bottom_sheet/ModalBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_bottom_sheet/ModalBottomSheet.kt @@ -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]. */ @@ -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 ) { @@ -51,6 +53,7 @@ fun ModalBottomSheet( ) .fillMaxWidth() .then(modifier), + sheetGesturesEnabled = sheetGesturesEnabled, onDismissRequest = { onDismissRequest() }, diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/core/navigation/NavigationBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/core/navigation/NavigationBottomSheet.kt index 34709e29..f41b1657 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/core/navigation/NavigationBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/core/navigation/NavigationBottomSheet.kt @@ -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), diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/BookInfoMoreBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/BookInfoMoreBottomSheet.kt index 8b98f437..dfebc5ad 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/BookInfoMoreBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/BookInfoMoreBottomSheet.kt @@ -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), diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/change_cover_bottom_sheet/BookInfoChangeCoverBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/change_cover_bottom_sheet/BookInfoChangeCoverBottomSheet.kt index 80d66374..081ff32a 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/change_cover_bottom_sheet/BookInfoChangeCoverBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/change_cover_bottom_sheet/BookInfoChangeCoverBottomSheet.kt @@ -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( diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/details_bottom_sheet/BookInfoDetailsBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/details_bottom_sheet/BookInfoDetailsBottomSheet.kt index e6d180aa..abb2bff0 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/details_bottom_sheet/BookInfoDetailsBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/screens/book_info/components/details_bottom_sheet/BookInfoDetailsBottomSheet.kt @@ -1,8 +1,7 @@ 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 @@ -10,6 +9,7 @@ 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 @@ -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)) } } \ No newline at end of file diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/screens/browse/components/filter_bottom_sheet/BrowseFilterBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/screens/browse/components/filter_bottom_sheet/BrowseFilterBottomSheet.kt index 73b0def3..5f7448f4 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/screens/browse/components/filter_bottom_sheet/BrowseFilterBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/screens/browse/components/filter_bottom_sheet/BrowseFilterBottomSheet.kt @@ -45,7 +45,8 @@ fun BrowseFilterBottomSheet() { dragHandle = {}, onDismissRequest = { onEvent(BrowseEvent.OnShowHideFilterBottomSheet) - } + }, + sheetGesturesEnabled = false ) { BrowseFilterBottomSheetTabRow( onEvent = onEvent, @@ -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, @@ -66,7 +67,7 @@ fun BrowseFilterBottomSheet() { } 1 -> { - LazyColumnWithScrollbar(Modifier.fillMaxSize()) { + LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) { BrowseFilterSubcategory( showTitle = false, showDivider = false, @@ -77,7 +78,7 @@ fun BrowseFilterBottomSheet() { } 2 -> { - LazyColumnWithScrollbar(Modifier.fillMaxSize()) { + LazyColumnWithScrollbar(modifier = Modifier.fillMaxSize()) { BrowseSortSubcategory( showTitle = false, showDivider = false, diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/components/settings_bottom_sheet/ReaderSettingsBottomSheet.kt b/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/components/settings_bottom_sheet/ReaderSettingsBottomSheet.kt index 386616e6..473bf54b 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/components/settings_bottom_sheet/ReaderSettingsBottomSheet.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/screens/reader/components/settings_bottom_sheet/ReaderSettingsBottomSheet.kt @@ -82,7 +82,8 @@ fun ReaderSettingsBottomSheet() { dragHandle = {}, onDismissRequest = { onEvent(ReaderEvent.OnShowHideSettingsBottomSheet(false)) - } + }, + sheetGesturesEnabled = false ) { ReaderSettingsBottomSheetTabRow(pagerState = pagerState)