-
-
Notifications
You must be signed in to change notification settings - Fork 992
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
Fix: onPressIn and onPressOut are triggered at the same time on Android #3286
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
latekvo
approved these changes
Dec 13, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great, this PR also fixes functional styles on fabric
on android
.
While testing i noticed the touch propagation mechanism seems to be completely broken for onPress
events on fabric
, but it does work for the functional styles, related to #3282
collapsed test code
import * as React from 'react';
import {
View,
Text,
Pressable as RNPressable,
SafeAreaView,
StyleSheet,
ScrollView,
PressableStateCallbackType,
} from 'react-native';
import {
GestureHandlerRootView,
Pressable as RNGHPressable,
TouchableHighlight,
TouchableOpacity,
} from 'react-native-gesture-handler';
const innerStyle = ({ pressed }: PressableStateCallbackType) => [
styles.innerPressable,
pressed ? { backgroundColor: '#c00' } : { backgroundColor: 'orange' },
];
const outerStyle = ({ pressed }: PressableStateCallbackType) => [
styles.pressable,
pressed ? { backgroundColor: '#00c' } : { backgroundColor: 'pink' },
];
export default function HomeScreen() {
return (
<GestureHandlerRootView>
<SafeAreaView style={{ flex: 1 }}>
<ScrollView contentContainerStyle={styles.rowContainer}>
<RNGHPressable
style={outerStyle}
onPressIn={() => console.log(JSON.stringify('RNGH: onPressIn'))}
onPressOut={() => console.log(JSON.stringify('RNGH: onPressOut'))}
onPress={() => console.log(JSON.stringify('RNGH: onPress'))}>
<Text style={styles.pressableText}>RNGH Pressable</Text>
</RNGHPressable>
<RNPressable
style={outerStyle}
onPressIn={() => console.log(JSON.stringify('RN: onPressIn'))}
onPressOut={() => console.log(JSON.stringify('RN: onPressOut'))}
onPress={() => console.log(JSON.stringify('RN: onPress'))}>
<Text style={styles.pressableText}>RN Pressable</Text>
</RNPressable>
<RNGHPressable
style={outerStyle}
onPress={() =>
console.log('TouchableOpacity in Pressable: Pressable')
}>
<TouchableOpacity
style={styles.innerPressable}
onPress={() =>
console.log('TouchableOpacity in Pressable: TouchableOpacity')
}>
<Text style={styles.pressableText}>
TouchableOpacity in Pressable
</Text>
</TouchableOpacity>
</RNGHPressable>
<TouchableOpacity
style={styles.pressable}
onPress={() =>
console.log('Pressable in TouchableOpacity: Pressable')
}>
<RNGHPressable
style={innerStyle}
onPress={() =>
console.log('Pressable in TouchableOpacity: TouchableOpacity')
}>
<Text style={styles.pressableText}>
Pressable in TouchableOpacity
</Text>
</RNGHPressable>
</TouchableOpacity>
<RNGHPressable
style={outerStyle}
onPress={() =>
console.log('TouchableHighlight in Pressable: Pressable')
}>
<TouchableHighlight
style={styles.innerPressable}
onPress={() =>
console.log(
'TouchableHighlight in Pressable: TouchableHighlight'
)
}>
<Text style={styles.pressableText}>
TouchableHighlight in Pressable
</Text>
</TouchableHighlight>
</RNGHPressable>
<TouchableHighlight
style={styles.pressable}
onPress={() =>
console.log('Pressable in TouchableHighlight: Pressable')
}>
<RNGHPressable
style={innerStyle}
onPress={() =>
console.log(
'Pressable in TouchableHighlight: TouchableHighlight'
)
}>
<Text style={styles.pressableText}>
Pressable in TouchableHighlight
</Text>
</RNGHPressable>
</TouchableHighlight>
<RNGHPressable
style={outerStyle}
onPress={() =>
console.log('Pressable in TouchableHighlight: Parent')
}>
<RNGHPressable
style={innerStyle}
onPress={() => console.log('Pressable in Pressable: Child')}>
<Text style={styles.pressableText}>Pressable in Pressable</Text>
</RNGHPressable>
</RNGHPressable>
</ScrollView>
<View style={styles.rowContainer}>
<RNGHPressable
style={outerStyle}
onPressIn={() => console.log(JSON.stringify('RNGH: onPressIn'))}
onPressOut={() => console.log(JSON.stringify('RNGH: onPressOut'))}
onPress={() => console.log(JSON.stringify('RNGH: onPress'))}>
<Text style={styles.pressableText}>RNGH Pressable</Text>
</RNGHPressable>
<RNPressable
style={outerStyle}
onPressIn={() => console.log(JSON.stringify('RN: onPressIn'))}
onPressOut={() => console.log(JSON.stringify('RN: onPressOut'))}
onPress={() => console.log(JSON.stringify('RN: onPress'))}>
<Text style={styles.pressableText}>RN Pressable</Text>
</RNPressable>
<RNGHPressable
style={outerStyle}
onPress={() =>
console.log('TouchableOpacity in Pressable: Pressable')
}>
<TouchableOpacity
style={styles.innerPressable}
onPress={() =>
console.log('TouchableOpacity in Pressable: TouchableOpacity')
}>
<Text style={styles.pressableText}>
TouchableOpacity in Pressable
</Text>
</TouchableOpacity>
</RNGHPressable>
<TouchableOpacity
style={styles.pressable}
onPress={() =>
console.log('Pressable in TouchableOpacity: Pressable')
}>
<RNGHPressable
style={innerStyle}
onPress={() =>
console.log('Pressable in TouchableOpacity: TouchableOpacity')
}>
<Text style={styles.pressableText}>
Pressable in TouchableOpacity
</Text>
</RNGHPressable>
</TouchableOpacity>
<RNGHPressable
style={outerStyle}
onPress={() =>
console.log('TouchableHighlight in Pressable: Pressable')
}>
<TouchableHighlight
style={styles.innerPressable}
onPress={() =>
console.log(
'TouchableHighlight in Pressable: TouchableHighlight'
)
}>
<Text style={styles.pressableText}>
TouchableHighlight in Pressable
</Text>
</TouchableHighlight>
</RNGHPressable>
<TouchableHighlight
style={styles.pressable}
onPress={() =>
console.log('Pressable in TouchableHighlight: Pressable')
}>
<RNGHPressable
style={innerStyle}
onPress={() =>
console.log(
'Pressable in TouchableHighlight: TouchableHighlight'
)
}>
<Text style={styles.pressableText}>
Pressable in TouchableHighlight
</Text>
</RNGHPressable>
</TouchableHighlight>
<RNGHPressable
style={outerStyle}
onPress={() =>
console.log('Pressable in TouchableHighlight: Parent')
}>
<RNGHPressable
style={innerStyle}
onPress={() => console.log('Pressable in Pressable: Child')}>
<Text style={styles.pressableText}>Pressable in Pressable</Text>
</RNGHPressable>
</RNGHPressable>
</View>
</SafeAreaView>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
gap: 10,
alignItems: 'center',
justifyContent: 'center',
},
rowContainer: {
flex: 1,
flexDirection: 'column',
gap: 5,
alignItems: 'center',
justifyContent: 'center',
},
pressable: {
backgroundColor: 'pink',
paddingHorizontal: 15,
height: 45,
width: 380,
alignItems: 'center',
justifyContent: 'center',
},
innerPressable: {
backgroundColor: 'orange',
paddingVertical: 10,
paddingHorizontal: 15,
height: 45,
width: 300,
alignItems: 'center',
justifyContent: 'center',
},
pressableText: {
color: '#000',
fontSize: 16,
fontWeight: 'bold',
},
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3280
The
pressInHandler
method returns early if theisTouchPropagationAllowed
isfalse
. On AndroidpressInHandler
is called initially before theisTouchPropagationAllowed
is set totrue
in buttonGesture. Changing the order of gestures seems to fix it.Test plan
Code