Implement vertical page panning in paged reader mode when using hardware keys (#716)

* Implement vertical page panning in paged reader mode when using hardware keys

* Pan to top or bottom of the page instead of directly moving to the previous/next page.
* Add `canPanUp`, `canPanDown`, `panUp`, `panDown` to `ReaderPageImageView`.
* Modify `moveUp` and `moveDown` in `PagerViewer` to utilize the new panning functions.

* add annotation
This commit is contained in:
Adrian Fleiszer 2025-03-07 21:49:22 +01:00 committed by GitHub
parent 62b19ffd07
commit d563e5996b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 4 deletions

View file

@ -187,6 +187,18 @@ open class ReaderPageImageView @JvmOverloads constructor(
*/
fun canPanRight(): Boolean = canPan { it.right }
// KMK -->
/**
* Check if the image can be panned up
*/
fun canPanUp(): Boolean = canPan { it.top }
/**
* Check if the image can be panned down
*/
fun canPanDown(): Boolean = canPan { it.bottom }
// KMK <--
/**
* Check whether the image can be panned.
* @param fn a function that returns the direction to check for
@ -215,6 +227,22 @@ open class ReaderPageImageView @JvmOverloads constructor(
pan { center, view -> center.also { it.x += view.width / view.scale } }
}
// KMK -->
/**
* Pans the image down by a screen's height worth.
*/
fun panDown() {
pan { center, view -> center.also { it.y += view.height / view.scale } }
}
/**
* Pans the image up by a screen's height worth.
*/
fun panUp() {
pan { center, view -> center.also { it.y -= view.height / view.scale } }
}
// KMK <--
/**
* Pans the image.
* @param fn a function that computes the new center of the image

View file

@ -384,17 +384,31 @@ abstract class PagerViewer(
}
/**
* Moves to the page at the top (or previous).
* Pans to the top of the page or if already on the top moves to the previous page.
*/
protected open fun moveUp() {
moveToPrevious()
// KMK -->
val holder = (currentPage as? ReaderPage)?.let(::getPageHolder)
if (holder != null && holder.canPanUp()) {
holder.panUp()
} else {
// KMK <--
moveToPrevious()
}
}
/**
* Moves to the page at the bottom (or next).
* Pans to the bottom of the page or if already on the bottom moves to the next page.
*/
protected open fun moveDown() {
moveToNext()
// KMK -->
val holder = (currentPage as? ReaderPage)?.let(::getPageHolder)
if (holder != null && holder.canPanDown()) {
holder.panDown()
} else {
// KMK <--
moveToNext()
}
}
/**