Skip to content

Commit fe80756

Browse files
authored
fix(Android): remove setting system bar translucent props from JS if in edge to edge (#2949)
## Description Fixes #2948 Fixes an issue where system bar styles set using `SystemBars.setStyle` function from `react-native-edge-to-edge` would be overridden by default values set in `react-native-screens`. Those should only work when we define system bar styles via screen options but in #2464 that integrated `react-native-edge-to-edge` with `react-native-screens`, we would always set `statusBarTranslucent` and `navigationBarTranslucent` props when in edge to edge ([code here](https://github.com/software-mansion/react-native-screens/pull/2464/files#diff-d51c072177510e603797455a4c3c14a049d0cfdbd39132fb53a6c187de8b7789R30-R31)), which would set `didSetStatusBarAppearance`/`didSetNavigationBarAppearance` and in result, make `screens` use default values for system bar styles. Setting `statusBarTranslucent` and `navigationBarTranslucent` props to `true` in edge-to-edge is not necessary and it's currently ignored in native code when in edge-to-edge after #2913 ([here](https://github.com/software-mansion/react-native-screens/pull/2913/files#diff-49e80f92048eb21d46beae35985ce78f79217693be04df175e5e679878d0f2c7R158) and [there](https://github.com/software-mansion/react-native-screens/pull/2913/files#diff-49e80f92048eb21d46beae35985ce78f79217693be04df175e5e679878d0f2c7R234)). Thanks to @efstathiosntonas for [reporting the issue and finding](#2913 (comment)) the culprit! ## Changes - remove setting `statusBarTranslucent` and `navigationBarTranslucent` in `edge-to-edge.tsx` - add test screen ## Screenshots / GIFs | before | after | | --- | --- | | <video src="https://github.com/user-attachments/assets/09739d52-7db6-49ac-8e48-1311734e8ff2" /> | <video src="https://github.com/user-attachments/assets/cd0dee11-135e-4134-a56c-1dbd20218304" /> | ## Test code and steps to reproduce Run `Test2949` **as a main app** by modifying `App.tsx` in example app. ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes
1 parent 10c9335 commit fe80756

3 files changed

Lines changed: 95 additions & 5 deletions

File tree

apps/src/tests/Test2949.tsx

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import React, { useEffect, useState } from 'react';
2+
import { NavigationContainer, ParamListBase } from '@react-navigation/native';
3+
import {
4+
NativeStackNavigationProp,
5+
createNativeStackNavigator,
6+
} from '@react-navigation/native-stack';
7+
import { Button, Text, View } from 'react-native';
8+
9+
// @ts-ignore: react-native-edge-to-edge is a dependency of example apps, not the library itself,
10+
// so we get an error here but it works correctly
11+
import { SystemBars } from 'react-native-edge-to-edge';
12+
13+
type RouteParamList = {
14+
Home: undefined;
15+
Second: undefined;
16+
};
17+
18+
type NavigationProp<ParamList extends ParamListBase> = {
19+
navigation: NativeStackNavigationProp<ParamList>;
20+
};
21+
22+
type StackNavigationProp = NavigationProp<RouteParamList>;
23+
24+
const Stack = createNativeStackNavigator<RouteParamList>();
25+
26+
function Home({ navigation }: StackNavigationProp) {
27+
const [style, setStyle] = useState<'dark' | 'light'>('dark');
28+
29+
useEffect(() => {
30+
SystemBars.setStyle({
31+
statusBar: style,
32+
navigationBar: style,
33+
});
34+
}, [style]);
35+
36+
return (
37+
<>
38+
<View
39+
style={{
40+
flex: 1,
41+
alignItems: 'center',
42+
justifyContent: 'center',
43+
gap: 10,
44+
}}>
45+
<View style={{ padding: 20 }}>
46+
<Text>
47+
The goal of this test is to check react-native-edge-to-edge's
48+
SystemBars.setStyle().
49+
</Text>
50+
<Text>
51+
Props from react-navigation/react-native-screens that modify the
52+
system bars interfere with the react-native-edge-to-edge's
53+
SystemBars so in order to test this properly, run this test as the
54+
main app content (without Example screen menu) by changing App.tsx.
55+
</Text>
56+
</View>
57+
<Button
58+
title="Change style"
59+
onPress={() =>
60+
style === 'dark' ? setStyle('light') : setStyle('dark')
61+
}
62+
/>
63+
<Button
64+
title="Open second"
65+
onPress={() => navigation.navigate('Second')}
66+
/>
67+
</View>
68+
</>
69+
);
70+
}
71+
72+
function Second({ navigation }: StackNavigationProp) {
73+
return (
74+
<>
75+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
76+
<Button title="Go back" onPress={() => navigation.goBack()} />
77+
</View>
78+
</>
79+
);
80+
}
81+
82+
export default function App() {
83+
return (
84+
<>
85+
<NavigationContainer>
86+
<Stack.Navigator>
87+
<Stack.Screen name="Home" component={Home} />
88+
<Stack.Screen name="Second" component={Second} />
89+
</Stack.Navigator>
90+
</NavigationContainer>
91+
</>
92+
);
93+
}

apps/src/tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export { default as Test2877 } from './Test2877'; // [E2E created](iOS): issue i
138138
export { default as Test2895 } from './Test2895';
139139
export { default as Test2899 } from './Test2899';
140140
export { default as Test2926 } from './Test2926'; // [E2E created](iOS): PR related to iOS search bar
141+
export { default as Test2949 } from './Test2949'; // [E2E skipped]: can't check system bars styles
141142
export { default as TestScreenAnimation } from './TestScreenAnimation';
142143
export { default as TestScreenAnimationV5 } from './TestScreenAnimationV5';
143144
export { default as TestHeader } from './TestHeader';

src/components/helpers/edge-to-edge.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,5 @@ export function transformEdgeToEdgeProps(props: ScreenProps): ScreenProps {
2525
});
2626
}
2727

28-
return {
29-
...rest,
30-
statusBarTranslucent: true,
31-
navigationBarTranslucent: true,
32-
};
28+
return rest;
3329
}

0 commit comments

Comments
 (0)