Added musician mode to EPUB and PDF readers, featuring tap-to-scroll regions and persistent state. Refactored auto-scroll lock functionality to support the new musician-oriented interface. (#39)

Added musician mode to EPUB and PDF readers, featuring tap-to-scroll regions and persistent state. Refactored auto-scroll lock functionality to support the new musician-oriented interface.
This commit is contained in:
Aryan 2026-03-07 21:28:15 +05:30 committed by GitHub
parent 3a31e4fc7b
commit b9f8825ad7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 298 additions and 50 deletions

View file

@ -137,8 +137,8 @@ class VerticalPdfReaderState {
internal set
internal var scrollToPageHandler: (suspend (Int) -> Unit)? = null
internal var snapToPageHandler: (suspend (Int) -> Unit)? = null
internal var scrollByHandler: (suspend (Float) -> Unit)? = null
suspend fun scrollToPage(pageIndex: Int) {
scrollToPageHandler?.invoke(pageIndex)
@ -147,6 +147,10 @@ class VerticalPdfReaderState {
suspend fun snapToPage(pageIndex: Int) {
snapToPageHandler?.invoke(pageIndex)
}
suspend fun scrollBy(delta: Float) {
scrollByHandler?.invoke(delta)
}
}
@Composable
@ -414,6 +418,22 @@ internal fun PdfVerticalReader(
panYAnimatable.snapTo(clampedPanY)
}
}
state.scrollByHandler = { delta ->
val currentZoom = zoomAnimatable.value
val zoomedDocHeight = totalDocHeight * currentZoom
val minPanY = (screenHeight - footerHeightPx - zoomedDocHeight).coerceAtMost(headerHeightPx)
val targetPanY = (panYAnimatable.value - delta).coerceIn(minPanY, headerHeightPx)
if (abs(targetPanY - panYAnimatable.value) > 0.5f) {
panYAnimatable.animateTo(
targetValue = targetPanY,
animationSpec = tween(durationMillis = 500, easing = FastOutSlowInEasing)
)
}
}
}
var selectionClearTrigger by remember { mutableLongStateOf(0L) }