-
-
Notifications
You must be signed in to change notification settings - Fork 579
fix(Fabric): back gesture activates Pressable
elements
#2131
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ed5384
Fix rtl issue & add reproductions
kkafar f944d20
ios fix
kkafar ab8e234
Cleanup iOS implementation
kkafar add5b73
Add modal screen to example
kkafar 1786094
Merge branch 'main' into @kkafar/fix-pressable-issue-2118
kkafar 8da1a1b
Fix typo
kkafar 30cfc12
Change extension method prefix from `rns` to `rnscreens`
kkafar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import { View, Text, Button, Pressable, StyleSheet, Alert } from 'react-native'; | ||
import { NavigationContainer, useNavigation } from '@react-navigation/native'; | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
||
const Stack = createNativeStackNavigator(); // <-- change to createStackNavigator to see a difference | ||
|
||
const ModalStack = createNativeStackNavigator(); | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator screenOptions={{ animation: 'slide_from_left' }}> | ||
<Stack.Screen name="Home" component={HomeScreen} /> | ||
<Stack.Screen name="DetailsStack" component={DetailsScreen} /> | ||
<Stack.Screen | ||
name="StackInModal" | ||
component={StackInModal} | ||
options={{ presentation: 'modal' }} | ||
/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
} | ||
|
||
function HomeScreen() { | ||
const navigation = useNavigation(); | ||
return ( | ||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<Text>Home Screen</Text> | ||
<Button | ||
title="Go to Details" | ||
onPress={() => navigation.navigate('DetailsStack')} | ||
/> | ||
<Button | ||
title="Go to StackInModal" | ||
onPress={() => navigation.navigate('StackInModal')} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
function DetailsScreen() { | ||
return ( | ||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
{new Array(10).fill(0).map((_, i) => ( | ||
<Pressable | ||
key={i.toString()} | ||
onPress={() => { | ||
Alert.alert('Pressed!'); | ||
}} | ||
style={({ pressed }) => [ | ||
{ | ||
backgroundColor: pressed ? 'rgb(210, 230, 255)' : 'white', | ||
}, | ||
styles.wrapperCustom, | ||
]}> | ||
{({ pressed }) => ( | ||
<Text style={styles.text}>{pressed ? 'Pressed!' : 'Press Me'}</Text> | ||
)} | ||
</Pressable> | ||
))} | ||
</View> | ||
); | ||
} | ||
|
||
function StackInModal() { | ||
return ( | ||
<ModalStack.Navigator> | ||
<ModalStack.Screen name="ModalHome" component={HomeScreen} /> | ||
<ModalStack.Screen name="ModalDetails" component={DetailsScreen} /> | ||
</ModalStack.Navigator> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
wrapperCustom: { | ||
width: '100%', | ||
height: 100, | ||
marginHorizontal: 30, | ||
borderRadius: 10, | ||
margin: 10, | ||
}, | ||
text: { | ||
fontSize: 20, | ||
color: 'black', | ||
}, | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import React from 'react'; | ||
import { View, Text, Button, Pressable, StyleSheet, Alert } from 'react-native'; | ||
import { NavigationContainer, useNavigation } from '@react-navigation/native'; | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
||
const Stack = createNativeStackNavigator(); // <-- change to createStackNavigator to see a difference | ||
|
||
const ModalStack = createNativeStackNavigator(); | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator screenOptions={{ animation: 'slide_from_left' }}> | ||
<Stack.Screen name="Home" component={HomeScreen} /> | ||
<Stack.Screen name="DetailsStack" component={DetailsScreen} /> | ||
<Stack.Screen | ||
name="StackInModal" | ||
component={StackInModal} | ||
options={{ presentation: 'modal' }} | ||
/> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
} | ||
|
||
function HomeScreen() { | ||
const navigation = useNavigation(); | ||
return ( | ||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
<Text>Home Screen</Text> | ||
<Button | ||
title="Go to Details" | ||
onPress={() => navigation.navigate('DetailsStack')} | ||
/> | ||
<Button | ||
title="Go to StackInModal" | ||
onPress={() => navigation.navigate('StackInModal')} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
function DetailsScreen() { | ||
return ( | ||
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> | ||
{new Array(10).fill(0).map((_, i) => ( | ||
<Pressable | ||
key={i.toString()} | ||
onPress={() => { | ||
Alert.alert('Pressed!'); | ||
}} | ||
style={({ pressed }) => [ | ||
{ | ||
backgroundColor: pressed ? 'rgb(210, 230, 255)' : 'white', | ||
}, | ||
styles.wrapperCustom, | ||
]}> | ||
{({ pressed }) => ( | ||
<Text style={styles.text}>{pressed ? 'Pressed!' : 'Press Me'}</Text> | ||
)} | ||
</Pressable> | ||
))} | ||
</View> | ||
); | ||
} | ||
|
||
function StackInModal() { | ||
return ( | ||
<ModalStack.Navigator> | ||
<ModalStack.Screen name="ModalHome" component={HomeScreen} /> | ||
<ModalStack.Screen name="ModalDetails" component={DetailsScreen} /> | ||
</ModalStack.Navigator> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
wrapperCustom: { | ||
width: '100%', | ||
height: 100, | ||
marginHorizontal: 30, | ||
borderRadius: 10, | ||
margin: 10, | ||
}, | ||
text: { | ||
fontSize: 20, | ||
color: 'black', | ||
}, | ||
}); |
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
|
||
#import <React/RCTSurfaceTouchHandler.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RCTSurfaceTouchHandler (RNSUtility) | ||
|
||
- (void)rns_cancelTouches; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // RCT_NEW_ARCH_ENABLED |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "RCTSurfaceTouchHandler+RNSUtility.h" | ||
|
||
@implementation RCTSurfaceTouchHandler (RNSUtility) | ||
|
||
- (void)rns_cancelTouches | ||
{ | ||
[self setEnabled:NO]; | ||
[self setEnabled:YES]; | ||
tboba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[self reset]; | ||
} | ||
|
||
@end | ||
#endif // RCT_NEW_ARCH_ENABLED |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef RCT_NEW_ARCH_ENABLED | ||
|
||
#import <React/RCTTouchHandler.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RCTTouchHandler (RNSUtility) | ||
|
||
- (void)rns_cancelTouches; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // !RCT_NEW_ARCH_ENABLED |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef RCT_NEW_ARCH_ENABLED | ||
#import "RCTTouchHandler+RNSUtility.h" | ||
|
||
@implementation RCTTouchHandler (RNSUtility) | ||
|
||
- (void)rns_cancelTouches | ||
{ | ||
[self setEnabled:NO]; | ||
[self setEnabled:YES]; | ||
tboba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[self reset]; | ||
} | ||
|
||
@end | ||
|
||
#endif // !RCT_NEW_ARCH_ENABLED |
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.
Uh oh!
There was an error while loading. Please reload this page.