Skip to content

Commit

Permalink
Making the first scroll in the manga reader not show the bars and mak…
Browse files Browse the repository at this point in the history
…ing it so that one can not show the bars on the first page
  • Loading branch information
jakepurple13 committed Sep 8, 2023
1 parent 7fc8509 commit 594dd21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ class ReadViewModel(
loadPages(modelPath)
}

var showInfo by mutableStateOf(false)
var showInfo by mutableStateOf(true)

var firstScroll by mutableStateOf(true)

fun addChapterToWatched(newChapter: Int, chapter: () -> Unit) {
currentChapter = newChapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,16 @@ fun ReadView(
activity.runOnUiThread { Toast.makeText(context, R.string.addedChapterItem, Toast.LENGTH_SHORT).show() }
}

val listShowItems = (listState.isScrolledToTheEnd() || listState.isScrolledToTheBeginning()) && listOrPager
val pagerShowItems = (pagerState.currentPage == 0 || pagerState.currentPage >= pages.size) && !listOrPager
val listShowItems by remember { derivedStateOf { listState.isScrolledToTheEnd() && listOrPager } }
val pagerShowItems by remember { derivedStateOf { pagerState.currentPage >= pages.size && !listOrPager } }

val listIndex by remember { derivedStateOf { listState.layoutInfo.visibleItemsInfo.firstOrNull()?.index ?: 0 } }
LaunchedEffect(listIndex, pagerState.currentPage, readVm.showInfo) {
if (readVm.firstScroll && (listIndex > 0 || pagerState.currentPage > 0)) {
readVm.showInfo = false
readVm.firstScroll = false
}
}

LaunchedEffect(pagerState) {
snapshotFlow { pagerState.currentPage }.collect { listState.scrollToItem(it) }
Expand All @@ -303,7 +311,7 @@ fun ReadView(
snapshotFlow { listState.firstVisibleItemIndex }.collect { pagerState.scrollToPage(it) }
}

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

val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())

Expand Down

0 comments on commit 594dd21

Please sign in to comment.