Skip to content

Commit 6c501eb

Browse files
Arthur Leefacebook-github-bot
Arthur Lee
authored andcommitted
Fix status bar default on Android
Summary: On Android, the status bar color is not always black by default. The existing code causes the status bar to revert to black once the last `<StatusBar>` component is unmounted from the "stack". This diff reverts the bar background color to what it was before, instead of assuming black. Reviewed By: yungsters Differential Revision: D13368136 fbshipit-source-id: ef0154f776607b57bb9400b72d521f5f485b0075
1 parent 630e9fa commit 6c501eb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Diff for: Libraries/Components/StatusBar/StatusBar.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ class StatusBar extends React.Component<Props> {
198198
static _defaultProps = createStackEntry({
199199
animated: false,
200200
showHideTransition: 'fade',
201-
backgroundColor: 'black',
201+
backgroundColor: Platform.select({
202+
android: StatusBarManager.DEFAULT_BACKGROUND_COLOR ?? 'black',
203+
ios: 'black',
204+
}),
202205
barStyle: 'default',
203206
translucent: false,
204207
hidden: false,

Diff for: ReactAndroid/src/main/java/com/facebook/react/modules/statusbar/StatusBarModule.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
public class StatusBarModule extends ReactContextBaseJavaModule {
3939

4040
private static final String HEIGHT_KEY = "HEIGHT";
41+
private static final String DEFAULT_BACKGROUND_COLOR_KEY = "DEFAULT_BACKGROUND_COLOR";
4142
public static final String NAME = "StatusBarManager";
4243

4344
public StatusBarModule(ReactApplicationContext reactContext) {
@@ -52,14 +53,22 @@ public String getName() {
5253
@Override
5354
public @Nullable Map<String, Object> getConstants() {
5455
final Context context = getReactApplicationContext();
56+
final Activity activity = getCurrentActivity();
57+
5558
final int heightResId = context.getResources()
5659
.getIdentifier("status_bar_height", "dimen", "android");
5760
final float height = heightResId > 0 ?
5861
PixelUtil.toDIPFromPixel(context.getResources().getDimensionPixelSize(heightResId)) :
5962
0;
63+
String statusBarColorString = "black";
64+
65+
if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
66+
final int statusBarColor = activity.getWindow().getStatusBarColor();
67+
statusBarColorString = String.format("#%06X", (0xFFFFFF & statusBarColor));
68+
}
6069

6170
return MapBuilder.<String, Object>of(
62-
HEIGHT_KEY, height);
71+
HEIGHT_KEY, height, DEFAULT_BACKGROUND_COLOR_KEY, statusBarColorString);
6372
}
6473

6574
@ReactMethod

0 commit comments

Comments
 (0)