feat(pdf-viewer): implement pan lock to disable horizontal movement (#9)

- Add `isScrollLocked` state to `PdfViewerScreen` to toggle panning behavior.
- Replace "Import SVG" debug icon with a Lock/Unlock toggle in the Top App Bar.
- Update `PdfVerticalReader` and `PdfPageComposable` to strictly zero out X-axis pan deltas and fling velocities when locked.
- Maintain zoom and vertical scrolling functionality while panning is locked.
This commit is contained in:
Aryan 2026-02-26 20:05:45 +05:30 committed by GitHub
parent f2daebe0a5
commit ea31765612
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 35 deletions

View file

@ -214,6 +214,7 @@ internal fun PdfVerticalReader(
onTextBoxMoved: (String, Int, Rect) -> Unit = { _, _, _ -> },
isAutoScrollPlaying: Boolean = false,
isAutoScrollTempPaused: Boolean = false,
isScrollLocked: Boolean = false,
autoScrollSpeed: Float = 1.0f,
onInteractionListener: () -> Unit = {}
) {
@ -837,7 +838,7 @@ internal fun PdfVerticalReader(
})
}
.pointerInput(totalDocHeight, isEditMode, selectedTool) {
.pointerInput(totalDocHeight, isEditMode, selectedTool, isScrollLocked) {
val tracker = VelocityTracker()
val decay = exponentialDecay<Float>()
val touchSlop = viewConfiguration.touchSlop
@ -916,7 +917,9 @@ internal fun PdfVerticalReader(
}
val zoomChange = event.calculateZoom()
val panChange = event.calculatePan()
val rawPanChange = event.calculatePan()
val panChange = if (isScrollLocked) Offset(0f, rawPanChange.y) else rawPanChange
val centroid = event.calculateCentroid(useCurrent = false)
val panMagnitude = panChange.getDistance()
val currentCentroidSize = event.calculateCentroidSize(
@ -1065,7 +1068,7 @@ internal fun PdfVerticalReader(
coroutineScope {
launch {
val rawX = velocity.x * flingSensitivity
val flingX = if (abs(rawX) > minFlingVelocity) rawX
val flingX = if (abs(rawX) > minFlingVelocity && !isScrollLocked) rawX
else 0f
if (flingX != 0f) panXAnimatable.animateDecay(