-
-
Notifications
You must be signed in to change notification settings - Fork 955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Pinch Gesture Handler Behavior to transition to END state after one finger is taken off screen and one left #1214
Comments
Tested UIPinchGestureRecognizer and yeah, it stays active – that's the behavior of iOS here. |
As I workaround for now I do: When const [pinchEnabled, setPinchEnabledState] = useState(true);
useEffect(() => {
if (!pinchEnabled) {
setPinchEnabledState(true);
}
}, [pinchEnabled]);
const disablePinch = useCallback(() => {
setPinchEnabledState(false);
}, []); When you need to pass the In that case, we disable the pinch gesture handler as soon as the user releases one finger. That workaround did the trick for me. Hope it will help someone else. But yeah, would be cool to have this case handled in the native. |
@terrysahaidak I am happy you found a solution and noticed it is a native behavior. |
I will try to experiment around it, but will probably close the issue anyway, as Gesture Handler was always about exposing native gesture recognizers and not making them the same on both platforms. |
The only real problem I found is that you probably would want to run some animation as soon as user leaves that finger, and you would do it on "END", but you can't because the "END" won't ever be called here. The real-world case for this: after you zoom-out and I guess they do the same trick here. My workaround is far from perfect because I trigger rerender of that view twice in the row which isn't great. I think the ability to at least set |
@terrysahaidak I will mark this issue as a feature request to alter how the pinch gesture handler behaves and speak to the rest of the team whether we want to change that. |
Sounds good, thank you. |
I have worked with this quite a bit and have the opposite issue, Android failing on 1 finger and not starting the pan when failed. You need to keep track of the focal points and fingers to adjust back and forth to removing and adding fingers. Here is some code to help you out....
|
@terrysahaidak please consider the opposite as currently smooth 1->2->1->2 finger movement on iOS seems to function better than Android. I have just spent a good amount of time on this issue and can give a bit more insight after looking at the Android implementation. Currently Android gets a start event with 1 finger pressing, this start event is missing info for focal, etc. Then until a second finger is applied no active events are fired, once a second finger is applied active events come in again until less than 2 fingers remain, GestureHandler then fires the end event, but as a finger still remains I believe MotionEvents from ScaleGestureDetector still arrive and are discarded. This means that at best with a Pan and Pinch Handler on Android you can pan, then pinch, then pan, i.e. 1->2->1 fingers. You cannot return to 2 finger use. I have implemented this using reanimated 2 alongside the iOS version where the pinch handler takes over indefinitely after it starts and it seems to me as the pinch handler on iOS is almost a pass through to |
Looks like my issue (#1225) is related to this one 🤔 |
Too bad UIPinchGestureRecognizer works that way and I really wonder why. It would make more sense if pinch gesture ended when another finger was taken off screen. Workarounds just make code much more complicated. |
@iqqmuT You can take a look at my implementation of pinch to zoom here: https://github.com/GetStream/stream-chat-react-native/blob/92f891e42ec2c881d357ffc1a759fc8c26edf727/src/components/ImageGallery/ImageGallery.tsx . Overall for a smooth experience the iOS functionality makes more sense and is a 1:1 representation of the native handler as I noted previously. You can easily deal with the change in the number of touches detected, but with Android ending the gesture tracking you are not given a choice of how you want to deal with one finger being removed. Therefore the iOS implementation adds flexibility and utility. |
@nhannah Thanks for the hint! Unfortunately I can't use reanimated library, because it requires Hermes. I'm using another library that is incompatible with Hermes. |
For this scenario I'd suggest looking at |
Description
After testing PinchGestureHandler in react-native-gallery-toolkit I found that on the real device Pinch gesture is active even though we have only a single finger on the screen. This breaks my focal point logic which is working as expected on Android.
Screenshots
As soon as I release one finger - it jumps because now the focal point is not the point between fingers, but that single finger location.
But it should just transition to state "END" instead.
Steps To Reproduce
Expected behavior
The gesture should be in the state "end" as soon as the user releases one finger – just like on Android
Actual behavior
The gesture remains active even when the user released one finger
Snack or minimal code example
Run the example app
Package versions
The text was updated successfully, but these errors were encountered: