Skip to content

Commit 5359e4e

Browse files
alduzykkafar
authored andcommitted
fix(iOS): FullWindowOverlay layout height (#2430)
## Description This PR intents to fix `FullWindowOverlay`s height issue. The component is given wrong frame size during layout because of it's placement in the react tree. Although in the iOS view hierarchy it is displayed independently its height is still reduced by the height of the header. Correct frame can be achieved by utilising `useWindowDimensions` hook and forcing correct width and height on the JS side. Fixes #1247 ## Changes - modified `Test1096` repro ## Screenshots / GIFs ### Before ![Simulator Screenshot - iPhone 16 Pro - 2024-10-22 at 10 08 00](https://github.com/user-attachments/assets/2b7164b4-8fc8-4685-b3e5-a7d1f01f08af) ### After ![Simulator Screenshot - iPhone 16 Pro - 2024-10-22 at 10 08 09](https://github.com/user-attachments/assets/8362dcc9-e5fd-4ce1-a2ea-a47ec6e7b214) ## Test code and steps to reproduce - use `Test1096` repro ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes (cherry picked from commit cf31492)
1 parent dc8c058 commit 5359e4e

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

apps/src/tests/Test1096.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ function Home({
3434
</View>
3535
</Modal>
3636
<FullWindowOverlay>
37-
<View
38-
style={{ flex: 1, justifyContent: 'center' }}
39-
pointerEvents="box-none">
37+
<View style={styles.overlay} pointerEvents="box-none">
4038
<View style={styles.box} />
4139
<Button title="click me" onPress={() => console.warn('clicked')} />
4240
</View>
@@ -80,7 +78,12 @@ const styles = StyleSheet.create({
8078
alignItems: 'flex-start',
8179
justifyContent: 'center',
8280
},
83-
81+
overlay: {
82+
flex: 1,
83+
justifyContent: 'center',
84+
alignItems: 'center',
85+
backgroundColor: `rgba(0,0,0,0.5)`,
86+
},
8487
box: {
8588
width: 40,
8689
height: 40,

src/components/FullWindowOverlay.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React, { PropsWithChildren, ReactNode } from 'react';
2-
import { Platform, StyleProp, View, ViewStyle } from 'react-native';
2+
import {
3+
Platform,
4+
StyleProp,
5+
StyleSheet,
6+
View,
7+
ViewStyle,
8+
useWindowDimensions,
9+
} from 'react-native';
310

411
// Native components
512
import FullWindowOverlayNativeComponent from '../fabric/FullWindowOverlayNativeComponent';
@@ -10,13 +17,14 @@ const NativeFullWindowOverlay: React.ComponentType<
1017
> = FullWindowOverlayNativeComponent as any;
1118

1219
function FullWindowOverlay(props: { children: ReactNode }) {
20+
const { width, height } = useWindowDimensions();
1321
if (Platform.OS !== 'ios') {
1422
console.warn('Using FullWindowOverlay is only valid on iOS devices.');
1523
return <View {...props} />;
1624
}
1725
return (
1826
<NativeFullWindowOverlay
19-
style={{ position: 'absolute', width: '100%', height: '100%' }}>
27+
style={[StyleSheet.absoluteFill, { width, height }]}>
2028
{props.children}
2129
</NativeFullWindowOverlay>
2230
);

0 commit comments

Comments
 (0)