Guy Carmeli 7 years ago
parent
commit
09fdf9a7e4

+ 3
- 4
android/app/src/main/java/com/reactnativenavigation/params/TitleBarLeftButtonParams.java View File

@@ -6,7 +6,6 @@ import com.balysv.materialmenu.MaterialMenuDrawable;
6 6
 
7 7
 public class TitleBarLeftButtonParams extends TitleBarButtonParams {
8 8
     @Nullable public MaterialMenuDrawable.IconState iconState;
9
-    public boolean overrideBackPressInJs;
10 9
 
11 10
     public TitleBarLeftButtonParams(TitleBarButtonParams params) {
12 11
         icon = params.icon;
@@ -19,11 +18,11 @@ public class TitleBarLeftButtonParams extends TitleBarButtonParams {
19 18
         return eventId.equals("back");
20 19
     }
21 20
 
22
-    public boolean hasIcon() {
21
+    public boolean hasDefaultIcon() {
23 22
         return iconState != null;
24 23
     }
25 24
 
26
-    public void setOverrideBackPressInJs(boolean overrideBackPressInJs) {
27
-        this.overrideBackPressInJs = overrideBackPressInJs;
25
+    public boolean hasCustomIcon() {
26
+        return icon != null;
28 27
     }
29 28
 }

+ 15
- 3
android/app/src/main/java/com/reactnativenavigation/views/LeftButton.java View File

@@ -8,6 +8,7 @@ import com.balysv.materialmenu.MaterialMenuDrawable;
8 8
 import com.reactnativenavigation.NavigationApplication;
9 9
 import com.reactnativenavigation.params.TitleBarButtonParams;
10 10
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
11
+import com.reactnativenavigation.utils.ViewUtils;
11 12
 
12 13
 class LeftButton extends MaterialMenuDrawable implements View.OnClickListener {
13 14
 
@@ -64,18 +65,29 @@ class LeftButton extends MaterialMenuDrawable implements View.OnClickListener {
64 65
 
65 66
     private void setInitialState() {
66 67
         if (params != null) {
67
-            setIconState(params.iconState);
68
+            if (params.iconState != null) {
69
+                setIconState(params.iconState);
70
+            }
68 71
         } else {
69 72
             setVisible(false);
70 73
         }
71 74
     }
72 75
 
76
+    @Override
77
+    public void setColor(int color) {
78
+        if (params.hasDefaultIcon()) {
79
+            super.setColor(color);
80
+        } else {
81
+            ViewUtils.tintDrawable(params.icon, color, true );
82
+        }
83
+    }
84
+
73 85
     private boolean isBackButton() {
74
-        return getIconState() == IconState.ARROW;
86
+        return params.hasDefaultIcon() && getIconState() == IconState.ARROW;
75 87
     }
76 88
 
77 89
     private boolean isSideMenuButton() {
78
-        return getIconState() == IconState.BURGER;
90
+        return params.hasDefaultIcon() && getIconState() == IconState.BURGER;
79 91
     }
80 92
 
81 93
     private void sendClickEvent() {

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java View File

@@ -61,7 +61,7 @@ public class TitleBar extends Toolbar {
61 61
         if (shouldSetLeftButton(leftButtonParams)) {
62 62
             createAndSetLeftButton(leftButtonParams, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
63 63
         } else if (hasLeftButton()) {
64
-            if (leftButtonParams.hasIcon()) {
64
+            if (leftButtonParams.hasDefaultIcon()) {
65 65
                 updateLeftButton(leftButtonParams);
66 66
             } else {
67 67
                 removeLeftButton();
@@ -164,7 +164,7 @@ public class TitleBar extends Toolbar {
164 164
     }
165 165
 
166 166
     private boolean shouldSetLeftButton(TitleBarLeftButtonParams leftButtonParams) {
167
-        return leftButton == null && leftButtonParams != null && leftButtonParams.iconState != null;
167
+        return leftButton == null && leftButtonParams != null && (leftButtonParams.hasDefaultIcon() || leftButtonParams.hasCustomIcon());
168 168
     }
169 169
 
170 170
     private void createAndSetLeftButton(TitleBarLeftButtonParams leftButtonParams,