-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iOS): not working hitslop for headerRight/Left views (#1995)
## Description Since #1825 header config is no longer first child of a screen & `hitTest:withEvent:` method assumed this invariant to be true. Fixed that by using appropriate screen method instead of blind assumption. Fixes #1981 ## Changes * Fixed `hitTest:withEvent:` method by using `findHeaderConfig` `RNSScreenView`'s method * Improved `findHeaderConfig` method itself ## Test code and steps to reproduce `Test1981` ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes
- Loading branch information
Showing
6 changed files
with
217 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React from 'react'; | ||
import { NavigationContainer, NavigationContext, ParamListBase } from '@react-navigation/native'; | ||
import { createNativeStackNavigator, NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
import { View, StyleSheet, Button, Pressable, Text } from 'react-native'; | ||
|
||
type NavProp = { | ||
navigation: NativeStackNavigationProp<ParamListBase>; | ||
}; | ||
|
||
const Stack = createNativeStackNavigator(); | ||
|
||
function FirstScreen({ navigation }: NavProp) { | ||
const navigateToSecond = () => { | ||
navigation.navigate('Second'); | ||
}; | ||
return ( | ||
<View style={[styles.redbox, styles.centeredView]}> | ||
<Button title="Navigate to Second" onPress={navigateToSecond} /> | ||
<PressableWithHitSlop /> | ||
</View> | ||
); | ||
} | ||
|
||
function SecondScreen({ navigation }: NavProp) { | ||
const navigateToFirst = () => { | ||
navigation.navigate('First'); | ||
}; | ||
|
||
return ( | ||
<View style={[styles.greenbox, styles.centeredView]}> | ||
<Button title="Navigate to First" onPress={navigateToFirst} /> | ||
</View> | ||
); | ||
} | ||
|
||
function HeaderLeft() { | ||
const onPressCallback = () => { | ||
console.log('HeaderLeft onPressCallback invoked'); | ||
}; | ||
|
||
return ( | ||
<Pressable style={[styles.bluebox]} hitSlop={12} onPress={onPressCallback}> | ||
<Text style={{ color: 'white' }}>Press me</Text> | ||
</Pressable> | ||
); | ||
} | ||
|
||
function PressableWithHitSlop() { | ||
const onPressCallback = () => { | ||
console.log('PressableWithHitSlop onPressCallback invoked'); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
padding: 12, | ||
margin: -12, | ||
backgroundColor: 'yellow', | ||
}}> | ||
<Pressable | ||
style={[styles.greenbox]} | ||
hitSlop={12} | ||
onPress={onPressCallback}> | ||
<Text style={{ color: 'white' }}>Press me</Text> | ||
</Pressable> | ||
</View> | ||
); | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="First" | ||
component={FirstScreen} | ||
options={{ | ||
headerLeft: () => HeaderLeft(), | ||
headerRight: () => PressableWithHitSlop(), | ||
}} | ||
/> | ||
<Stack.Screen name="Second" component={SecondScreen} /> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
redbox: { | ||
backgroundColor: 'red', | ||
}, | ||
greenbox: { | ||
backgroundColor: 'green', | ||
}, | ||
bluebox: { | ||
backgroundColor: 'blue', | ||
}, | ||
centeredView: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React from 'react'; | ||
import { NavigationContainer, NavigationContext, ParamListBase } from '@react-navigation/native'; | ||
import { createNativeStackNavigator, NativeStackNavigationProp } from '@react-navigation/native-stack'; | ||
import { View, StyleSheet, Button, Pressable, Text } from 'react-native'; | ||
|
||
type NavProp = { | ||
navigation: NativeStackNavigationProp<ParamListBase>; | ||
}; | ||
|
||
const Stack = createNativeStackNavigator(); | ||
|
||
function FirstScreen({ navigation }: NavProp) { | ||
const navigateToSecond = () => { | ||
navigation.navigate('Second'); | ||
}; | ||
return ( | ||
<View style={[styles.redbox, styles.centeredView]}> | ||
<Button title="Navigate to Second" onPress={navigateToSecond} /> | ||
<PressableWithHitSlop /> | ||
</View> | ||
); | ||
} | ||
|
||
function SecondScreen({ navigation }: NavProp) { | ||
const navigateToFirst = () => { | ||
navigation.navigate('First'); | ||
}; | ||
|
||
return ( | ||
<View style={[styles.greenbox, styles.centeredView]}> | ||
<Button title="Navigate to First" onPress={navigateToFirst} /> | ||
</View> | ||
); | ||
} | ||
|
||
function HeaderLeft() { | ||
const onPressCallback = () => { | ||
console.log('HeaderLeft onPressCallback invoked'); | ||
}; | ||
|
||
return ( | ||
<Pressable style={[styles.bluebox]} hitSlop={12} onPress={onPressCallback}> | ||
<Text style={{ color: 'white' }}>Press me</Text> | ||
</Pressable> | ||
); | ||
} | ||
|
||
function PressableWithHitSlop() { | ||
const onPressCallback = () => { | ||
console.log('PressableWithHitSlop onPressCallback invoked'); | ||
}; | ||
|
||
return ( | ||
<View | ||
style={{ | ||
padding: 12, | ||
margin: -12, | ||
backgroundColor: 'yellow', | ||
}}> | ||
<Pressable | ||
style={[styles.greenbox]} | ||
hitSlop={12} | ||
onPress={onPressCallback}> | ||
<Text style={{ color: 'white' }}>Press me</Text> | ||
</Pressable> | ||
</View> | ||
); | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Stack.Navigator> | ||
<Stack.Screen | ||
name="First" | ||
component={FirstScreen} | ||
options={{ | ||
headerLeft: () => HeaderLeft(), | ||
headerRight: () => PressableWithHitSlop(), | ||
}} | ||
/> | ||
<Stack.Screen name="Second" component={SecondScreen} /> | ||
</Stack.Navigator> | ||
</NavigationContainer> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
redbox: { | ||
backgroundColor: 'red', | ||
}, | ||
greenbox: { | ||
backgroundColor: 'green', | ||
}, | ||
bluebox: { | ||
backgroundColor: 'blue', | ||
}, | ||
centeredView: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
}); |
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
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