mirror of
https://github.com/status-im/react-native.git
synced 2025-02-23 06:38:13 +00:00
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
This commit is contained in:
parent
630e9faf74
commit
6c501eb666
@ -198,7 +198,10 @@ class StatusBar extends React.Component<Props> {
|
|||||||
static _defaultProps = createStackEntry({
|
static _defaultProps = createStackEntry({
|
||||||
animated: false,
|
animated: false,
|
||||||
showHideTransition: 'fade',
|
showHideTransition: 'fade',
|
||||||
backgroundColor: 'black',
|
backgroundColor: Platform.select({
|
||||||
|
android: StatusBarManager.DEFAULT_BACKGROUND_COLOR ?? 'black',
|
||||||
|
ios: 'black',
|
||||||
|
}),
|
||||||
barStyle: 'default',
|
barStyle: 'default',
|
||||||
translucent: false,
|
translucent: false,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
|
@ -38,6 +38,7 @@ import javax.annotation.Nullable;
|
|||||||
public class StatusBarModule extends ReactContextBaseJavaModule {
|
public class StatusBarModule extends ReactContextBaseJavaModule {
|
||||||
|
|
||||||
private static final String HEIGHT_KEY = "HEIGHT";
|
private static final String HEIGHT_KEY = "HEIGHT";
|
||||||
|
private static final String DEFAULT_BACKGROUND_COLOR_KEY = "DEFAULT_BACKGROUND_COLOR";
|
||||||
public static final String NAME = "StatusBarManager";
|
public static final String NAME = "StatusBarManager";
|
||||||
|
|
||||||
public StatusBarModule(ReactApplicationContext reactContext) {
|
public StatusBarModule(ReactApplicationContext reactContext) {
|
||||||
@ -52,14 +53,22 @@ public class StatusBarModule extends ReactContextBaseJavaModule {
|
|||||||
@Override
|
@Override
|
||||||
public @Nullable Map<String, Object> getConstants() {
|
public @Nullable Map<String, Object> getConstants() {
|
||||||
final Context context = getReactApplicationContext();
|
final Context context = getReactApplicationContext();
|
||||||
|
final Activity activity = getCurrentActivity();
|
||||||
|
|
||||||
final int heightResId = context.getResources()
|
final int heightResId = context.getResources()
|
||||||
.getIdentifier("status_bar_height", "dimen", "android");
|
.getIdentifier("status_bar_height", "dimen", "android");
|
||||||
final float height = heightResId > 0 ?
|
final float height = heightResId > 0 ?
|
||||||
PixelUtil.toDIPFromPixel(context.getResources().getDimensionPixelSize(heightResId)) :
|
PixelUtil.toDIPFromPixel(context.getResources().getDimensionPixelSize(heightResId)) :
|
||||||
0;
|
0;
|
||||||
|
String statusBarColorString = "black";
|
||||||
|
|
||||||
|
if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
final int statusBarColor = activity.getWindow().getStatusBarColor();
|
||||||
|
statusBarColorString = String.format("#%06X", (0xFFFFFF & statusBarColor));
|
||||||
|
}
|
||||||
|
|
||||||
return MapBuilder.<String, Object>of(
|
return MapBuilder.<String, Object>of(
|
||||||
HEIGHT_KEY, height);
|
HEIGHT_KEY, height, DEFAULT_BACKGROUND_COLOR_KEY, statusBarColorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user