Skip to content

Commit

Permalink
- Refactor: Improve Bottom Bar Behavior in Reader
Browse files Browse the repository at this point in the history
This commit refactors the bottom bar behavior in the reader to:

- Move the bottom bar outside the floating bar logic, ensuring it's always visible when `showItems` is true.
- Add a `LaunchedEffect` to reset the floating bar's offset when `showItems` becomes true.
- Update the BannerBox composable to use a fun interface for `BannerScope`, simplifying its usage.

This improves the overall user experience by making the bottom bar controls more consistent and predictable.
  • Loading branch information
jacobrein committed Oct 22, 2024
1 parent ac82f6a commit 687db86
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,12 @@ fun OtakuBannerBox(
) {
var itemInfo by remember { mutableStateOf<ItemModel?>(null) }

var bannerScope by remember { mutableStateOf<BannerScope?>(null) }
val bannerScope = BannerScope { itemModel -> itemInfo = itemModel }

DisposableEffect(Unit) {
bannerScope = object : BannerScope {
override fun newItemModel(itemModel: ItemModel?) {
itemInfo = itemModel
}
}
/*DisposableEffect(Unit) {
bannerScope = BannerScope { itemModel -> itemInfo = itemModel }
onDispose { bannerScope = null }
}
}*/

BannerBox(
modifier = modifier,
Expand Down Expand Up @@ -534,11 +530,11 @@ fun OtakuBannerBox(
)
}
},
content = { bannerScope?.content() }
content = { bannerScope.content() }
)
}

interface BannerScope {
fun interface BannerScope {
//TODO: Maybe add a modifier into here for onLongClick?
fun newItemModel(itemModel: ItemModel?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ fun ReadView(

val exitAlwaysScrollBehavior = FloatingAppBarDefaults.exitAlwaysScrollBehavior(exitDirection = FloatingAppBarExitDirection.Bottom)

LaunchedEffect(showItems) {
if (showItems) {
exitAlwaysScrollBehavior.state.offset = 0f
}
}

BackHandler(drawerState.isOpen || showBottomSheet) {
scope.launch {
when {
Expand Down Expand Up @@ -281,21 +287,21 @@ fun ReadView(
}
},
bottomBar = {
if (floatingBottomBar) {
FloatingBottomBar(
onPageSelectClick = { showBottomSheet = true },
onSettingsClick = { settingsPopup = true },
chapterChange = ::showToast,
onChapterShow = { scope.launch { drawerState.open() } },
vm = readVm,
exitAlwaysScrollBehavior = exitAlwaysScrollBehavior
)
} else {
AnimatedVisibility(
visible = showItems,
enter = slideInVertically { it } + fadeIn(),
exit = slideOutVertically { it } + fadeOut()
) {
AnimatedVisibility(
visible = showItems,
enter = slideInVertically { it } + fadeIn(),
exit = slideOutVertically { it } + fadeOut()
) {
if (floatingBottomBar) {
FloatingBottomBar(
onPageSelectClick = { showBottomSheet = true },
onSettingsClick = { settingsPopup = true },
chapterChange = ::showToast,
onChapterShow = { scope.launch { drawerState.open() } },
vm = readVm,
exitAlwaysScrollBehavior = exitAlwaysScrollBehavior.takeIf { showItems }
)
} else {
BottomBar(
onPageSelectClick = { showBottomSheet = true },
onSettingsClick = { settingsPopup = true },
Expand Down

0 comments on commit 687db86

Please sign in to comment.