Skip to content

Commit

Permalink
NEW COMPOSE UPDATE WITH BOTTOM APP BAR SCROLL BEHAVIOR!
Browse files Browse the repository at this point in the history
  • Loading branch information
jakepurple13 committed Sep 20, 2023
1 parent e55d8d9 commit d17a6b4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ziplineVersion = "1.1.0"
landscapist = "2.2.8"
protobufVersion = "3.24.2"
sketchVersion = "3.2.5"
composeBomVersion = "2023.10.00-alpha01"
composeBomVersion = "2023.10.00-alpha02"

### MangaWorld
piasy = "1.8.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.expandHorizontally
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkHorizontally
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
Expand Down Expand Up @@ -77,6 +73,8 @@ import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.BottomAppBarDefaults
import androidx.compose.material3.BottomAppBarScrollBehavior
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CenterAlignedTopAppBar
Expand Down Expand Up @@ -313,7 +311,20 @@ fun ReadView(

val showItems by remember { derivedStateOf { readVm.showInfo || listShowItems || pagerShowItems } }

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior(canScroll = { !showItems })
val bottomBarScrollBehavior = BottomAppBarDefaults.exitAlwaysScrollBehavior(canScroll = { !showItems })

LaunchedEffect(showItems) {
if (showItems) {
//Expand
scrollBehavior.state.heightOffset = 0f
bottomBarScrollBehavior.state.heightOffset = 0f
} else {
//Collapse
scrollBehavior.state.heightOffset = -1000f
bottomBarScrollBehavior.state.heightOffset = -1000f
}
}

val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
var showBottomSheet by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -353,34 +364,37 @@ fun ReadView(
gesturesEnabled = readVm.list.size > 1
) {
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
modifier = Modifier
.nestedScroll(scrollBehavior.nestedScrollConnection)
.nestedScroll(bottomBarScrollBehavior.nestedScrollConnection),
topBar = {
AnimatedVisibility(
/*AnimatedVisibility(
visible = showItems,
enter = slideInVertically() + fadeIn(),
exit = slideOutVertically() + fadeOut()
) {
TopBar(
scrollBehavior = scrollBehavior,
pages = pages,
currentPage = currentPage,
vm = readVm
)
}
) {*/
TopBar(
scrollBehavior = scrollBehavior,
pages = pages,
currentPage = currentPage,
vm = readVm
)
//}
},
bottomBar = {
AnimatedVisibility(
/*AnimatedVisibility(
visible = showItems,
enter = slideInVertically { it / 2 } + fadeIn(),
exit = slideOutVertically { it / 2 } + fadeOut()
) {
BottomBar(
onPageSelectClick = { showBottomSheet = true },
onSettingsClick = { settingsPopup = true },
chapterChange = ::showToast,
vm = readVm
)
}
) {*/
BottomBar(
onPageSelectClick = { showBottomSheet = true },
onSettingsClick = { settingsPopup = true },
chapterChange = ::showToast,
vm = readVm,
scrollBehavior = bottomBarScrollBehavior
)
//}
}
) { paddingValues ->
Box(
Expand Down Expand Up @@ -1068,17 +1082,20 @@ private fun TopBar(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun BottomBar(
vm: ReadViewModel,
onPageSelectClick: () -> Unit,
onSettingsClick: () -> Unit,
chapterChange: () -> Unit,
scrollBehavior: BottomAppBarScrollBehavior,
modifier: Modifier = Modifier,
) {
BottomAppBar(
modifier = modifier,
windowInsets = WindowInsets(0.dp)
windowInsets = WindowInsets(0.dp),
scrollBehavior = scrollBehavior
) {
val prevShown = vm.currentChapter < vm.list.lastIndex
val nextShown = vm.currentChapter > 0
Expand Down

0 comments on commit d17a6b4

Please sign in to comment.