Browse Source

Modal context menu fix (#1106)

* React Native v0.40.0 fixes

* Implement disableIconTint property on Android TitleBarButtons

* Show contextual menu only on Modal, if showing

* Fix crash if font not set in title bar button parameters
Darren Osadchuk 7 years ago
parent
commit
d42f7eeed4

+ 11
- 4
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

347
     }
347
     }
348
 
348
 
349
     public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
349
     public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
350
-        layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
351
-        modalController.showContextualMenu(screenInstanceId, params, onButtonClicked);
350
+        if (modalController.isShowing()) {
351
+            modalController.showContextualMenu(screenInstanceId, params, onButtonClicked);
352
+        } else
353
+        {
354
+            layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
355
+        }
352
     }
356
     }
353
 
357
 
354
     public void dismissContextualMenu(String screenInstanceId) {
358
     public void dismissContextualMenu(String screenInstanceId) {
355
-        layout.dismissContextualMenu(screenInstanceId);
356
-        modalController.dismissContextualMenu(screenInstanceId);
359
+        if (modalController.isShowing()) {
360
+            modalController.dismissContextualMenu(screenInstanceId);
361
+        } else {
362
+            layout.dismissContextualMenu(screenInstanceId);
363
+        }
357
     }
364
     }
358
 
365
 
359
     @Override
366
     @Override

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/BaseTitleBarButtonParams.java View File

24
     public StyleParams.Color disabledColor;
24
     public StyleParams.Color disabledColor;
25
     public ShowAsAction showAsAction;
25
     public ShowAsAction showAsAction;
26
     public boolean enabled = true;
26
     public boolean enabled = true;
27
+    public boolean disableIconTint = false;
27
 
28
 
28
     public void setStyleFromScreen(StyleParams styleParams) {
29
     public void setStyleFromScreen(StyleParams styleParams) {
29
         setColorFromScreenStyle(styleParams.titleBarButtonColor);
30
         setColorFromScreenStyle(styleParams.titleBarButtonColor);

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/TitleBarButtonParams.java View File

9
         super.setStyleFromScreen(styleParams);
9
         super.setStyleFromScreen(styleParams);
10
         font = styleParams.titleBarTitleFont;
10
         font = styleParams.titleBarTitleFont;
11
     }
11
     }
12
+
13
+    public boolean hasFont()
14
+    {
15
+        return font != null && font.hasFont();
16
+    }
12
 }
17
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/TitleBarButtonParamsParser.java View File

32
         result.enabled = bundle.getBoolean("enabled", true);
32
         result.enabled = bundle.getBoolean("enabled", true);
33
         result.hint = bundle.getString("hint", "");
33
         result.hint = bundle.getString("hint", "");
34
         result.eventId = bundle.getString("id");
34
         result.eventId = bundle.getString("id");
35
+        result.disableIconTint = bundle.getBoolean("disableIconTint", false);
35
         return result;
36
         return result;
36
     }
37
     }
37
 
38
 

+ 8
- 4
android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java View File

42
     }
42
     }
43
 
43
 
44
     private MenuItem createMenuItem(int index) {
44
     private MenuItem createMenuItem(int index) {
45
-        if (!buttonParams.font.hasFont() || TextUtils.isEmpty(buttonParams.label)) {
45
+        if (!buttonParams.hasFont() || TextUtils.isEmpty(buttonParams.label)) {
46
             return menu.add(Menu.NONE, Menu.NONE, index, buttonParams.label);
46
             return menu.add(Menu.NONE, Menu.NONE, index, buttonParams.label);
47
         }
47
         }
48
         TypefaceSpan span = new TypefaceSpan(buttonParams.font.get());
48
         TypefaceSpan span = new TypefaceSpan(buttonParams.font.get());
58
     }
58
     }
59
 
59
 
60
     private void setColor() {
60
     private void setColor() {
61
-        if (!hasColor()) {
61
+        if (!hasColor() || disableIconTint()) {
62
             return;
62
             return;
63
         }
63
         }
64
 
64
 
84
     }
84
     }
85
 
85
 
86
     private void setFont() {
86
     private void setFont() {
87
-        if (!buttonParams.font.hasFont()) {
87
+        if (!buttonParams.hasFont()) {
88
             return;
88
             return;
89
         }
89
         }
90
         ArrayList<View> buttons = findActualTextViewInMenuByLabel();
90
         ArrayList<View> buttons = findActualTextViewInMenuByLabel();
106
 
106
 
107
     private void setTextFontForFoundButtonViews(ArrayList<View> buttons) {
107
     private void setTextFontForFoundButtonViews(ArrayList<View> buttons) {
108
         for (View button : buttons) {
108
         for (View button : buttons) {
109
-            if (buttonParams.font.hasFont()) {
109
+            if (buttonParams.hasFont()) {
110
                 ((TextView) button).setTypeface(buttonParams.font.get());
110
                 ((TextView) button).setTypeface(buttonParams.font.get());
111
             }
111
             }
112
         }
112
         }
120
         return buttonParams.color.hasColor();
120
         return buttonParams.color.hasColor();
121
     }
121
     }
122
 
122
 
123
+    private boolean disableIconTint() {
124
+        return buttonParams.disableIconTint;
125
+    }
126
+
123
     @Override
127
     @Override
124
     public boolean onMenuItemClick(MenuItem item) {
128
     public boolean onMenuItemClick(MenuItem item) {
125
         NavigationApplication.instance.getEventEmitter().sendNavigatorEvent(buttonParams.eventId, navigatorEventId);
129
         NavigationApplication.instance.getEventEmitter().sendNavigatorEvent(buttonParams.eventId, navigatorEventId);