Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
49 changes: 49 additions & 0 deletions apps/src/tests/Test3345.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import { View, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

const Stack = createNativeStackNavigator();

function HomeScreen({ navigation }) {
return (
// In original repro SafeAreaView from `react-native` has been used here.
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Button
title="Open Modal"
onPress={() => navigation.navigate('Modal')}
/>
</View>
);
}

function ModalScreen() {
const onLayout = (event) => {
const { width } = event.nativeEvent.layout;
console.log('Modal width:', width);
};
return (
<View style={{ flex: 1, width: '100%', alignSelf: 'center', paddingHorizontal: 16, backgroundColor: 'green' }} onLayout={onLayout}>
<View style={{ flex: 1, backgroundColor: 'purple' }} />
</View>
);
}

function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen
name="Modal"
component={ModalScreen}
options={{
presentation: 'modal'
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
}

export default App;
1 change: 1 addition & 0 deletions apps/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,4 @@ export { default as TestBottomTabs } from './TestBottomTabs';
export { default as TestScreenStack } from './TestScreenStack';
export { default as TestSplitView } from './TestSplitView';
export { default as TestSafeAreaViewIOS } from './TestSafeAreaViewIOS';
export { default as Test3345 } from './Test3345';
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I'd move this a few lines above, closer to other numbered tests.

8 changes: 8 additions & 0 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,14 @@ - (void)updateLayoutMetrics:(const react::LayoutMetrics &)layoutMetrics
_newLayoutMetrics = layoutMetrics;
_oldLayoutMetrics = oldLayoutMetrics;
UIViewController *parentVC = self.reactViewController.parentViewController;

if (parentVC == nil && [self isKindOfClass:RNSModalScreen.class]) {
// If we're in modal presentation, we don't want to set the frame from RN,
// as the available space is most likely restriced & differs from what Yoga
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// as the available space is most likely restriced & differs from what Yoga
// as the available space is most likely restricted & differs from what Yoga

// resolves during firt layout. We want to rely on native layout here.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// resolves during firt layout. We want to rely on native layout here.
// resolves during first layout. We want to rely on native layout here.

return;
}

if (parentVC == nil || ![parentVC isKindOfClass:[RNSNavigationController class]]) {
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
}
Expand Down
Loading