Bladeren bron

Support statusBarTextColorScheme on Android

Guy Carmeli 7 jaren geleden
bovenliggende
commit
096243827a

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/params/StatusBarTextColorScheme.java Bestand weergeven

@@ -0,0 +1,20 @@
1
+package com.reactnativenavigation.params;
2
+
3
+import android.os.Build;
4
+import android.support.annotation.Nullable;
5
+
6
+public enum StatusBarTextColorScheme {
7
+    Light, Dark, Undefined;
8
+
9
+    public static StatusBarTextColorScheme fromString(@Nullable String colorScheme) {
10
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || colorScheme == null) return Undefined;
11
+        switch (colorScheme) {
12
+            case "light":
13
+                return Light;
14
+            case "dark":
15
+                return Dark;
16
+            default:
17
+                return Undefined;
18
+        }
19
+    }
20
+}

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Bestand weergeven

@@ -73,6 +73,7 @@ public class StyleParams {
73 73
     }
74 74
 
75 75
     public Orientation orientation;
76
+    public StatusBarTextColorScheme statusBarTextColorScheme;
76 77
     public Color statusBarColor;
77 78
     public Color contextualMenuStatusBarColor;
78 79
     public Color contextualMenuButtonsColor;

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java Bestand weergeven

@@ -5,6 +5,7 @@ import android.os.Bundle;
5 5
 
6 6
 import com.reactnativenavigation.params.AppStyle;
7 7
 import com.reactnativenavigation.params.Orientation;
8
+import com.reactnativenavigation.params.StatusBarTextColorScheme;
8 9
 import com.reactnativenavigation.params.StyleParams;
9 10
 
10 11
 public class StyleParamsParser {
@@ -27,6 +28,7 @@ public class StyleParamsParser {
27 28
         StyleParams result = new StyleParams(params);
28 29
         result.orientation = Orientation.fromString(params.getString("orientation", getDefaultOrientation()));
29 30
         result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
31
+        result.statusBarTextColorScheme = StatusBarTextColorScheme.fromString(params.getString("statusBarTextColorScheme"));
30 32
         result.contextualMenuStatusBarColor = getColor("contextualMenuStatusBarColor", getDefaultContextualMenuStatusBarColor());
31 33
         result.contextualMenuButtonsColor = getColor("contextualMenuButtonsColor", getDefaultContextualMenuButtonsColor());
32 34
         result.contextualMenuBackgroundColor = getColor("contextualMenuBackgroundColor", getDefaultContextualMenuBackgroundColor());

+ 22
- 0
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Bestand weergeven

@@ -7,6 +7,7 @@ import android.graphics.Color;
7 7
 import android.os.Build;
8 8
 import android.os.Bundle;
9 9
 import android.support.v7.app.AppCompatActivity;
10
+import android.view.View;
10 11
 import android.view.Window;
11 12
 import android.widget.RelativeLayout;
12 13
 
@@ -23,6 +24,7 @@ import com.reactnativenavigation.params.BaseScreenParams;
23 24
 import com.reactnativenavigation.params.ContextualMenuParams;
24 25
 import com.reactnativenavigation.params.FabParams;
25 26
 import com.reactnativenavigation.params.ScreenParams;
27
+import com.reactnativenavigation.params.StatusBarTextColorScheme;
26 28
 import com.reactnativenavigation.params.StyleParams;
27 29
 import com.reactnativenavigation.params.TitleBarButtonParams;
28 30
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
@@ -104,6 +106,7 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
104 106
 
105 107
     public void setStyle() {
106 108
         setStatusBarColor(styleParams.statusBarColor);
109
+        setStatusBarTextColorScheme(styleParams.statusBarTextColorScheme);
107 110
         setNavigationBarColor(styleParams.navigationBarColor);
108 111
         topBar.setStyle(styleParams);
109 112
         if (styleParams.screenBackgroundColor.hasColor()) {
@@ -172,6 +175,25 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
172 175
         }
173 176
     }
174 177
 
178
+    @TargetApi(Build.VERSION_CODES.M)
179
+    private void setStatusBarTextColorScheme(StatusBarTextColorScheme textColorScheme) {
180
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
181
+        if (StatusBarTextColorScheme.Dark.equals(textColorScheme)) {
182
+            int flags = getSystemUiVisibility();
183
+            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
184
+            setSystemUiVisibility(flags);
185
+        } else {
186
+            clearLightStatusBar();
187
+        }
188
+    }
189
+
190
+    public void clearLightStatusBar() {
191
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
192
+        int flags = getSystemUiVisibility();
193
+        flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
194
+        setSystemUiVisibility(flags);
195
+    }
196
+
175 197
     @TargetApi(Build.VERSION_CODES.LOLLIPOP)
176 198
     public void setNavigationBarColor(StyleParams.Color navigationBarColor) {
177 199
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js Bestand weergeven

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