usuiat / Zoomable

Jetpack Compose library that enables contents zooming with pinch gesture.
https://usuiat.github.io/Zoomable/
Apache License 2.0
375 stars 20 forks source link

Use nested scroll system to achieve both Pager swiping and zoomed image dragging #125

Closed usuiat closed 10 months ago

usuiat commented 10 months ago

Issue

Overview

As described in the issue #93, pinch gestures sometimes caused expanding the image and swiping the pages concurrently. This pull request resolve it by using the nested scroll system instead of controlling cosumption of PointerInputEvents.

Before

If the detected PointerInputEvents were recognized as a pinch gesture, Modifier.zoomable() consumed them to enlarge the image. On the other hands, if they were recognized as a swipe gesture, Modifier.zoomable() didn't consume them and propagated them to the Pager. However, the event was propagated to the Pager until the determination of whether the gesture was a pinch gesture or a swipe gesture was completed. If the gesture was determined to be a pinch gesture after several PointerInputEvents were propagated to the Pager, both the Pager swipe and the image enlargement were occurring simultaneously.

After

Now Modifier.zoomable() consumes all of PointerInputEvents. After Modifier.zoomable() determines that the gesture is a swipe gesture, it issues a scroll event using NestedScrollDispatcher.

API Change

Pass ZoomableDefault.pageNestedScrollConnection to Pager when you apply Modifier.zoomable() to the contents on the Pager.

HorizontalPager(
    pageNestedScrollConnection = ZoomableDefaults.pageNestedScrollConnection,
) {
    Image(modifier = Modifier.zoomable(zoomState))
}