Procházet zdrojové kódy

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

Guy Carmeli před 6 roky
rodič
revize
4daf9debd0
No account linked to committer's email address

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

@@ -33,11 +33,22 @@ public class TopBarButtons {
33 33
     @Nullable public ArrayList<Button> right;
34 34
 
35 35
     void mergeWith(TopBarButtons other) {
36
-        if (other.left != null) left = other.left;
36
+        if (other.left != null) left = mergeLeftButton(other.left);
37 37
         if (other.right != null) right = other.right;
38 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 52
     void mergeWithDefault(TopBarButtons defaultOptions) {
42 53
         if (left == null) {
43 54
             left = defaultOptions.left;
@@ -55,4 +66,8 @@ public class TopBarButtons {
55 66
         }
56 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 Zobrazit soubor

@@ -17,7 +17,7 @@ import org.json.JSONObject;
17 17
 import java.util.ArrayList;
18 18
 
19 19
 public class Button {
20
-    public String id;
20
+    @Nullable public String id;
21 21
     public Text text = new NullText();
22 22
     public Bool enabled = new NullBool();
23 23
     public Bool disableIconTint = new NullBool();
@@ -105,6 +105,21 @@ public class Button {
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 123
     public void mergeWithDefault(Button defaultOptions) {
109 124
         if (!text.hasValue()) text = defaultOptions.text;
110 125
         if (!enabled.hasValue()) enabled = defaultOptions.enabled;

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java Zobrazit soubor

@@ -127,7 +127,7 @@ public class StackOptionsPresenter {
127 127
     private void applyButtons(TopBarButtons buttons) {
128 128
         topBar.setLeftButtons(buttons.left);
129 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 133
     private void applyTopTabsOptions(TopTabsOptions options) {