Bläddra i källkod

[Android] Add ability to hide status bar via statusBarHidden option (#1821)

Vadim Ruban 7 år sedan
förälder
incheckning
16802218b8

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Visa fil

@@ -75,6 +75,7 @@ public class StyleParams {
75 75
     public Orientation orientation;
76 76
     public StatusBarTextColorScheme statusBarTextColorScheme;
77 77
     public Color statusBarColor;
78
+    public boolean statusBarHidden;
78 79
     public Color contextualMenuStatusBarColor;
79 80
     public Color contextualMenuButtonsColor;
80 81
     public Color contextualMenuBackgroundColor;

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java Visa fil

@@ -29,6 +29,7 @@ public class StyleParamsParser {
29 29
         StyleParams result = new StyleParams(params);
30 30
         result.orientation = Orientation.fromString(params.getString("orientation", getDefaultOrientation()));
31 31
         result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
32
+        result.statusBarHidden = getBoolean("statusBarHidden", getDefaultStatusHidden());
32 33
         result.statusBarTextColorScheme = StatusBarTextColorScheme.fromString(params.getString("statusBarTextColorScheme"));
33 34
         result.contextualMenuStatusBarColor = getColor("contextualMenuStatusBarColor", getDefaultContextualMenuStatusBarColor());
34 35
         result.contextualMenuButtonsColor = getColor("contextualMenuButtonsColor", getDefaultContextualMenuButtonsColor());
@@ -260,6 +261,10 @@ public class StyleParamsParser {
260 261
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.statusBarColor;
261 262
     }
262 263
 
264
+    private boolean getDefaultStatusHidden() {
265
+        return AppStyle.appStyle != null && AppStyle.appStyle.statusBarHidden;
266
+    }
267
+
263 268
     private StyleParams.Font getDefaultBottomTabsFontFamily() {
264 269
         return AppStyle.appStyle == null ? new StyleParams.Font() : AppStyle.appStyle.bottomTabFontFamily;
265 270
     }

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Visa fil

@@ -8,6 +8,7 @@ import android.os.Bundle;
8 8
 import android.support.v7.app.AppCompatActivity;
9 9
 import android.view.View;
10 10
 import android.view.Window;
11
+import android.view.WindowManager;
11 12
 import android.widget.RelativeLayout;
12 13
 
13 14
 import com.facebook.react.bridge.Callback;
@@ -105,6 +106,7 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
105 106
 
106 107
     public void setStyle() {
107 108
         setStatusBarColor(styleParams.statusBarColor);
109
+        setStatusBarHidden(styleParams.statusBarHidden);
108 110
         setStatusBarTextColorScheme(styleParams.statusBarTextColorScheme);
109 111
         setNavigationBarColor(styleParams.navigationBarColor);
110 112
         topBar.setStyle(styleParams);
@@ -175,6 +177,15 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
175 177
         }
176 178
     }
177 179
 
180
+    private void setStatusBarHidden(boolean statusBarHidden) {
181
+        final Window window = ((NavigationActivity) activity).getScreenWindow();
182
+        if (statusBarHidden) {
183
+            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
184
+        } else {
185
+            window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
186
+        }
187
+    }
188
+
178 189
     @TargetApi(Build.VERSION_CODES.M)
179 190
     private void setStatusBarTextColorScheme(StatusBarTextColorScheme textColorScheme) {
180 191
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js Visa fil

@@ -139,6 +139,7 @@ function convertStyleParams(originalStyleObject) {
139 139
   let ret = {
140 140
     orientation: originalStyleObject.orientation,
141 141
     statusBarColor: processColor(originalStyleObject.statusBarColor),
142
+    statusBarHidden: originalStyleObject.statusBarHidden,
142 143
     statusBarTextColorScheme: originalStyleObject.statusBarTextColorScheme,
143 144
     topBarReactView: originalStyleObject.navBarCustomView,
144 145
     topBarReactViewAlignment: originalStyleObject.navBarComponentAlignment,