Sfoglia il codice sorgente

Modal background color (#1038)

Support status bar color in Modals

fixes #1034
Guy Carmeli 7 anni fa
parent
commit
2e64705660

+ 9
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java Vedi File

@@ -2,6 +2,7 @@ package com.reactnativenavigation.controllers;
2 2
 
3 3
 import android.app.Dialog;
4 4
 import android.content.DialogInterface;
5
+import android.os.Build;
5 6
 import android.support.v7.app.AppCompatActivity;
6 7
 import android.view.Window;
7 8
 import android.view.WindowManager;
@@ -102,11 +103,18 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
102 103
         setOnDismissListener(this);
103 104
         requestWindowFeature(Window.FEATURE_NO_TITLE);
104 105
         layout = new ModalScreenLayout(getActivity(), screenParams, this);
105
-        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
106
+        setWindowFlags();
106 107
         setOrientation(screenParams.styleParams.orientation);
107 108
         setContentView(layout.asView());
108 109
     }
109 110
 
111
+    private void setWindowFlags() {
112
+        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
113
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
114
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
115
+        }
116
+    }
117
+
110 118
     private void setAnimation() {
111 119
         if (!screenParams.animateScreenTransitions) {
112 120
             if (getWindow() != null) {

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java Vedi File

@@ -1,6 +1,7 @@
1 1
 package com.reactnativenavigation.controllers;
2 2
 
3 3
 import android.support.v7.app.AppCompatActivity;
4
+import android.view.Window;
4 5
 
5 6
 import com.facebook.react.bridge.Callback;
6 7
 import com.reactnativenavigation.events.EventBus;
@@ -159,4 +160,8 @@ class ModalController implements ScreenStackContainer, Modal.OnModalDismissedLis
159 160
     void hideSlidingOverlay() {
160 161
         stack.peek().hideSlidingOverlay();
161 162
     }
163
+
164
+    Window getWindow() {
165
+        return stack.peek().getWindow();
166
+    }
162 167
 }

+ 6
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Vedi File

@@ -8,6 +8,7 @@ import android.os.Bundle;
8 8
 import android.support.annotation.Nullable;
9 9
 import android.support.v7.app.AppCompatActivity;
10 10
 import android.view.KeyEvent;
11
+import android.view.Window;
11 12
 
12 13
 import com.facebook.react.bridge.Callback;
13 14
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
@@ -66,8 +67,8 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
66 67
         activityParams = NavigationCommandsHandler.parseActivityParams(getIntent());
67 68
         disableActivityShowAnimationIfNeeded();
68 69
         setOrientation();
69
-        createLayout();
70 70
         createModalController();
71
+        createLayout();
71 72
         NavigationApplication.instance.getActivityCallbacks().onActivityCreated(this, savedInstanceState);
72 73
     }
73 74
 
@@ -370,6 +371,10 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
370 371
         }
371 372
     }
372 373
 
374
+    public Window getScreenWindow() {
375
+        return modalController.isShowing() ? modalController.getWindow() : getWindow();
376
+    }
377
+
373 378
     private void handleJsDevReloadEvent() {
374 379
         modalController.destroy();
375 380
         layout.destroy();

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java Vedi File

@@ -11,6 +11,7 @@ import android.widget.RelativeLayout;
11 11
 import com.facebook.react.bridge.Callback;
12 12
 import com.reactnativenavigation.NavigationApplication;
13 13
 import com.reactnativenavigation.animation.VisibilityAnimator;
14
+import com.reactnativenavigation.controllers.NavigationActivity;
14 15
 import com.reactnativenavigation.events.ContextualMenuHiddenEvent;
15 16
 import com.reactnativenavigation.events.Event;
16 17
 import com.reactnativenavigation.events.EventBus;
@@ -151,8 +152,7 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
151 152
     private void setStatusBarColor(StyleParams.Color statusBarColor) {
152 153
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
153 154
 
154
-        final Activity context = (Activity) getContext();
155
-        final Window window = context.getWindow();
155
+        final Window window = ((NavigationActivity) activity).getScreenWindow();
156 156
         if (statusBarColor.hasColor()) {
157 157
             window.setStatusBarColor(statusBarColor.getColor());
158 158
         } else {