Explorar el Código

Custom left button fixes (#1205)

* navBarButtonColor was not applied to custom initial left button
* Dynamic custom button didn’t work
* Setting default icon (like menu or back button) after a custom icon was used didn’t work
Guy Carmeli hace 7 años
padre
commit
8dcc6d2096

+ 18
- 3
android/app/src/main/java/com/reactnativenavigation/views/LeftButton.java Ver fichero

@@ -34,16 +34,20 @@ class LeftButton extends MaterialMenuDrawable implements View.OnClickListener {
34 34
         this.navigatorEventId = navigatorEventId;
35 35
         this.overrideBackPressInJs = overrideBackPressInJs;
36 36
         setInitialState();
37
+        setColor();
37 38
     }
38 39
 
39 40
     void setIconState(TitleBarLeftButtonParams params) {
40 41
         this.params = params;
41
-        if (params.color.hasColor()) {
42
-            setColor(params.color.getColor());
43
-        }
42
+        setColor();
44 43
         animateIconState(params.iconState);
45 44
     }
46 45
 
46
+    void setCustomIcon(TitleBarLeftButtonParams params) {
47
+        this.params = params;
48
+        setColor();
49
+    }
50
+
47 51
     @Override
48 52
     public void onClick(View v) {
49 53
         if (isBackButton()) {
@@ -73,6 +77,17 @@ class LeftButton extends MaterialMenuDrawable implements View.OnClickListener {
73 77
         }
74 78
     }
75 79
 
80
+    private void setColor() {
81
+        if (!params.color.hasColor()) {
82
+            return;
83
+        }
84
+        if (params.hasDefaultIcon()) {
85
+            setColor(params.color.getColor());
86
+        } else if (params.hasCustomIcon()) {
87
+            ViewUtils.tintDrawable(params.icon, params.color.getColor(), true);
88
+        }
89
+    }
90
+
76 91
     @Override
77 92
     public void setColor(int color) {
78 93
         if (params.hasDefaultIcon()) {

+ 9
- 3
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java Ver fichero

@@ -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.hasDefaultIcon()) {
64
+            if (leftButtonParams.hasDefaultIcon() || leftButtonParams.hasCustomIcon()) {
65 65
                 updateLeftButton(leftButtonParams);
66 66
             } else {
67 67
                 removeLeftButton();
@@ -160,7 +160,13 @@ public class TitleBar extends Toolbar {
160 160
     }
161 161
 
162 162
     private void updateLeftButton(TitleBarLeftButtonParams leftButtonParams) {
163
-        leftButton.setIconState(leftButtonParams);
163
+        if (leftButtonParams.hasDefaultIcon()) {
164
+            leftButton.setIconState(leftButtonParams);
165
+            setNavigationIcon(leftButton);
166
+        } else if (leftButtonParams.hasCustomIcon()) {
167
+            leftButton.setCustomIcon(leftButtonParams);
168
+            setNavigationIcon(leftButtonParams.icon);
169
+        }
164 170
     }
165 171
 
166 172
     private boolean shouldSetLeftButton(TitleBarLeftButtonParams leftButtonParams) {
@@ -175,7 +181,7 @@ public class TitleBar extends Toolbar {
175 181
                 overrideBackPressInJs);
176 182
         setNavigationOnClickListener(leftButton);
177 183
 
178
-        if (leftButtonParams.icon != null) {
184
+        if (leftButtonParams.hasCustomIcon()) {
179 185
             setNavigationIcon(leftButtonParams.icon);
180 186
         } else {
181 187
             setNavigationIcon(leftButton);