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.

BEGAN state isn't handled if taps are very quick

See original GitHub issue

Description

Assuming even a simple JS-side reanimated-Code block that depends on both BEGAN and END states (associated with down and up press events from a tap), the BEGAN state will not be handled if the tap gesture (touch and release) is done very quickly.

In particular, we find this to be an issue with automated tests written with Detox.

For example, consider this simple usage of reanimated:

const buttonOpacity = new Value(1.0);
const gestureState = new Value(-1);

// ...
<Reanimated.Code>
  {() =>
    block([
      cond(eq(gestureState, State.BEGAN), set(buttonOpacity, 0.25)),
      cond(eq(gestureState, State.END), set(buttonOpacity, 1.0))
    ])
  }
</Reanimated.Code>

If the tap is performed really fast, the BEGAN will not be fired, and with that the opacity flicker will not take place.

Root cause

I’ve done some research as to what causes this and this is what I dug up.

The root of the problem - on Android, at least, is that the history of states doesn’t get recorded in ValueNodes. Rather, ValueNodes only keep the most recent value set to it. Combined with the fact that these updates’ handling is only triggered via the choreographer’s callback - which is only dispatched async’ly in ~16ms intervals, if the gap between events is small enough (i.e. both take place fast enough to precede the next callback exec) then you end up with the BEGAN getting lost, and only the ACTIVE and END being handled.

Additional Artefacts, Reproduction

In essence, this can be reproduced by running Wix’ public RN UI-Lib project’s demo app, as explained by @ethanshar’s comment below.

Technical Info

  • React native version: 0.61.5
  • Reanimated version: 1.7.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:18
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ethansharcommented, Feb 5, 2020

Please take a look at the attached GIF demonstrating how the button doesn’t react to “soft” taps while “hard” taps work.

To reproduce this You can checkout this code https://github.com/wix/react-native-ui-lib/blob/demo/TouchableTapIssue/demo/src/screens/PlaygroundScreen.js

And the source code for this component can be found here https://github.com/wix/react-native-ui-lib/blob/demo/TouchableTapIssue/src/incubator/TouchableOpacity.js#L58 TouchableOpacityIssue

1reaction
d4vidicommented, Mar 19, 2020

@kmagiera So given the situation, we’re now considering submitting a fix through a PR. I tried a few naive solutions such as maintaining a values queue inside ValueNode but these attempts have been futile so far (animations and state changes go crazy 😄).

Do you have any suggestions as to how we should approach this, given the broader outlook on things?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling tap gestures | Apple Developer Documentation
Tap gestures are discrete, so your action method is called only when the tap gesture is recognized successfully. You can configure a tap...
Read more >
Handle taps - Flutter documentation
Use the GestureDetector widget to respond to fundamental actions, such as tapping and dragging. Your browser can't play this video.
Read more >
SwiftUI: how to handle BOTH tap & long press of button?
We sequence the gestures as follows: Use 'Exclusively' to combine the "Long Press" (i.e. 2 & 3 above combined) and Tap (first gesture...
Read more >
Why has my bathroom cold water tap (but no others) stopped ...
I could be that the connection between the handle and the actual valve ... Use a cloth/rag if your hot water is too...
Read more >
The activity lifecycle | Android Developers
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial...
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