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.

State.BEGAN is skipped for LongPressGestureHandler on iOS

See original GitHub issue

When using any of the gesture handlers, I normally expect to see the state flow go UNDETERMINED (0) -> BEGAN (2) -> ACTIVE (4) -> END (5). When using a LongPressGestureHandler in iOS though, I’m seeing it go UNDETERMINED (0) -> ACTIVE (4) -> END (5). In Android it behaves as expected.

I am using the iPhone 11 simulator running iOS 13.2.2 and the Android emulator running Pixel 2 API 28. I’m using RN 0.61.4 and RNGH 1.5.1 with an App function component that looks like this (TSX):

const App = () => {
	return (
		<>
			<StatusBar barStyle="dark-content" />
			<SafeAreaView style={{ flex: 1 }}>
				<LongPressGestureHandler
					onHandlerStateChange={(event: LongPressGestureHandlerStateChangeEvent) => {
						console.log(`LongPress state change ${event.nativeEvent.oldState} -> ${event.nativeEvent.state}`);
					}}
				>
					<View style={{ width: 200, height: 100, backgroundColor: 'blue' }}>
						<Text>LongPress</Text>
					</View>
				</LongPressGestureHandler>
				<PanGestureHandler
					onHandlerStateChange={(event: PanGestureHandlerStateChangeEvent) => {
						console.log(`Pan state change ${event.nativeEvent.oldState} -> ${event.nativeEvent.state}`);
					}}
				>
					<View style={{ width: 200, height: 100, backgroundColor: 'green' }}>
						<Text>Pan</Text>
					</View>
				</PanGestureHandler>
			</SafeAreaView>
		</>
	);
}

When testing on iOS, the Pan behaves as expected but not the LongPress:

 LOG  LongPress state change 0 -> 4
 LOG  LongPress state change 4 -> 5
 LOG  LongPress state change 0 -> 4
 LOG  LongPress state change 4 -> 5
 LOG  Pan state change 0 -> 2
 LOG  Pan state change 2 -> 4
 LOG  Pan state change 4 -> 5

When testing on Android, both behave as expected:

 LOG  LongPress state change 0 -> 2
 LOG  LongPress state change 2 -> 4
 LOG  LongPress state change 4 -> 5
 LOG  Pan state change 0 -> 2
 LOG  Pan state change 2 -> 4
 LOG  Pan state change 4 -> 5

Additionally, because the LongPress never “begins” on iOS, we never see failed presses either. Here’s an example of a too-short press on Android going from UNDETERMINED (0) -> BEGAN (2) -> FAILED (1):

 LOG  LongPress state change 0 -> 2
 LOG  LongPress state change 2 -> 1

This relates tangentially to some existing issues, although most of those seem to be about the timing of when the state changes occur on the different platforms. In the case above, a specific state is being omitted entirely.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

LongPressGestureHandler | React Native Gesture Handler
A discrete gesture handler that activates when the corresponding view is pressed for a sufficiently long time. This handler's state will turn into...
Read more >
Handling long-press gestures | Apple Developer Documentation
Long-press gestures are continuous gestures, meaning that your action method may be called multiple times as the state changes. After a person's fingers...
Read more >
Why is the UITapGestureRecognizer never getting called with ...
Let me start by saying that UITapGestureRecognizer docs clearly tell to expect a callback for all states. For gesture recognition, the ...
Read more >
react-native-gesture-handler - npm
State.BEGAN - handler has initiated recognition but have not enough data to tell if it has recognized or not; State.CANCELLED - handler has...
Read more >
How to use the react-native-gesture-handler.State.BEGAN ...
To help you get started, we've selected a few react-native-gesture-handler.State.BEGAN examples, based on popular ways it is used in public projects.
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