Browse Source

Don't set left button if not needed

Guy Carmeli 8 years ago
parent
commit
09b1cad778

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

@@ -45,13 +45,25 @@ public class TitleBar extends Toolbar {
45 45
 
46 46
     public void setLeftButton(TitleBarLeftButtonParams leftButtonParams,
47 47
                                TitleBarBackButtonListener titleBarBackButtonListener, String navigatorEventId) {
48
-        if (leftButton == null) {
48
+        if (shouldSetLeftButton(leftButtonParams)) {
49 49
             createAndSetLeftButton(leftButtonParams, titleBarBackButtonListener, navigatorEventId);
50
-        } else {
51
-            leftButton.setIconState(leftButtonParams);
50
+        } else if (hasLeftButton()) {
51
+            updateLeftButton(leftButtonParams);
52 52
         }
53 53
     }
54 54
 
55
+    private boolean hasLeftButton() {
56
+        return leftButton != null;
57
+    }
58
+
59
+    private void updateLeftButton(TitleBarLeftButtonParams leftButtonParams) {
60
+        leftButton.setIconState(leftButtonParams);
61
+    }
62
+
63
+    private boolean shouldSetLeftButton(TitleBarLeftButtonParams leftButtonParams) {
64
+        return leftButton == null && leftButtonParams != null;
65
+    }
66
+
55 67
     private void createAndSetLeftButton(TitleBarLeftButtonParams leftButtonParams, TitleBarBackButtonListener titleBarBackButtonListener, String navigatorEventId) {
56 68
         leftButton = new LeftButton(getContext(), leftButtonParams, titleBarBackButtonListener, navigatorEventId);
57 69
         setNavigationOnClickListener(leftButton);