question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pinch focalX/focalY in state change callback don't match Animated values

See original GitHub issue

I am working with PinchGestureHandler and using focalX/focalY variables to calculate translateX/translateY values. Everything works fine during the gesture.

When the gesture finishes, I have set up curX and curY variables, to which I offload the current values of translateX/translateY (derived from the focal coordinates). However, I have noticed that the focalX and focalY results reported to PinchGestureHandler’s onHandlerStateChange do not match the values reported to the Animated.Values passed in through onGestureEvent.

On iOS this issue does not occur - the values match up. On Android however, because the values do not match up I end up with a jerky effect when the gesture resolves.

I was able to compare the values by calling __getValue() on the Animated.Values in onHandlerStateChange. On iOS all the values line up, but on Android only the scale values match - the focalX and focalY values do not.

Is this a known issue? Any ideas as to what might be causing it?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
wcandilloncommented, Mar 12, 2020

@Ashoat Thanks for your great work regarding the PinchGestureHandler. In redash, I plan to add the following function that makes the pinch behavior consistent across Android and iOS and closer to what we would expect:

const withFocalOffset = (
  value: Animated.Node<number>,
  state: Animated.Node<State>,
  numberOfPointers: Animated.Node<number>,
  offset: Animated.Value<number> = new Value(0)
) =>
  cond(
    and(eq(state, State.ACTIVE), eq(numberOfPointers, 2)),
    [set(offset, value), offset],
    offset
  );
2reactions
samridhguptacommented, Jun 1, 2021

https://github.com/wcandillon/can-it-be-done-in-react-native/blob/master/the-10-min/src/PinchGesture/PinchGesture.tsx

@wcandillon Seems like this implementation is stale now as the redash library is rewritten in a different way.

Can you update the implementation with Redash v2

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native: Animation callback does not access latest state ...
Alright, I think that the problem is you are not getting and updated value for the state. Remember that setting the state is...
Read more >
Animated.Value - React Native
callback is invoked with the final value after stopping the animation, which is useful for updating state to match the animation position with ......
Read more >
Using Animation Callbacks When Animation Transitions Are ...
If the two values match, we know the transition completed "successfully", which means we can revert the state back to "none". However, if...
Read more >
Making Sense of react-spring - CSS-Tricks
I'll have a working demo at the end of this section, so don't worry if ... We already know how to animate changing...
Read more >
React Native's Animated.loop: Invoking A Callback Whenever ...
delay and then perform a transition of the this.state.width property to value 400, over a course of 2 seconds. Animated.loop also takes a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found