usuiat / Zoomable

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

Cancel gesture handling when PointerEvent is consumed by the parent. #180

Closed usuiat closed 7 months ago

usuiat commented 7 months ago

Related Issue

Overview

In some cases, the Zoomable Modifier would continue gesture processing even after PointerEvents were consumed by the parent component. As a result, scrolling of the HorizontalPager and onTap of the Zoomable were occurring simultaneously.

In this PR, Zoomable Modifier cancels the gesture processing when the parent component consumes PointerEvents.

Kartex7260 commented 2 months ago

Hello, this is not a very clear change. Normally, in Compose, the child element overrides the parent input events by using input events. This change does not correspond to this concept. The change is nice, but I would consider using NestedScrollConnection.

We used your library and encountered a problem when updating it. When tapping, we hide and show the UI, but due to this change, DoubleTap stopped working for us, since the parent element uses clickable.

usuiat commented 2 months ago

@Kartex7260 Hi, Thank you for your comment.

I experimented with the following code.

Box(modifier = Modifier.clickable { println("Tap parent") }) {
    Image(
        ...
        modifier = Modifier
            .zoomable(
                ...
                onDoubleTap = { println("DoubleTap Zoomable") }
            )
    )
}

When I double-tap the Image, Zoomable v1.6.0 prints “DoubleTap Zoomable”. But Zoomable v1.6.1 does not print it and "Tap parent" is printed twice. Is this what you are trying to point out?

Kartex7260 commented 2 months ago

@usuiat Thank you for your reply. That's right, in version 1.6.0, there is a tap on both the parent view and the zoomable view. However, in version 1.6.1, the zoomable tap no longer works, as the parent clickable element disables it.

I believe it would be more intuitive if, when tapping on the zoomable area, the parent view was not tapped. Additionally, conflicts between the zoomable gesture and Pager or Scrollable components can be resolved using NestedScrollView.