Browse Source

Modal background color (#1038)

Support status bar color in Modals

fixes #1034
Guy Carmeli 7 years ago
parent
commit
2e64705660

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

2
 
2
 
3
 import android.app.Dialog;
3
 import android.app.Dialog;
4
 import android.content.DialogInterface;
4
 import android.content.DialogInterface;
5
+import android.os.Build;
5
 import android.support.v7.app.AppCompatActivity;
6
 import android.support.v7.app.AppCompatActivity;
6
 import android.view.Window;
7
 import android.view.Window;
7
 import android.view.WindowManager;
8
 import android.view.WindowManager;
102
         setOnDismissListener(this);
103
         setOnDismissListener(this);
103
         requestWindowFeature(Window.FEATURE_NO_TITLE);
104
         requestWindowFeature(Window.FEATURE_NO_TITLE);
104
         layout = new ModalScreenLayout(getActivity(), screenParams, this);
105
         layout = new ModalScreenLayout(getActivity(), screenParams, this);
105
-        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
106
+        setWindowFlags();
106
         setOrientation(screenParams.styleParams.orientation);
107
         setOrientation(screenParams.styleParams.orientation);
107
         setContentView(layout.asView());
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
     private void setAnimation() {
118
     private void setAnimation() {
111
         if (!screenParams.animateScreenTransitions) {
119
         if (!screenParams.animateScreenTransitions) {
112
             if (getWindow() != null) {
120
             if (getWindow() != null) {

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

1
 package com.reactnativenavigation.controllers;
1
 package com.reactnativenavigation.controllers;
2
 
2
 
3
 import android.support.v7.app.AppCompatActivity;
3
 import android.support.v7.app.AppCompatActivity;
4
+import android.view.Window;
4
 
5
 
5
 import com.facebook.react.bridge.Callback;
6
 import com.facebook.react.bridge.Callback;
6
 import com.reactnativenavigation.events.EventBus;
7
 import com.reactnativenavigation.events.EventBus;
159
     void hideSlidingOverlay() {
160
     void hideSlidingOverlay() {
160
         stack.peek().hideSlidingOverlay();
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 View File

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

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

11
 import com.facebook.react.bridge.Callback;
11
 import com.facebook.react.bridge.Callback;
12
 import com.reactnativenavigation.NavigationApplication;
12
 import com.reactnativenavigation.NavigationApplication;
13
 import com.reactnativenavigation.animation.VisibilityAnimator;
13
 import com.reactnativenavigation.animation.VisibilityAnimator;
14
+import com.reactnativenavigation.controllers.NavigationActivity;
14
 import com.reactnativenavigation.events.ContextualMenuHiddenEvent;
15
 import com.reactnativenavigation.events.ContextualMenuHiddenEvent;
15
 import com.reactnativenavigation.events.Event;
16
 import com.reactnativenavigation.events.Event;
16
 import com.reactnativenavigation.events.EventBus;
17
 import com.reactnativenavigation.events.EventBus;
151
     private void setStatusBarColor(StyleParams.Color statusBarColor) {
152
     private void setStatusBarColor(StyleParams.Color statusBarColor) {
152
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
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
         if (statusBarColor.hasColor()) {
156
         if (statusBarColor.hasColor()) {
157
             window.setStatusBarColor(statusBarColor.getColor());
157
             window.setStatusBarColor(statusBarColor.getColor());
158
         } else {
158
         } else {