Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/src/shared/PressableWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const PressableWithFeedback = React.forwardRef((props: PressableProps, ref: Forw
return (
<View ref={ref} style={[contentsStyle]}>
<Pressable
{...props}
onPressIn={onPressInCallback}
onPress={onPressCallback}
onPressOut={onPressOutCallback}
Expand Down
153 changes: 153 additions & 0 deletions apps/src/tests/Test3446.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import React, { useState, useEffect } from 'react';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from '@react-navigation/native-stack';
import PressableWithFeedback from '../shared/PressableWithFeedback';
import { ScrollView, View } from 'react-native';
import Colors from '../shared/styling/Colors';
import { SettingsPicker, SettingsSwitch } from '../shared';

type RouteParamList = {
Home: undefined;
};

type NavigationProp<ParamList extends ParamListBase> = {
navigation: NativeStackNavigationProp<ParamList>;
};

type StackNavigationProp = NavigationProp<RouteParamList>;

const Stack = createNativeStackNavigator();

interface Configuration {
size: 'sm' | 'md' | 'lg';
hidesSharedBackground: boolean;
hitSlop: '0' | '10' | '30';
pressRetentionOffset: '0' | '20' | '50';
}

function getPressableFromConfig(config: Configuration) {
return (
<PressableWithFeedback
key={
config.size +
'_' +
config.hidesSharedBackground +
'_' +
config.hitSlop +
'_' +
config.pressRetentionOffset
}
hitSlop={Number(config.hitSlop)}
pressRetentionOffset={Number(config.pressRetentionOffset)}>
<View
style={{
width: config.size === 'sm' ? 10 : config.size === 'md' ? 36 : 80,
height: config.size === 'sm' ? 10 : config.size === 'md' ? 36 : 40,
}}
/>
</PressableWithFeedback>
);
}

function Screen({ navigation }: StackNavigationProp) {
const [config, setConfig] = useState<Configuration>({
size: 'sm',
hidesSharedBackground: true,
hitSlop: '0',
pressRetentionOffset: '0',
});

useEffect(() => {
navigation.setOptions({
unstable_headerLeftItems: () => [
{
type: 'custom',
element: getPressableFromConfig(config),
hidesSharedBackground: config.hidesSharedBackground,
},
],
unstable_headerRightItems: () => [
{
type: 'custom',
element: getPressableFromConfig(config),
hidesSharedBackground: config.hidesSharedBackground,
},
],
});
}, [config, navigation]);

return (
<ScrollView
contentInsetAdjustmentBehavior="automatic"
contentContainerStyle={{ padding: 16, gap: 5 }}>
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: 200,
backgroundColor: Colors.BlueLight60,
}}>
{getPressableFromConfig(config)}
</View>
<SettingsSwitch
label="hidesSharedBackground"
value={config.hidesSharedBackground}
onValueChange={value =>
setConfig({ ...config, hidesSharedBackground: value })
}
/>
<SettingsPicker<Configuration['size']>
label="size"
value={config.size}
onValueChange={value =>
setConfig({
...config,
size: value,
})
}
items={['sm', 'md', 'lg']}
/>
<SettingsPicker<Configuration['hitSlop']>
label="hitSlop"
value={config.hitSlop}
onValueChange={value =>
setConfig({
...config,
hitSlop: value,
})
}
items={['0', '10', '30']}
/>
<SettingsPicker<Configuration['pressRetentionOffset']>
label="pressRetentionOffset"
value={config.pressRetentionOffset}
onValueChange={value =>
setConfig({
...config,
pressRetentionOffset: value,
})
}
items={['0', '20', '50']}
/>
</ScrollView>
);
}

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Screen}
options={{ title: 'Test Pressables' }}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
1 change: 1 addition & 0 deletions apps/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export { default as Test3369 } from './Test3369';
export { default as Test3379 } from './Test3379';
export { default as Test3422 } from './Test3422';
export { default as Test3425 } from './Test3425';
export { default as Test3446 } from './Test3446';
export { default as TestScreenAnimation } from './TestScreenAnimation';
// The following test was meant to demo the "go back" gesture using Reanimated
// but the associated PR in react-navigation is currently put on hold
Expand Down
3 changes: 2 additions & 1 deletion ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,8 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
RNSScreenView *topMostScreen = (RNSScreenView *)_reactSubviews.lastObject;
UIView *headerConfig = topMostScreen.findHeaderConfig;
if ([headerConfig isKindOfClass:[RNSScreenStackHeaderConfig class]]) {
UIView *headerHitTestResult = [headerConfig hitTest:point withEvent:event];
CGPoint convertedPoint = [self convertPoint:point toView:headerConfig];
UIView *headerHitTestResult = [headerConfig hitTest:convertedPoint withEvent:event];
if (headerHitTestResult != nil) {
return headerHitTestResult;
}
Expand Down
12 changes: 5 additions & 7 deletions ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,17 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
continue;
}

// we wrap the headerLeft/Right component in a UIBarButtonItem
// so we need to hit test subviews from left to right, because of the view flattening
UIView *headerComponent = nil;
for (UIView *headerComponentSubview in subview.subviews) {
// We wrap the headerLeft/Right component in a UIBarButtonItem
// so we need to hit test subviews, because of the view flattening
// (we match RCTViewComponentView implementation).
for (UIView *headerComponentSubview in [subview.subviews reverseObjectEnumerator]) {
CGPoint convertedPoint = [self convertPoint:point toView:headerComponentSubview];
UIView *hitTestResult = [headerComponentSubview hitTest:convertedPoint withEvent:event];

if (hitTestResult != nil) {
headerComponent = hitTestResult;
return hitTestResult;
}
}
Comment on lines +172 to 182
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above the for loop explicitly states, that the default behaviour of reverse iterating over the children) has been deliberately changed to left to right.

Can we do some research & see what problem exactly this approach solved & whether we do not introduce a regression with swapping this back?


return headerComponent;
}
}
return nil;
Expand Down
Loading