usuiat / Zoomable

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

Zooming image and swiping page occur at same time #93

Closed usuiat closed 9 months ago

usuiat commented 1 year ago

Pinch gestures to an Image placed on a HorizontalPager may cause the image to expand and the page to swipe at the same time. While pinch gestures are detected, swiping page should be disabled.

Attached is a video of this issue. it is slow playback.

https://github.com/usuiat/Zoomable/assets/17829294/c078ffc0-4912-4ed5-b755-9542f27ea856

romainbsl commented 1 year ago

I ran into this recently. How do you think we could disable swiping gesture when pinching? I tried to disable nested scoll consumption with


[...]
var pagerScrollEnabled by remember { mutableStateOf(true) }

HorizontalPager(
   state = pagerState,
   modifier = Modifier.disabledHorizontalPointerInputScroll(!pagerScrollEnabled)
)
[...]

private val HorizontalScrollConsumer =
    object : NestedScrollConnection {
        override fun onPreScroll(available: Offset, source: NestedScrollSource) =
            available.copy(y = 0f)
        override suspend fun onPreFling(available: Velocity) = available.copy(y = 0f)
    }

fun Modifier.disabledHorizontalPointerInputScroll(disabled: Boolean = true) =
    if (disabled) this.nestedScroll(HorizontalScrollConsumer) else this

But it give weird behaviour. If you have a better solution.

IacobIonut01 commented 1 year ago

https://github.com/IacobIonut01/Gallery/blob/v1/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt#L55

That's the way I do it

usuiat commented 1 year ago

@romainbsl I have confirmed that the cause of thie issue lies in the touch slop detection. I'm currently fixing it.

@IacobIonut01 Thank you for sharing the workaround.

usuiat commented 1 year ago

It is more difficult and time consuming than I expected. I may need to consider nested scroll. Sorry for the delay.

latsson commented 1 year ago

IacobIonut01/Gallery@v1/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt#L55

That's the way I do it

Sadly it's quite buggy for me on my Pixel 6 Pro. Sometimes the whole layout freeze so I can't do anything. And sometimes there are some UI glitches. I tested this in the Gallery apk on your Github

IacobIonut01 commented 1 year ago

IacobIonut01/Gallery@v1/app/src/main/kotlin/com/dot/gallery/feature_node/presentation/mediaview/components/media/ZoomablePagerImage.kt#L55

That's the way I do it

Sadly it's quite buggy for me on my Pixel 6 Pro. Sometimes the whole layout freeze so I can't do anything. And sometimes there are some UI glitches. I tested this in the Gallery apk on your Github

Unless you actually try to make the bug, it's pretty usable for day to day

usuiat commented 11 months ago

@romainbsl @latsson @IacobIonut01 I am very sorry for the delay, but I was able to resolve this Issue. However, as noted in the PR #125 , the API will be changed. If you have any opinions, comments are welcome.

You can try with v1.6.0-beta1

usuiat commented 9 months ago

I found better way to solve this issue and merged #143. Please try the beta release, v1.6.0-beta3

I will close this issue but feel free to ask any question.