Просмотр исходного кода

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 лет назад
Родитель
Сommit
d42f7eeed4

+ 11
- 4
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Просмотреть файл

@@ -347,13 +347,20 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
347 347
     }
348 348
 
349 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 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 366
     @Override

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/BaseTitleBarButtonParams.java Просмотреть файл

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

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/TitleBarButtonParams.java Просмотреть файл

@@ -9,4 +9,9 @@ public class TitleBarButtonParams extends BaseTitleBarButtonParams {
9 9
         super.setStyleFromScreen(styleParams);
10 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 Просмотреть файл

@@ -32,6 +32,7 @@ public class TitleBarButtonParamsParser extends Parser {
32 32
         result.enabled = bundle.getBoolean("enabled", true);
33 33
         result.hint = bundle.getString("hint", "");
34 34
         result.eventId = bundle.getString("id");
35
+        result.disableIconTint = bundle.getBoolean("disableIconTint", false);
35 36
         return result;
36 37
     }
37 38
 

+ 8
- 4
android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java Просмотреть файл

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