Browse Source

[V3] Android: re-add support for navigationBarColor (#5547)

Add support for NavigationBar color on Android
Maurus Cuelenaere 5 years ago
parent
commit
8af95da24a

+ 9
- 1
docs/docs/options-migration.md View File

540
 }
540
 }
541
 ```
541
 ```
542
 
542
 
543
+## navigationBarColor
544
+NavigationBar color
545
+
546
+```js
547
+navigationBar: {
548
+  backgroundColor: 'red'
549
+}
550
+```
551
+
543
 ## drawUnderStatusBar
552
 ## drawUnderStatusBar
544
 Draw content behind the StatusBar
553
 Draw content behind the StatusBar
545
 
554
 
603
 * topBarShadowOffset
612
 * topBarShadowOffset
604
 * topBarShadowRadius
613
 * topBarShadowRadius
605
 * preferredContentSize
614
 * preferredContentSize
606
-* navigationBarColor
607
 * navBarSubTitleTextCentered
615
 * navBarSubTitleTextCentered
608
 * collapsingToolBarImage
616
 * collapsingToolBarImage
609
 * collapsingToolBarCollapsedColor
617
 * collapsingToolBarCollapsedColor

+ 3
- 0
docs/docs/styling.md View File

258
     drawBehind: true,
258
     drawBehind: true,
259
     visible: false
259
     visible: false
260
   },
260
   },
261
+  navigationBar: {
262
+    backgroundColor: 'red',
263
+  },
261
   layout: {
264
   layout: {
262
     topMargin: (await Navigation.constants()).statusBarHeight, // Set the layout's top margin
265
     topMargin: (await Navigation.constants()).statusBarHeight, // Set the layout's top margin
263
     orientation: ['portrait', 'landscape'] | ['sensorLandscape'], // An array of supported orientations
266
     orientation: ['portrait', 'landscape'] | ['sensorLandscape'], // An array of supported orientations

+ 28
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/NavigationBarOptions.java View File

1
+package com.reactnativenavigation.parse;
2
+
3
+import com.reactnativenavigation.parse.params.Colour;
4
+import com.reactnativenavigation.parse.params.NullColor;
5
+import com.reactnativenavigation.parse.parsers.ColorParser;
6
+
7
+import org.json.JSONObject;
8
+
9
+public class NavigationBarOptions {
10
+    public static NavigationBarOptions parse(JSONObject json) {
11
+        NavigationBarOptions result = new NavigationBarOptions();
12
+        if (json == null) return result;
13
+
14
+        result.backgroundColor = ColorParser.parse(json, "backgroundColor");
15
+
16
+        return result;
17
+    }
18
+
19
+    public Colour backgroundColor = new NullColor();
20
+
21
+    public void mergeWith(NavigationBarOptions other) {
22
+        if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
23
+    }
24
+
25
+    public void mergeWithDefault(NavigationBarOptions defaultOptions) {
26
+        if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
27
+    }
28
+}

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java View File

27
         result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu"));
27
         result.sideMenuRootOptions = SideMenuRootOptions.parse(json.optJSONObject("sideMenu"));
28
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
28
         result.animations = AnimationsOptions.parse(json.optJSONObject("animations"));
29
         result.modal = ModalOptions.parse(json);
29
         result.modal = ModalOptions.parse(json);
30
+        result.navigationBar = NavigationBarOptions.parse(json.optJSONObject("navigationBar"));
30
         result.statusBar = StatusBarOptions.parse(json.optJSONObject("statusBar"));
31
         result.statusBar = StatusBarOptions.parse(json.optJSONObject("statusBar"));
31
         result.layout = LayoutOptions.parse(json.optJSONObject("layout"));
32
         result.layout = LayoutOptions.parse(json.optJSONObject("layout"));
32
         result.transitions = Transitions.parse(json.optJSONObject("customTransition"));
33
         result.transitions = Transitions.parse(json.optJSONObject("customTransition"));
44
     @NonNull public AnimationsOptions animations = new AnimationsOptions();
45
     @NonNull public AnimationsOptions animations = new AnimationsOptions();
45
     @NonNull public SideMenuRootOptions sideMenuRootOptions = new SideMenuRootOptions();
46
     @NonNull public SideMenuRootOptions sideMenuRootOptions = new SideMenuRootOptions();
46
     @NonNull public ModalOptions modal = new ModalOptions();
47
     @NonNull public ModalOptions modal = new ModalOptions();
48
+    @NonNull public NavigationBarOptions navigationBar = new NavigationBarOptions();
47
     @NonNull public StatusBarOptions statusBar = new StatusBarOptions();
49
     @NonNull public StatusBarOptions statusBar = new StatusBarOptions();
48
     @NonNull public LayoutOptions layout = new LayoutOptions();
50
     @NonNull public LayoutOptions layout = new LayoutOptions();
49
     @NonNull public Transitions transitions = new Transitions();
51
     @NonNull public Transitions transitions = new Transitions();
65
         result.sideMenuRootOptions.mergeWith(sideMenuRootOptions);
67
         result.sideMenuRootOptions.mergeWith(sideMenuRootOptions);
66
         result.animations.mergeWith(animations);
68
         result.animations.mergeWith(animations);
67
         result.modal.mergeWith(modal);
69
         result.modal.mergeWith(modal);
70
+        result.navigationBar.mergeWith(navigationBar);
68
         result.statusBar.mergeWith(statusBar);
71
         result.statusBar.mergeWith(statusBar);
69
         result.layout.mergeWith(layout);
72
         result.layout.mergeWith(layout);
70
         result.transitions.mergeWith(transitions);
73
         result.transitions.mergeWith(transitions);
83
         result.animations.mergeWith(other.animations);
86
         result.animations.mergeWith(other.animations);
84
         result.sideMenuRootOptions.mergeWith(other.sideMenuRootOptions);
87
         result.sideMenuRootOptions.mergeWith(other.sideMenuRootOptions);
85
         result.modal.mergeWith(other.modal);
88
         result.modal.mergeWith(other.modal);
89
+        result.navigationBar.mergeWith(other.navigationBar);
86
         result.statusBar.mergeWith(other.statusBar);
90
         result.statusBar.mergeWith(other.statusBar);
87
         result.layout.mergeWith(other.layout);
91
         result.layout.mergeWith(other.layout);
88
         result.transitions.mergeWith(transitions);
92
         result.transitions.mergeWith(transitions);
99
         animations.mergeWithDefault(defaultOptions.animations);
103
         animations.mergeWithDefault(defaultOptions.animations);
100
         sideMenuRootOptions.mergeWithDefault(defaultOptions.sideMenuRootOptions);
104
         sideMenuRootOptions.mergeWithDefault(defaultOptions.sideMenuRootOptions);
101
         modal.mergeWithDefault(defaultOptions.modal);
105
         modal.mergeWithDefault(defaultOptions.modal);
106
+        navigationBar.mergeWithDefault(defaultOptions.navigationBar);
102
         statusBar.mergeWithDefault(defaultOptions.statusBar);
107
         statusBar.mergeWithDefault(defaultOptions.statusBar);
103
         layout.mergeWithDefault(defaultOptions.layout);
108
         layout.mergeWithDefault(defaultOptions.layout);
104
         transitions.mergeWithDefault(defaultOptions.transitions);
109
         transitions.mergeWithDefault(defaultOptions.transitions);

+ 9
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/Presenter.java View File

10
 import android.view.ViewGroup.MarginLayoutParams;
10
 import android.view.ViewGroup.MarginLayoutParams;
11
 import android.view.Window;
11
 import android.view.Window;
12
 
12
 
13
+import com.reactnativenavigation.parse.NavigationBarOptions;
13
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.OrientationOptions;
15
 import com.reactnativenavigation.parse.OrientationOptions;
15
 import com.reactnativenavigation.parse.StatusBarOptions;
16
 import com.reactnativenavigation.parse.StatusBarOptions;
84
     }
85
     }
85
 
86
 
86
     private void applyStatusBarOptions(Options options) {
87
     private void applyStatusBarOptions(Options options) {
88
+        setNavigationBarBackgroundColor(options.navigationBar);
87
         setStatusBarBackgroundColor(options.statusBar);
89
         setStatusBarBackgroundColor(options.statusBar);
88
         setTextColorScheme(options.statusBar.textColorScheme);
90
         setTextColorScheme(options.statusBar.textColorScheme);
89
         setTranslucent(options.statusBar);
91
         setTranslucent(options.statusBar);
117
         }
119
         }
118
     }
120
     }
119
 
121
 
122
+    private void setNavigationBarBackgroundColor(NavigationBarOptions navigationBar) {
123
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && navigationBar.backgroundColor.canApplyValue()) {
124
+            int defaultColor = activity.getWindow().getNavigationBarColor();
125
+            activity.getWindow().setNavigationBarColor(navigationBar.backgroundColor.get(defaultColor));
126
+        }
127
+    }
128
+
120
     private void setTextColorScheme(TextColorScheme scheme) {
129
     private void setTextColorScheme(TextColorScheme scheme) {
121
         final View view = activity.getWindow().getDecorView();
130
         final View view = activity.getWindow().getDecorView();
122
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
131
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;