Browse Source

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 7 years ago
parent
commit
8dcc6d2096

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

34
         this.navigatorEventId = navigatorEventId;
34
         this.navigatorEventId = navigatorEventId;
35
         this.overrideBackPressInJs = overrideBackPressInJs;
35
         this.overrideBackPressInJs = overrideBackPressInJs;
36
         setInitialState();
36
         setInitialState();
37
+        setColor();
37
     }
38
     }
38
 
39
 
39
     void setIconState(TitleBarLeftButtonParams params) {
40
     void setIconState(TitleBarLeftButtonParams params) {
40
         this.params = params;
41
         this.params = params;
41
-        if (params.color.hasColor()) {
42
-            setColor(params.color.getColor());
43
-        }
42
+        setColor();
44
         animateIconState(params.iconState);
43
         animateIconState(params.iconState);
45
     }
44
     }
46
 
45
 
46
+    void setCustomIcon(TitleBarLeftButtonParams params) {
47
+        this.params = params;
48
+        setColor();
49
+    }
50
+
47
     @Override
51
     @Override
48
     public void onClick(View v) {
52
     public void onClick(View v) {
49
         if (isBackButton()) {
53
         if (isBackButton()) {
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
     @Override
91
     @Override
77
     public void setColor(int color) {
92
     public void setColor(int color) {
78
         if (params.hasDefaultIcon()) {
93
         if (params.hasDefaultIcon()) {

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

61
         if (shouldSetLeftButton(leftButtonParams)) {
61
         if (shouldSetLeftButton(leftButtonParams)) {
62
             createAndSetLeftButton(leftButtonParams, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
62
             createAndSetLeftButton(leftButtonParams, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
63
         } else if (hasLeftButton()) {
63
         } else if (hasLeftButton()) {
64
-            if (leftButtonParams.hasDefaultIcon()) {
64
+            if (leftButtonParams.hasDefaultIcon() || leftButtonParams.hasCustomIcon()) {
65
                 updateLeftButton(leftButtonParams);
65
                 updateLeftButton(leftButtonParams);
66
             } else {
66
             } else {
67
                 removeLeftButton();
67
                 removeLeftButton();
160
     }
160
     }
161
 
161
 
162
     private void updateLeftButton(TitleBarLeftButtonParams leftButtonParams) {
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
     private boolean shouldSetLeftButton(TitleBarLeftButtonParams leftButtonParams) {
172
     private boolean shouldSetLeftButton(TitleBarLeftButtonParams leftButtonParams) {
175
                 overrideBackPressInJs);
181
                 overrideBackPressInJs);
176
         setNavigationOnClickListener(leftButton);
182
         setNavigationOnClickListener(leftButton);
177
 
183
 
178
-        if (leftButtonParams.icon != null) {
184
+        if (leftButtonParams.hasCustomIcon()) {
179
             setNavigationIcon(leftButtonParams.icon);
185
             setNavigationIcon(leftButtonParams.icon);
180
         } else {
186
         } else {
181
             setNavigationIcon(leftButton);
187
             setNavigationIcon(leftButton);