Преглед на файлове

Set modal status bar style in constructor (#2103)

Since status bar style was applied when the screen was created, this caused a noticeable
artifact in status bar color.
Guy Carmeli преди 7 години
родител
ревизия
da69c6f54e
No account linked to committer's email address

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java Целия файл

@@ -19,10 +19,12 @@ import com.reactnativenavigation.params.FabParams;
19 19
 import com.reactnativenavigation.params.Orientation;
20 20
 import com.reactnativenavigation.params.ScreenParams;
21 21
 import com.reactnativenavigation.params.SlidingOverlayParams;
22
+import com.reactnativenavigation.params.StyleParams;
22 23
 import com.reactnativenavigation.params.TitleBarButtonParams;
23 24
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
24 25
 import com.reactnativenavigation.params.parsers.ModalAnimationFactory;
25 26
 import com.reactnativenavigation.screens.NavigationType;
27
+import com.reactnativenavigation.utils.StatusBar;
26 28
 
27 29
 import java.util.List;
28 30
 
@@ -112,6 +114,14 @@ class Modal extends Dialog implements DialogInterface.OnDismissListener, ScreenS
112 114
         this.screenParams = screenParams;
113 115
         createContent();
114 116
         setAnimation(screenParams);
117
+        setStatusBarStyle(screenParams.styleParams);
118
+    }
119
+
120
+    private void setStatusBarStyle(StyleParams styleParams) {
121
+        Window window = getWindow();
122
+        if (window == null) return;
123
+        StatusBar.setColor(window, styleParams.statusBarColor);
124
+        StatusBar.setTextColorScheme(window.getDecorView(), styleParams.statusBarTextColorScheme);
115 125
     }
116 126
 
117 127
     public AppCompatActivity getActivity() {

+ 4
- 33
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Целия файл

@@ -7,9 +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;
11 10
 import android.view.Window;
12
-import android.view.WindowManager;
13 11
 import android.widget.RelativeLayout;
14 12
 
15 13
 import com.facebook.react.bridge.Callback;
@@ -30,6 +28,7 @@ import com.reactnativenavigation.params.StyleParams;
30 28
 import com.reactnativenavigation.params.TitleBarButtonParams;
31 29
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
32 30
 import com.reactnativenavigation.params.parsers.StyleParamsParser;
31
+import com.reactnativenavigation.utils.StatusBar;
33 32
 import com.reactnativenavigation.views.ContentView;
34 33
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
35 34
 import com.reactnativenavigation.views.TopBar;
@@ -170,44 +169,16 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
170 169
         addView(topBar, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
171 170
     }
172 171
 
173
-    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
174 172
     private void setStatusBarColor(StyleParams.Color statusBarColor) {
175
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
176
-
177
-        final Window window = ((NavigationActivity) activity).getScreenWindow();
178
-        if (statusBarColor.hasColor()) {
179
-            window.setStatusBarColor(statusBarColor.getColor());
180
-        } else {
181
-            window.setStatusBarColor(Color.BLACK);
182
-        }
173
+        StatusBar.setColor(((NavigationActivity) activity).getScreenWindow(), statusBarColor);
183 174
     }
184 175
 
185 176
     private void setStatusBarHidden(boolean statusBarHidden) {
186
-        final Window window = ((NavigationActivity) activity).getScreenWindow();
187
-        if (statusBarHidden) {
188
-            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
189
-        } else {
190
-            window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
191
-        }
177
+        StatusBar.setHidden(((NavigationActivity) activity).getScreenWindow(), statusBarHidden);
192 178
     }
193 179
 
194
-    @TargetApi(Build.VERSION_CODES.M)
195 180
     private void setStatusBarTextColorScheme(StatusBarTextColorScheme textColorScheme) {
196
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
197
-        if (StatusBarTextColorScheme.Dark.equals(textColorScheme)) {
198
-            int flags = getSystemUiVisibility();
199
-            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
200
-            setSystemUiVisibility(flags);
201
-        } else {
202
-            clearLightStatusBar();
203
-        }
204
-    }
205
-
206
-    public void clearLightStatusBar() {
207
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
208
-        int flags = getSystemUiVisibility();
209
-        flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
210
-        setSystemUiVisibility(flags);
181
+        StatusBar.setTextColorScheme(this, textColorScheme);
211 182
     }
212 183
 
213 184
     @TargetApi(Build.VERSION_CODES.LOLLIPOP)

+ 51
- 0
android/app/src/main/java/com/reactnativenavigation/utils/StatusBar.java Целия файл

@@ -0,0 +1,51 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import android.annotation.TargetApi;
4
+import android.graphics.Color;
5
+import android.os.Build;
6
+import android.view.View;
7
+import android.view.Window;
8
+import android.view.WindowManager;
9
+
10
+import com.reactnativenavigation.params.StatusBarTextColorScheme;
11
+import com.reactnativenavigation.params.StyleParams;
12
+
13
+public class StatusBar {
14
+
15
+    public static void setHidden(Window window, boolean statusBarHidden) {
16
+        if (statusBarHidden) {
17
+            window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
18
+        } else {
19
+            window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
20
+        }
21
+    }
22
+
23
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
24
+    public static void setColor(Window window, StyleParams.Color statusBarColor) {
25
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
26
+        if (statusBarColor.hasColor()) {
27
+            window.setStatusBarColor(statusBarColor.getColor());
28
+        } else {
29
+            window.setStatusBarColor(Color.BLACK);
30
+        }
31
+    }
32
+
33
+    @TargetApi(Build.VERSION_CODES.M)
34
+    public static void setTextColorScheme(View view, StatusBarTextColorScheme textColorScheme) {
35
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
36
+        if (StatusBarTextColorScheme.Dark.equals(textColorScheme)) {
37
+            int flags = view.getSystemUiVisibility();
38
+            flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
39
+            view.setSystemUiVisibility(flags);
40
+        } else {
41
+            clearLightStatusBar(view);
42
+        }
43
+    }
44
+
45
+    private static void clearLightStatusBar(View view) {
46
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
47
+        int flags = view.getSystemUiVisibility();
48
+        flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
49
+        view.setSystemUiVisibility(flags);
50
+    }
51
+}