Selaa lähdekoodia

Introduce Bool instead of BooleanOptions

* Fix Options.copy
* Screens are now by default drawBehind: false
Guy Carmeli 6 vuotta sitten
vanhempi
commit
19146a0911

+ 12
- 11
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabsOptions.java Näytä tiedosto

@@ -1,7 +1,8 @@
1 1
 package com.reactnativenavigation.parse;
2 2
 
3
-
4
-import com.reactnativenavigation.parse.Options.BooleanOptions;
3
+import com.reactnativenavigation.parse.params.Bool;
4
+import com.reactnativenavigation.parse.params.NullBool;
5
+import com.reactnativenavigation.parse.parsers.BoolParser;
5 6
 
6 7
 import org.json.JSONObject;
7 8
 
@@ -15,17 +16,17 @@ public class BottomTabsOptions implements DEFAULT_VALUES {
15 16
         options.selectedColor = ColorParser.parse(json, "selectedTabColor");
16 17
         options.currentTabId = TextParser.parse(json, "currentTabId");
17 18
 		options.currentTabIndex = json.optInt("currentTabIndex", NO_INT_VALUE);
18
-		options.visible = BooleanOptions.parse(json.optString("visible"));
19
-		options.animateHide = BooleanOptions.parse(json.optString("animateHide"));
19
+		options.visible = BoolParser.parse(json,"visible");
20
+		options.animateHide = BoolParser.parse(json,"animateHide");
20 21
         options.testId = TextParser.parse(json, "testID");
21 22
 
22 23
 		return options;
23 24
 	}
24 25
 
25 26
     public Color color = new NullColor();
26
-    public Color selectedColor = new NullColor();
27
-	BooleanOptions visible = BooleanOptions.False;
28
-	BooleanOptions animateHide = BooleanOptions.False;
27
+    private Color selectedColor = new NullColor();
28
+	Bool visible = new NullBool();
29
+	Bool animateHide = new NullBool();
29 30
 	public int currentTabIndex = NO_INT_VALUE;
30 31
 	public Text currentTabId = new NullText();
31 32
     public Text testId = new NullText();
@@ -37,10 +38,10 @@ public class BottomTabsOptions implements DEFAULT_VALUES {
37 38
 		if (NO_INT_VALUE != other.currentTabIndex) {
38 39
             currentTabIndex = other.currentTabIndex;
39 40
 		}
40
-		if (other.visible != BooleanOptions.NoValue) {
41
+		if (other.visible.hasValue()) {
41 42
 			visible = other.visible;
42 43
 		}
43
-		if (other.animateHide != BooleanOptions.NoValue) {
44
+		if (other.animateHide.hasValue()) {
44 45
 			animateHide = other.animateHide;
45 46
 		}
46 47
         if (other.color.hasValue()) {
@@ -58,10 +59,10 @@ public class BottomTabsOptions implements DEFAULT_VALUES {
58 59
         if (NO_INT_VALUE == currentTabIndex) {
59 60
             currentTabIndex = defaultOptions.currentTabIndex;
60 61
         }
61
-        if (visible == BooleanOptions.NoValue) {
62
+        if (!visible.hasValue()) {
62 63
             visible = defaultOptions.visible;
63 64
         }
64
-        if (animateHide == BooleanOptions.NoValue) {
65
+        if (!animateHide.hasValue()) {
65 66
             animateHide = defaultOptions.animateHide;
66 67
         }
67 68
         if (!color.hasValue()) {

+ 8
- 5
lib/android/app/src/main/java/com/reactnativenavigation/parse/Button.java Näytä tiedosto

@@ -3,6 +3,9 @@ package com.reactnativenavigation.parse;
3 3
 import android.support.annotation.ColorInt;
4 4
 import android.view.MenuItem;
5 5
 
6
+import com.reactnativenavigation.parse.params.Bool;
7
+import com.reactnativenavigation.parse.parsers.BoolParser;
8
+
6 9
 import org.json.JSONArray;
7 10
 import org.json.JSONObject;
8 11
 
@@ -13,12 +16,12 @@ import static com.reactnativenavigation.parse.Options.NO_INT_VALUE;
13 16
 public class Button {
14 17
 	public String id;
15 18
 	public Text title;
16
-	public Options.BooleanOptions disabled;
17
-	public Options.BooleanOptions disableIconTint;
19
+	public Bool disabled;
20
+	public Bool disableIconTint;
18 21
 	public int showAsAction;
19 22
 	@ColorInt public int buttonColor;
20 23
 	public int buttonFontSize;
21
-	public Text buttonFontWeight;
24
+	private Text buttonFontWeight;
22 25
 	public Text icon = new NullText();
23 26
 	public Text testId;
24 27
 
@@ -26,8 +29,8 @@ public class Button {
26 29
 		Button button = new Button();
27 30
 		button.id = json.optString("id");
28 31
 		button.title = TextParser.parse(json, "title");
29
-		button.disabled = Options.BooleanOptions.parse(json.optString("disabled", ""));
30
-		button.disableIconTint = Options.BooleanOptions.parse(json.optString("disableIconTint", ""));
32
+		button.disabled = BoolParser.parse(json,"disabled");
33
+		button.disableIconTint = BoolParser.parse(json,"disableIconTint");
31 34
 		button.showAsAction = parseShowAsAction(json);
32 35
 		button.buttonColor = json.optInt("buttonColor", NO_INT_VALUE);
33 36
 		button.buttonFontSize = json.optInt("buttonFontSize", NO_INT_VALUE);

+ 8
- 16
lib/android/app/src/main/java/com/reactnativenavigation/parse/Options.java Näytä tiedosto

@@ -2,7 +2,6 @@ package com.reactnativenavigation.parse;
2 2
 
3 3
 import android.support.annotation.CheckResult;
4 4
 import android.support.annotation.NonNull;
5
-import android.text.TextUtils;
6 5
 
7 6
 import com.reactnativenavigation.utils.TypefaceLoader;
8 7
 
@@ -10,19 +9,6 @@ import org.json.JSONObject;
10 9
 
11 10
 public class Options implements DEFAULT_VALUES {
12 11
 
13
-    public enum BooleanOptions {
14
-		True,
15
-		False,
16
-		NoValue;
17
-
18
-		static BooleanOptions parse(String value) {
19
-			if (!TextUtils.isEmpty(value)) {
20
-				return Boolean.valueOf(value) ? True : False;
21
-			}
22
-			return NoValue;
23
-		}
24
-	}
25
-
26 12
     @NonNull
27 13
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {
28 14
         return parse(typefaceManager, json, new Options());
@@ -56,12 +42,18 @@ public class Options implements DEFAULT_VALUES {
56 42
 
57 43
     @CheckResult
58 44
     public Options copy() {
59
-        return new Options().mergeWith(this);
45
+        Options result = new Options();
46
+        result.topBarOptions.mergeWith(topBarOptions);
47
+        result.topTabsOptions.mergeWith(topTabsOptions);
48
+        result.topTabOptions.mergeWith(topTabOptions);
49
+        result.bottomTabOptions.mergeWith(bottomTabOptions);
50
+        result.bottomTabsOptions.mergeWith(bottomTabsOptions);
51
+        return result;
60 52
     }
61 53
 
62 54
     @CheckResult
63 55
 	public Options mergeWith(final Options other) {
64
-        Options result = new Options();
56
+        Options result = copy();
65 57
         result.topBarOptions.mergeWith(other.topBarOptions);
66 58
         result.topTabsOptions.mergeWith(other.topTabsOptions);
67 59
         result.topTabOptions.mergeWith(other.topTabOptions);

+ 6
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/OverlayOptions.java Näytä tiedosto

@@ -1,15 +1,19 @@
1 1
 package com.reactnativenavigation.parse;
2 2
 
3
+import com.reactnativenavigation.parse.params.Bool;
4
+import com.reactnativenavigation.parse.params.NullBool;
5
+import com.reactnativenavigation.parse.parsers.BoolParser;
6
+
3 7
 import org.json.JSONObject;
4 8
 
5 9
 public class OverlayOptions {
6
-    public Options.BooleanOptions interceptTouchOutside = Options.BooleanOptions.False;
10
+    public Bool interceptTouchOutside = new NullBool();
7 11
 
8 12
     public static OverlayOptions parse(JSONObject json) {
9 13
         OverlayOptions options = new OverlayOptions();
10 14
         if (json == null) return options;
11 15
 
12
-        options.interceptTouchOutside = Options.BooleanOptions.parse(json.optString("interceptTouchOutside", ""));
16
+        options.interceptTouchOutside = BoolParser.parse(json,"interceptTouchOutside");
13 17
         return options;
14 18
     }
15 19
 }

+ 21
- 17
lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarOptions.java Näytä tiedosto

@@ -4,6 +4,9 @@ package com.reactnativenavigation.parse;
4 4
 import android.graphics.Typeface;
5 5
 import android.support.annotation.Nullable;
6 6
 
7
+import com.reactnativenavigation.parse.params.Bool;
8
+import com.reactnativenavigation.parse.params.NullBool;
9
+import com.reactnativenavigation.parse.parsers.BoolParser;
7 10
 import com.reactnativenavigation.utils.TypefaceLoader;
8 11
 
9 12
 import org.json.JSONObject;
@@ -21,10 +24,10 @@ public class TopBarOptions implements DEFAULT_VALUES {
21 24
         options.textColor = ColorParser.parse(json, "textColor");
22 25
         options.textFontSize = FractionParser.parse(json, "textFontSize");
23 26
         options.textFontFamily = typefaceManager.getTypeFace(json.optString("textFontFamily", ""));
24
-        options.hidden = Options.BooleanOptions.parse(json.optString("hidden", "false"));
25
-        options.animateHide = Options.BooleanOptions.parse(json.optString("animateHide", "true"));
26
-        options.hideOnScroll = Options.BooleanOptions.parse(json.optString("hideOnScroll"));
27
-        options.drawBehind = Options.BooleanOptions.parse(json.optString("drawBehind"));
27
+        options.hidden = BoolParser.parse(json, "hidden");
28
+        options.animateHide = BoolParser.parse(json,"animateHide");
29
+        options.hideOnScroll = BoolParser.parse(json,"hideOnScroll");
30
+        options.drawBehind = BoolParser.parse(json,"drawBehind");
28 31
         options.rightButtons = Button.parseJsonArray(json.optJSONArray("rightButtons"));
29 32
         options.leftButtons = Button.parseJsonArray(json.optJSONArray("leftButtons"));
30 33
         options.testId = TextParser.parse(json, "testID");
@@ -38,15 +41,16 @@ public class TopBarOptions implements DEFAULT_VALUES {
38 41
     public Color textColor = new NullColor();
39 42
     public Fraction textFontSize = new NullFraction();
40 43
     @Nullable public Typeface textFontFamily;
41
-    public Options.BooleanOptions hidden = Options.BooleanOptions.False;
42
-    public Options.BooleanOptions animateHide = Options.BooleanOptions.True;
43
-    public Options.BooleanOptions hideOnScroll = Options.BooleanOptions.NoValue;
44
-    public Options.BooleanOptions drawBehind = Options.BooleanOptions.NoValue;
44
+    public Bool hidden = new NullBool();
45
+    public Bool animateHide = new NullBool();
46
+    public Bool hideOnScroll = new NullBool();
47
+    public Bool drawBehind = new NullBool();
45 48
     public ArrayList<Button> leftButtons;
46 49
     public ArrayList<Button> rightButtons;
47 50
 
48 51
     void mergeWith(final TopBarOptions other) {
49
-        if (other.title != null) title = other.title;
52
+        if (other.title.hasValue())
53
+            title = other.title;
50 54
         if (other.backgroundColor.hasValue())
51 55
             backgroundColor = other.backgroundColor;
52 56
         if (other.textColor.hasValue())
@@ -55,16 +59,16 @@ public class TopBarOptions implements DEFAULT_VALUES {
55 59
             textFontSize = other.textFontSize;
56 60
         if (other.textFontFamily != null)
57 61
             textFontFamily = other.textFontFamily;
58
-        if (other.hidden != Options.BooleanOptions.NoValue) {
62
+        if (other.hidden.hasValue()) {
59 63
             hidden = other.hidden;
60 64
         }
61
-        if (other.animateHide != Options.BooleanOptions.NoValue) {
65
+        if (other.animateHide.hasValue()) {
62 66
             animateHide = other.animateHide;
63 67
         }
64
-        if (other.hideOnScroll != Options.BooleanOptions.NoValue) {
68
+        if (other.hideOnScroll.hasValue()) {
65 69
             hideOnScroll = other.hideOnScroll;
66 70
         }
67
-        if (other.drawBehind != Options.BooleanOptions.NoValue) {
71
+        if (other.drawBehind.hasValue()) {
68 72
             drawBehind = other.drawBehind;
69 73
         }
70 74
         if (other.leftButtons != null)
@@ -84,13 +88,13 @@ public class TopBarOptions implements DEFAULT_VALUES {
84 88
             textFontSize = defaultOptions.textFontSize;
85 89
         if (textFontFamily == null)
86 90
             textFontFamily = defaultOptions.textFontFamily;
87
-        if (hidden == Options.BooleanOptions.NoValue)
91
+        if (!hidden.hasValue())
88 92
             hidden = defaultOptions.hidden;
89
-        if (animateHide == Options.BooleanOptions.NoValue)
93
+        if (!animateHide.hasValue())
90 94
             animateHide = defaultOptions.animateHide;
91
-        if (hideOnScroll == Options.BooleanOptions.NoValue)
95
+        if (!hideOnScroll.hasValue())
92 96
             hideOnScroll = defaultOptions.hideOnScroll;
93
-        if (drawBehind == Options.BooleanOptions.NoValue)
97
+        if (!drawBehind.hasValue())
94 98
             drawBehind = defaultOptions.drawBehind;
95 99
         if (leftButtons == null)
96 100
             leftButtons = defaultOptions.leftButtons;

+ 25
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Bool.java Näytä tiedosto

@@ -0,0 +1,25 @@
1
+package com.reactnativenavigation.parse.params;
2
+
3
+import com.reactnativenavigation.parse.Param;
4
+
5
+public class Bool extends Param<Boolean> {
6
+    public Bool(Boolean value) {
7
+        super(value);
8
+    }
9
+
10
+    public boolean isFalseOrUndefined() {
11
+        return !hasValue() || !get();
12
+    }
13
+
14
+    public boolean isTrueOrUndefined() {
15
+        return !hasValue() || get();
16
+    }
17
+
18
+    public boolean isTrue() {
19
+        return hasValue() && get();
20
+    }
21
+
22
+    public boolean isFalse() {
23
+        return hasValue() && get();
24
+    }
25
+}

+ 7
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/params/NullBool.java Näytä tiedosto

@@ -0,0 +1,7 @@
1
+package com.reactnativenavigation.parse.params;
2
+
3
+public class NullBool extends Bool {
4
+    public NullBool() {
5
+        super(null);
6
+    }
7
+}

+ 12
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/parsers/BoolParser.java Näytä tiedosto

@@ -0,0 +1,12 @@
1
+package com.reactnativenavigation.parse.parsers;
2
+
3
+import com.reactnativenavigation.parse.params.Bool;
4
+import com.reactnativenavigation.parse.params.NullBool;
5
+
6
+import org.json.JSONObject;
7
+
8
+public class BoolParser {
9
+    public static Bool parse(JSONObject json, String bool) {
10
+        return json.has(bool) ? new Bool(json.optBoolean(bool)) : new NullBool();
11
+    }
12
+}

+ 6
- 9
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java Näytä tiedosto

@@ -10,9 +10,6 @@ import com.reactnativenavigation.views.TopBar;
10 10
 
11 11
 import java.util.ArrayList;
12 12
 
13
-import static com.reactnativenavigation.parse.Options.BooleanOptions.False;
14
-import static com.reactnativenavigation.parse.Options.BooleanOptions.True;
15
-
16 13
 public class OptionsPresenter {
17 14
     private TopBar topBar;
18 15
     private ReactComponent component;
@@ -37,21 +34,21 @@ public class OptionsPresenter {
37 34
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
38 35
 
39 36
         topBar.setTitleTypeface(options.textFontFamily);
40
-        if (options.hidden == True) {
37
+        if (options.hidden.isTrue()) {
41 38
             topBar.hide(options.animateHide);
42 39
         }
43
-        if (options.hidden == False) {
40
+        if (options.hidden.isFalseOrUndefined()) {
44 41
             topBar.show(options.animateHide);
45 42
         }
46
-        if (options.drawBehind == True) {
43
+        if (options.drawBehind.isTrue()) {
47 44
             component.drawBehindTopBar();
48
-        } else if (options.drawBehind == False) {
45
+        } else if (options.drawBehind.isFalseOrUndefined()) {
49 46
             component.drawBelowTopBar(topBar);
50 47
         }
51 48
 
52
-        if (options.hideOnScroll == True) {
49
+        if (options.hideOnScroll.isTrue()) {
53 50
             topBar.enableCollapse(component.getScrollEventListener());
54
-        } else if (options.hideOnScroll == False) {
51
+        } else if (options.hideOnScroll.isTrue()) {
55 52
             topBar.disableCollapse();
56 53
         }
57 54
     }

+ 12
- 7
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java Näytä tiedosto

@@ -25,6 +25,7 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, Titl
25 25
 		super(context);
26 26
 		this.reactView = reactView;
27 27
         addView(reactView.asView(), MATCH_PARENT, MATCH_PARENT);
28
+        setContentDescription("ComponentLayout");
28 29
         touchDelegate = new OverlayTouchDelegate(reactView);
29 30
     }
30 31
 
@@ -55,7 +56,7 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, Titl
55 56
 
56 57
     @Override
57 58
     public void applyOptions(Options options) {
58
-        touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside == Options.BooleanOptions.True);
59
+        touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside.isTrue());
59 60
     }
60 61
 
61 62
     @Override
@@ -75,16 +76,20 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, Titl
75 76
 
76 77
     @Override
77 78
     public void drawBehindTopBar() {
78
-        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
79
-        layoutParams.removeRule(BELOW);
80
-        setLayoutParams(layoutParams);
79
+        if (getParent() instanceof RelativeLayout) {
80
+            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
81
+            layoutParams.removeRule(BELOW);
82
+            setLayoutParams(layoutParams);
83
+        }
81 84
     }
82 85
 
83 86
     @Override
84 87
     public void drawBelowTopBar(TopBar topBar) {
85
-        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
86
-        layoutParams.addRule(BELOW, topBar.getId());
87
-        setLayoutParams(layoutParams);
88
+        if (getParent() instanceof RelativeLayout) {
89
+            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
90
+            layoutParams.addRule(BELOW, topBar.getId());
91
+            setLayoutParams(layoutParams);
92
+        }
88 93
     }
89 94
 
90 95
     @Override

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java Näytä tiedosto

@@ -21,6 +21,7 @@ public class StackLayout extends RelativeLayout implements TitleBarButton.OnClic
21 21
         topBar = new TopBar(context, this);
22 22
         topBar.setId(CompatUtils.generateViewId());
23 23
         createLayout();
24
+        setContentDescription("StackLayout");
24 25
     }
25 26
 
26 27
     void createLayout() {

+ 3
- 4
lib/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java Näytä tiedosto

@@ -17,7 +17,6 @@ import android.widget.ImageButton;
17 17
 import android.widget.TextView;
18 18
 
19 19
 import com.reactnativenavigation.parse.Button;
20
-import com.reactnativenavigation.parse.Options;
21 20
 import com.reactnativenavigation.parse.Text;
22 21
 import com.reactnativenavigation.utils.ArrayUtils;
23 22
 import com.reactnativenavigation.utils.ImageLoader;
@@ -46,7 +45,7 @@ public class TitleBarButton implements MenuItem.OnMenuItemClickListener {
46 45
 	void addToMenu(Context context, final Menu menu) {
47 46
 		MenuItem menuItem = menu.add(button.title.get(""));
48 47
 		menuItem.setShowAsAction(button.showAsAction);
49
-		menuItem.setEnabled(button.disabled != Options.BooleanOptions.True);
48
+		menuItem.setEnabled(button.disabled.isFalseOrUndefined());
50 49
 		menuItem.setOnMenuItemClickListener(this);
51 50
 
52 51
 		if (hasIcon()) {
@@ -109,12 +108,12 @@ public class TitleBarButton implements MenuItem.OnMenuItemClickListener {
109 108
 	}
110 109
 
111 110
 	private void setIconColor() {
112
-		if (button.disabled == Options.BooleanOptions.False || button.disabled == Options.BooleanOptions.NoValue) {
111
+		if (button.disabled.isFalseOrUndefined()) {
113 112
 			UiUtils.tintDrawable(icon, button.buttonColor);
114 113
 			return;
115 114
 		}
116 115
 
117
-		if (button.disableIconTint == Options.BooleanOptions.True) {
116
+		if (button.disableIconTint.isTrue()) {
118 117
 			UiUtils.tintDrawable(icon, button.buttonColor);
119 118
 		} else {
120 119
 			UiUtils.tintDrawable(icon, Color.LTGRAY);

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Näytä tiedosto

@@ -20,7 +20,7 @@ import com.reactnativenavigation.parse.Button;
20 20
 import com.reactnativenavigation.parse.Color;
21 21
 import com.reactnativenavigation.parse.Fraction;
22 22
 import com.reactnativenavigation.parse.Number;
23
-import com.reactnativenavigation.parse.Options;
23
+import com.reactnativenavigation.parse.params.Bool;
24 24
 
25 25
 import java.util.ArrayList;
26 26
 
@@ -169,22 +169,22 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
169 169
         collapsingBehavior.disableCollapse();
170 170
     }
171 171
 
172
-    public void show(Options.BooleanOptions animated) {
172
+    public void show(Bool animated) {
173 173
         if (getVisibility() == View.VISIBLE) {
174 174
             return;
175 175
         }
176
-        if (animated == Options.BooleanOptions.True) {
176
+        if (animated.isTrue()) {
177 177
             animator.show();
178 178
         } else {
179 179
             setVisibility(View.VISIBLE);
180 180
         }
181 181
     }
182 182
 
183
-    public void hide(Options.BooleanOptions animated) {
183
+    public void hide(Bool animated) {
184 184
         if (getVisibility() == View.GONE) {
185 185
             return;
186 186
         }
187
-        if (animated == Options.BooleanOptions.True) {
187
+        if (animated.isTrue()) {
188 188
             animator.hide();
189 189
         } else {
190 190
             setVisibility(View.GONE);

+ 28
- 25
lib/android/app/src/test/java/com/reactnativenavigation/parse/OptionsTest.java Näytä tiedosto

@@ -5,13 +5,13 @@ import android.support.annotation.*;
5 5
 
6 6
 import com.reactnativenavigation.*;
7 7
 import com.reactnativenavigation.mocks.*;
8
+import com.reactnativenavigation.parse.params.Bool;
8 9
 import com.reactnativenavigation.utils.*;
9 10
 
10 11
 import org.json.*;
11 12
 import org.junit.*;
12 13
 import org.mockito.*;
13 14
 
14
-import static com.reactnativenavigation.parse.Options.BooleanOptions.*;
15 15
 import static org.assertj.core.api.Java6Assertions.*;
16 16
 
17 17
 public class OptionsTest extends BaseTest {
@@ -22,11 +22,11 @@ public class OptionsTest extends BaseTest {
22 22
     private static final int TOP_BAR_FONT_SIZE = 18;
23 23
     private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
24 24
     private static final Typeface TOP_BAR_TYPEFACE = Typeface.create("HelveticaNeue-CondensedBold", Typeface.BOLD);
25
-    private static final Options.BooleanOptions TOP_BAR_HIDDEN = True;
26
-    private static final Options.BooleanOptions TOP_BAR_DRAW_BEHIND = True;
27
-    private static final Options.BooleanOptions TOP_BAR_HIDE_ON_SCROLL = True;
28
-    private static final Options.BooleanOptions BOTTOM_TABS_ANIMATE_HIDE = True;
29
-    private static final Options.BooleanOptions BOTTOM_TABS_HIDDEN = True;
25
+    private static final Bool TOP_BAR_HIDDEN = new Bool(true);
26
+    private static final Bool TOP_BAR_DRAW_BEHIND = new Bool(true);
27
+    private static final Bool TOP_BAR_HIDE_ON_SCROLL = new Bool(true);
28
+    private static final Bool BOTTOM_TABS_ANIMATE_HIDE = new Bool(true);
29
+    private static final Bool BOTTOM_TABS_HIDDEN = new Bool(true);
30 30
     private static final String BOTTOM_TABS_BADGE = "3";
31 31
     private static final String BOTTOM_TABS_CURRENT_TAB_ID = "ComponentId";
32 32
     private static final int BOTTOM_TABS_CURRENT_TAB_INDEX = 1;
@@ -46,7 +46,7 @@ public class OptionsTest extends BaseTest {
46 46
     @Test
47 47
     public void parsesJson() throws Exception {
48 48
         JSONObject json = new JSONObject()
49
-                .put("topBar", createTopBar(TOP_BAR_HIDDEN))
49
+                .put("topBar", createTopBar(TOP_BAR_HIDDEN.get()))
50 50
                 .put("bottomTabs", createBottomTabs());
51 51
         Options result = Options.parse(mockLoader, json);
52 52
         assertResult(result);
@@ -58,11 +58,11 @@ public class OptionsTest extends BaseTest {
58 58
         assertThat(result.topBarOptions.textColor.get()).isEqualTo(TOP_BAR_TEXT_COLOR);
59 59
         assertThat(result.topBarOptions.textFontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE);
60 60
         assertThat(result.topBarOptions.textFontFamily).isEqualTo(TOP_BAR_TYPEFACE);
61
-        assertThat(result.topBarOptions.hidden).isEqualTo(TOP_BAR_HIDDEN);
62
-        assertThat(result.topBarOptions.drawBehind).isEqualTo(TOP_BAR_DRAW_BEHIND);
63
-        assertThat(result.topBarOptions.hideOnScroll).isEqualTo(TOP_BAR_HIDE_ON_SCROLL);
64
-        assertThat(result.bottomTabsOptions.animateHide).isEqualTo(BOTTOM_TABS_ANIMATE_HIDE);
65
-        assertThat(result.bottomTabsOptions.visible).isEqualTo(BOTTOM_TABS_HIDDEN);
61
+        assertThat(result.topBarOptions.hidden.get()).isEqualTo(TOP_BAR_HIDDEN.get());
62
+        assertThat(result.topBarOptions.drawBehind.get()).isEqualTo(TOP_BAR_DRAW_BEHIND.get());
63
+        assertThat(result.topBarOptions.hideOnScroll.get()).isEqualTo(TOP_BAR_HIDE_ON_SCROLL.get());
64
+        assertThat(result.bottomTabsOptions.animateHide.get()).isEqualTo(BOTTOM_TABS_ANIMATE_HIDE.get());
65
+        assertThat(result.bottomTabsOptions.visible.get()).isEqualTo(BOTTOM_TABS_HIDDEN.get());
66 66
         assertThat(result.bottomTabsOptions.currentTabId.get()).isEqualTo(BOTTOM_TABS_CURRENT_TAB_ID);
67 67
         assertThat(result.bottomTabsOptions.currentTabIndex).isEqualTo(BOTTOM_TABS_CURRENT_TAB_INDEX);
68 68
     }
@@ -72,12 +72,12 @@ public class OptionsTest extends BaseTest {
72 72
         return new JSONObject()
73 73
                 .put("currentTabId", BOTTOM_TABS_CURRENT_TAB_ID)
74 74
                 .put("currentTabIndex", BOTTOM_TABS_CURRENT_TAB_INDEX)
75
-                .put("visible", BOTTOM_TABS_HIDDEN)
76
-                .put("animateHide", BOTTOM_TABS_ANIMATE_HIDE);
75
+                .put("visible", BOTTOM_TABS_HIDDEN.get())
76
+                .put("animateHide", BOTTOM_TABS_ANIMATE_HIDE.get());
77 77
     }
78 78
 
79 79
     @NonNull
80
-    private JSONObject createTopBar(Options.BooleanOptions hidden) throws JSONException {
80
+    private JSONObject createTopBar(boolean hidden) throws JSONException {
81 81
         return new JSONObject()
82 82
                 .put("title", "the title")
83 83
                 .put("backgroundColor", TOP_BAR_BACKGROUND_COLOR)
@@ -85,8 +85,8 @@ public class OptionsTest extends BaseTest {
85 85
                 .put("textFontSize", TOP_BAR_FONT_SIZE)
86 86
                 .put("textFontFamily", TOP_BAR_FONT_FAMILY)
87 87
                 .put("hidden", hidden)
88
-                .put("drawBehind", TOP_BAR_DRAW_BEHIND)
89
-                .put("hideOnScroll", TOP_BAR_HIDE_ON_SCROLL);
88
+                .put("drawBehind", TOP_BAR_DRAW_BEHIND.get())
89
+                .put("hideOnScroll", TOP_BAR_HIDE_ON_SCROLL.get());
90 90
     }
91 91
 
92 92
     @NonNull
@@ -113,23 +113,26 @@ public class OptionsTest extends BaseTest {
113 113
     @Test
114 114
     public void mergeDoesNotMutate() throws Exception {
115 115
         JSONObject json1 = new JSONObject();
116
-        json1.put("topBar", createTopBar(Options.BooleanOptions.True));
116
+        json1.put("topBar", createTopBar(true));
117 117
         Options options1 = Options.parse(mockLoader, json1);
118
+        options1.topBarOptions.title = new Text("some title");
118 119
 
119 120
 
120 121
         JSONObject json2 = new JSONObject();
121
-        json2.put("topBar", createTopBar(Options.BooleanOptions.False));
122
+        json2.put("topBar", createTopBar(false));
122 123
         Options options2 = Options.parse(mockLoader, json2);
124
+        options2.topBarOptions.title = new NullText();
123 125
 
124 126
         Options merged = options1.mergeWith(options2);
125
-        assertThat(options1.topBarOptions.hidden).isEqualTo(Options.BooleanOptions.True);
126
-        assertThat(merged.topBarOptions.hidden).isEqualTo(False);
127
+        assertThat(options1.topBarOptions.hidden.get()).isTrue();
128
+        assertThat(merged.topBarOptions.hidden.get()).isFalse();
129
+        assertThat(merged.topBarOptions.title.get()).isEqualTo("some title");
127 130
     }
128 131
 
129 132
     @Test
130 133
     public void mergeDefaultOptions() throws Exception {
131 134
         JSONObject json = new JSONObject();
132
-        json.put("topBar", createTopBar(TOP_BAR_HIDDEN));
135
+        json.put("topBar", createTopBar(TOP_BAR_HIDDEN.get()));
133 136
         json.put("bottomTabs", createBottomTabs());
134 137
         Options defaultOptions = Options.parse(mockLoader, json);
135 138
         Options options = new Options();
@@ -145,7 +148,7 @@ public class OptionsTest extends BaseTest {
145 148
         Options defaultOptions = Options.parse(mockLoader, defaultJson);
146 149
 
147 150
         JSONObject json = new JSONObject()
148
-                .put("topBar", createTopBar(TOP_BAR_HIDDEN))
151
+                .put("topBar", createTopBar(TOP_BAR_HIDDEN.get()))
149 152
                 .put("bottomTabs", createBottomTabs());
150 153
         Options options = Options.parse(mockLoader, json);
151 154
         options.withDefaultOptions(defaultOptions);
@@ -161,7 +164,7 @@ public class OptionsTest extends BaseTest {
161 164
     @Test
162 165
     public void topBar_defaultOptions() throws Exception {
163 166
         Options uut = new Options();
164
-        assertThat(uut.topBarOptions.hidden).isEqualTo(Options.BooleanOptions.False);
165
-        assertThat(uut.topBarOptions.animateHide).isEqualTo(Options.BooleanOptions.True);
167
+        assertThat(uut.topBarOptions.hidden.isFalseOrUndefined()).isTrue();
168
+        assertThat(uut.topBarOptions.animateHide.isTrueOrUndefined()).isTrue();
166 169
     }
167 170
 }

+ 5
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Näytä tiedosto

@@ -13,6 +13,7 @@ import com.reactnativenavigation.mocks.TestReactView;
13 13
 import com.reactnativenavigation.parse.Fraction;
14 14
 import com.reactnativenavigation.parse.Options;
15 15
 import com.reactnativenavigation.parse.Text;
16
+import com.reactnativenavigation.parse.params.Bool;
16 17
 
17 18
 import org.junit.Test;
18 19
 
@@ -145,7 +146,7 @@ public class OptionsApplyingTest extends BaseTest {
145 146
         assertThat(stackController.getTopBar().getVisibility()).isNotEqualTo(View.GONE);
146 147
 
147 148
         Options opts = new Options();
148
-        opts.topBarOptions.hidden = Options.BooleanOptions.True;
149
+        opts.topBarOptions.hidden = new Bool(true);
149 150
         uut.mergeOptions(opts);
150 151
 
151 152
         assertThat(stackController.getTopBar().getVisibility()).isEqualTo(View.GONE);
@@ -154,17 +155,17 @@ public class OptionsApplyingTest extends BaseTest {
154 155
     @Test
155 156
     public void appliesDrawUnder() throws Exception {
156 157
         uut.options.topBarOptions.title = new Text("the title");
157
-        uut.options.topBarOptions.drawBehind = Options.BooleanOptions.False;
158
+        uut.options.topBarOptions.drawBehind = new Bool(false);
158 159
         uut.ensureViewIsCreated();
159
-        uut.onViewAppeared();
160 160
         stackController.animatePush(uut, new MockPromise() {
161 161
             @Override
162 162
             public void resolve(@Nullable Object value) {
163
+                uut.onViewAppeared();
163 164
                 RelativeLayout.LayoutParams uutLayoutParams = (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
164 165
                 assertThat(uutLayoutParams.getRule(BELOW)).isNotEqualTo(0);
165 166
 
166 167
                 Options opts = new Options();
167
-                opts.topBarOptions.drawBehind = Options.BooleanOptions.True;
168
+                opts.topBarOptions.drawBehind = new Bool(true);
168 169
                 uut.mergeOptions(opts);
169 170
 
170 171
                 uutLayoutParams = (RelativeLayout.LayoutParams) (uut.getComponent().asView()).getLayoutParams();

+ 1
- 1
playground/src/screens/ScrollViewScreen.js Näytä tiedosto

@@ -11,6 +11,7 @@ class ScrollViewScreen extends Component {
11 11
     return {
12 12
       topBar: {
13 13
         title: 'Collapse',
14
+        drawBehind: true,
14 15
         textColor: 'black',
15 16
         textFontSize: 16
16 17
       }
@@ -46,7 +47,6 @@ class ScrollViewScreen extends Component {
46 47
   componentDidUpdate() {
47 48
     Navigation.setOptions(this.props.componentId, {
48 49
       topBar: {
49
-        drawUnder: true,
50 50
         hideOnScroll: this.state.topBarHideOnScroll
51 51
       }
52 52
     });