Skip to content

Commit df7cd90

Browse files
authored
Don't block onPress if onLongPress is not defined (#3549)
## Description Currently if `onLongPress` is not passed into `Pressable`, `onPress` will not be called anyway, opposed to react-native Fixes #3514 ## Test plan <details> <summary>Tested on the following example</summary> ```jsx import React from 'react'; import { StyleSheet, View, Pressable as RNPressable } from 'react-native'; import { Pressable } from 'react-native-gesture-handler'; export default function EmptyExample() { return ( <View style={styles.container}> <RNPressable style={styles.button} onPress={() => console.log('onPress')} onPressOut={() => console.log('onPressOut')} /> <Pressable style={styles.button} onPress={() => console.log('onPress')} onPressOut={() => console.log('onPressOut')} /> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', gap: 10, }, button: { backgroundColor: 'blue', width: 200, height: 50, justifyContent: 'center', alignItems: 'center', }, }); ``` </details>
1 parent fc92105 commit df7cd90

File tree

1 file changed

+2
-2
lines changed
  • packages/react-native-gesture-handler/src/components/Pressable

1 file changed

+2
-2
lines changed

packages/react-native-gesture-handler/src/components/Pressable/Pressable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ const Pressable = forwardRef(
231231
return;
232232
}
233233

234-
if (hasPassedBoundsChecks.current) {
235-
onLongPress?.(gestureTouchToPressableEvent(event));
234+
if (hasPassedBoundsChecks.current && onLongPress) {
235+
onLongPress(gestureTouchToPressableEvent(event));
236236
isPressCallbackEnabled.current = false;
237237
}
238238

0 commit comments

Comments
 (0)