Skip to content

Commit 7e84e0b

Browse files
authored
Update common example not to disable E2E (#3531)
## Description Removes usage of `StatusBar` component, which disables edge-to-edge mode and replaces RN's `SafeAreaView` with `useSafeAreaInsets` from `react-native-safe-area-context`, which also works on Android. ## Test plan iOS: |Before|After| |-|-| |<img width="544" alt="Screenshot 2025-05-26 at 09 18 52" src="https://github.com/user-attachments/assets/7c4eb741-e5c5-4176-9465-431d399f480a" />|<img width="544" alt="Screenshot 2025-05-26 at 09 19 18" src="https://github.com/user-attachments/assets/5ad4e627-abf2-42fc-851b-cd6710b461a8" />| Android: |Before|After| |-|-| |<img width="436" alt="Screenshot 2025-05-26 at 09 18 57" src="https://github.com/user-attachments/assets/57a316d3-5344-40e9-b161-2da2a7a55f99" />|<img width="436" alt="Screenshot 2025-05-26 at 09 36 45" src="https://github.com/user-attachments/assets/55aab0ac-08f8-48e1-aaad-3bf7a6878b75" />|
1 parent 3a93c6e commit 7e84e0b

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

apps/common-app/App.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import React, { useEffect } from 'react';
2-
import {
3-
Text,
4-
View,
5-
StyleSheet,
6-
Platform,
7-
Dimensions,
8-
StatusBar,
9-
SafeAreaView,
10-
} from 'react-native';
2+
import { Text, View, StyleSheet, Platform, Dimensions } from 'react-native';
113
import {
124
createStackNavigator,
135
StackNavigationProp,
@@ -19,6 +11,7 @@ import {
1911
RectButton,
2012
Switch,
2113
} from 'react-native-gesture-handler';
14+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
2215
import AsyncStorage from '@react-native-async-storage/async-storage';
2316
import OverflowParent from './src/release_tests/overflowParent';
2417
import DoublePinchRotate from './src/release_tests/doubleScalePinchAndRotate';
@@ -260,7 +253,6 @@ const Stack = createStackNavigator<RootStackParamList>();
260253
export default function App() {
261254
return (
262255
<GestureHandlerRootView>
263-
<StatusBar barStyle="dark-content" />
264256
<NavigationContainer>
265257
<Stack.Navigator
266258
screenOptions={{
@@ -306,6 +298,8 @@ function navigate(
306298
}
307299

308300
function MainScreen({ navigation }: StackScreenProps<ParamListBase>) {
301+
const insets = useSafeAreaInsets();
302+
309303
useEffect(() => {
310304
void AsyncStorage.multiGet([OPEN_LAST_EXAMPLE_KEY, LAST_EXAMPLE_KEY]).then(
311305
([openLastExample, lastExample]) => {
@@ -321,12 +315,16 @@ function MainScreen({ navigation }: StackScreenProps<ParamListBase>) {
321315
}, []);
322316

323317
return (
324-
<SafeAreaView style={styles.container}>
318+
<View style={styles.container}>
325319
<ListWithHeader
326320
style={styles.list}
327321
sections={EXAMPLES}
328322
keyExtractor={(example) => example.name}
329323
ListHeaderComponent={OpenLastExampleSetting}
324+
contentContainerStyle={{
325+
paddingBottom: insets.bottom,
326+
paddingTop: insets.top,
327+
}}
330328
renderItem={({ item }) => (
331329
<MainScreenItem
332330
name={item.name}
@@ -339,7 +337,7 @@ function MainScreen({ navigation }: StackScreenProps<ParamListBase>) {
339337
)}
340338
ItemSeparatorComponent={() => <View style={styles.separator} />}
341339
/>
342-
</SafeAreaView>
340+
</View>
343341
);
344342
}
345343

apps/common-app/src/ListWithHeader/ListWithHeader.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ScrollViewProps,
55
SectionList,
66
SectionListProps,
7+
StyleSheet,
78
} from 'react-native';
89
import Animated, {
910
SharedValue,
@@ -73,9 +74,22 @@ export function ListWithHeader<ItemT, SectionT>(
7374
};
7475
});
7576

77+
const contentContainerStyle =
78+
StyleSheet.flatten(props.contentContainerStyle) || {};
79+
if (typeof contentContainerStyle.paddingTop !== 'number') {
80+
contentContainerStyle.paddingTop = 0;
81+
console.error(
82+
'ListWithHeader: contentContainerStyle.paddingTop should be a number.'
83+
);
84+
}
85+
7686
return (
7787
<GestureDetector gesture={dragGesture}>
78-
<Animated.View style={[{ flex: 1 }, containerProps]}>
88+
<Animated.View
89+
style={[
90+
{ flex: 1, marginTop: contentContainerStyle.paddingTop },
91+
containerProps,
92+
]}>
7993
<Header scrollOffset={scrollOffset} />
8094
<SectionList
8195
{...props}
@@ -137,7 +151,10 @@ const ScrollComponentWithOffset = ({
137151
<Animated.ScrollView
138152
{...props}
139153
ref={scrollRef}
140-
contentContainerStyle={{ paddingTop: HEADER_HEIGHT }}
154+
contentContainerStyle={[
155+
props.contentContainerStyle,
156+
{ paddingTop: HEADER_HEIGHT },
157+
]}
141158
scrollEventThrottle={1}
142159
animatedProps={scrollProps}
143160
/>

0 commit comments

Comments
 (0)