Browse Source

Dont set back button if leftButton is decalred dynamically (#3630)

Guy Carmeli 6 years ago
parent
commit
4daf9debd0
No account linked to committer's email address

+ 16
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarButtons.java View File

33
     @Nullable public ArrayList<Button> right;
33
     @Nullable public ArrayList<Button> right;
34
 
34
 
35
     void mergeWith(TopBarButtons other) {
35
     void mergeWith(TopBarButtons other) {
36
-        if (other.left != null) left = other.left;
36
+        if (other.left != null) left = mergeLeftButton(other.left);
37
         if (other.right != null) right = other.right;
37
         if (other.right != null) right = other.right;
38
         back.mergeWith(other.back);
38
         back.mergeWith(other.back);
39
     }
39
     }
40
 
40
 
41
+    private ArrayList<Button> mergeLeftButton(ArrayList<Button> other) {
42
+        if (!other.isEmpty() && !CollectionUtils.isNullOrEmpty(left)) {
43
+            Button otherLeft = other.get(0);
44
+            if (otherLeft.id == null) {
45
+                left.get(0).mergeWith(otherLeft);
46
+                return left;
47
+            }
48
+        }
49
+        return other;
50
+    }
51
+
41
     void mergeWithDefault(TopBarButtons defaultOptions) {
52
     void mergeWithDefault(TopBarButtons defaultOptions) {
42
         if (left == null) {
53
         if (left == null) {
43
             left = defaultOptions.left;
54
             left = defaultOptions.left;
55
         }
66
         }
56
         back.mergeWithDefault(defaultOptions.back);
67
         back.mergeWithDefault(defaultOptions.back);
57
     }
68
     }
69
+
70
+    public boolean hasLeftButtons() {
71
+        return !CollectionUtils.isNullOrEmpty(left) && left.get(0).id != null;
72
+    }
58
 }
73
 }

+ 16
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Button.java View File

17
 import java.util.ArrayList;
17
 import java.util.ArrayList;
18
 
18
 
19
 public class Button {
19
 public class Button {
20
-    public String id;
20
+    @Nullable public String id;
21
     public Text text = new NullText();
21
     public Text text = new NullText();
22
     public Bool enabled = new NullBool();
22
     public Bool enabled = new NullBool();
23
     public Bool disableIconTint = new NullBool();
23
     public Bool disableIconTint = new NullBool();
105
         }
105
         }
106
     }
106
     }
107
 
107
 
108
+    public void mergeWith(Button other) {
109
+        if (other.text.hasValue()) text = other.text;
110
+        if (other.enabled.hasValue()) enabled = other.enabled;
111
+        if (other.disableIconTint.hasValue()) disableIconTint = other.disableIconTint;
112
+        if (other.color.hasValue()) color = other.color;
113
+        if (other.disabledColor.hasValue()) disabledColor = other.disabledColor;
114
+        if (other.fontSize.hasValue()) fontSize = other.fontSize;
115
+        if (other.fontFamily != null) fontFamily = other.fontFamily;
116
+        if (other.fontWeight.hasValue()) fontWeight = other.fontWeight;
117
+        if (other.testId.hasValue()) testId = other.testId;
118
+        if (other.component.hasValue()) component = other.component;
119
+        if (other.showAsAction.hasValue()) showAsAction = other.showAsAction;
120
+        if (other.icon.hasValue()) icon = other.icon;
121
+    }
122
+
108
     public void mergeWithDefault(Button defaultOptions) {
123
     public void mergeWithDefault(Button defaultOptions) {
109
         if (!text.hasValue()) text = defaultOptions.text;
124
         if (!text.hasValue()) text = defaultOptions.text;
110
         if (!enabled.hasValue()) enabled = defaultOptions.enabled;
125
         if (!enabled.hasValue()) enabled = defaultOptions.enabled;

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java View File

127
     private void applyButtons(TopBarButtons buttons) {
127
     private void applyButtons(TopBarButtons buttons) {
128
         topBar.setLeftButtons(buttons.left);
128
         topBar.setLeftButtons(buttons.left);
129
         topBar.setRightButtons(buttons.right);
129
         topBar.setRightButtons(buttons.right);
130
-        if (buttons.back.visible.isTrue()) topBar.setBackButton(buttons.back);
130
+        if (buttons.back.visible.isTrue() && !buttons.hasLeftButtons()) topBar.setBackButton(buttons.back);
131
     }
131
     }
132
 
132
 
133
     private void applyTopTabsOptions(TopTabsOptions options) {
133
     private void applyTopTabsOptions(TopTabsOptions options) {