Epub page turn animation (#23)
* Added realistic page turn animation option in epub pagination mode * Added volume key navigation support for paginated render mode and added page turn animation to "tap to change page" and "volume button to change page"
This commit is contained in:
parent
7d26e10c07
commit
1ce353ad44
6 changed files with 1203 additions and 926 deletions
|
|
@ -100,10 +100,11 @@ fun Modifier.volumeScrollHandler(
|
|||
currentChapterIndex: Int,
|
||||
totalChapters: Int,
|
||||
onScrollBy: (Int) -> Unit,
|
||||
onNavigateChapter: (offset: Int, scrollTarget: ChapterScrollPosition) -> Unit
|
||||
onNavigateChapter: (offset: Int, scrollTarget: ChapterScrollPosition) -> Unit,
|
||||
onNextPage: () -> Unit = {},
|
||||
onPrevPage: () -> Unit = {}
|
||||
): Modifier = this.onPreviewKeyEvent { keyEvent ->
|
||||
val shouldHandle = volumeScrollEnabled &&
|
||||
renderMode == RenderMode.VERTICAL_SCROLL &&
|
||||
!isTtsActive &&
|
||||
!isMusicActive
|
||||
|
||||
|
|
@ -115,25 +116,22 @@ fun Modifier.volumeScrollHandler(
|
|||
if (!isVolumeKey) return@onPreviewKeyEvent false
|
||||
|
||||
if (keyEvent.type == KeyEventType.KeyDown) {
|
||||
val direction = if (keyEvent.nativeKeyEvent.keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) 1 else -1
|
||||
val isAtBottom = (currentScrollY + currentClientHeight) >= (currentScrollHeight - 2)
|
||||
val isNext = keyEvent.nativeKeyEvent.keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
|
||||
|
||||
Timber.d("Dir: $direction, AtBottom: $isAtBottom, Y: $currentScrollY")
|
||||
if (renderMode == RenderMode.VERTICAL_SCROLL) {
|
||||
val direction = if (isNext) 1 else -1
|
||||
val isAtBottom = (currentScrollY + currentClientHeight) >= (currentScrollHeight - 2)
|
||||
|
||||
if (direction == -1 && currentScrollY == 0) {
|
||||
// Top -> Prev Chapter
|
||||
if (currentChapterIndex > 0) {
|
||||
onNavigateChapter(-1, ChapterScrollPosition.END)
|
||||
}
|
||||
} else if (direction == 1 && isAtBottom) {
|
||||
// Bottom -> Next Chapter
|
||||
if (currentChapterIndex < totalChapters - 1) {
|
||||
onNavigateChapter(1, ChapterScrollPosition.START)
|
||||
if (direction == -1 && currentScrollY == 0) {
|
||||
if (currentChapterIndex > 0) onNavigateChapter(-1, ChapterScrollPosition.END)
|
||||
} else if (direction == 1 && isAtBottom) {
|
||||
if (currentChapterIndex < totalChapters - 1) onNavigateChapter(1, ChapterScrollPosition.START)
|
||||
} else {
|
||||
val scrollAmount = (currentClientHeight * 0.25).toInt() * direction
|
||||
onScrollBy(scrollAmount)
|
||||
}
|
||||
} else {
|
||||
// Scroll
|
||||
val scrollAmount = (currentClientHeight * 0.25).toInt() * direction
|
||||
onScrollBy(scrollAmount)
|
||||
if (isNext) onNextPage() else onPrevPage()
|
||||
}
|
||||
}
|
||||
true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue