Browse Source

Introduce Bool instead of BooleanOptions

* Fix Options.copy
* Screens are now by default drawBehind: false
Guy Carmeli 6 years ago
parent
commit
19146a0911

+ 12
- 11
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabsOptions.java View File

1
 package com.reactnativenavigation.parse;
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
 import org.json.JSONObject;
7
 import org.json.JSONObject;
7
 
8
 
15
         options.selectedColor = ColorParser.parse(json, "selectedTabColor");
16
         options.selectedColor = ColorParser.parse(json, "selectedTabColor");
16
         options.currentTabId = TextParser.parse(json, "currentTabId");
17
         options.currentTabId = TextParser.parse(json, "currentTabId");
17
 		options.currentTabIndex = json.optInt("currentTabIndex", NO_INT_VALUE);
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
         options.testId = TextParser.parse(json, "testID");
21
         options.testId = TextParser.parse(json, "testID");
21
 
22
 
22
 		return options;
23
 		return options;
23
 	}
24
 	}
24
 
25
 
25
     public Color color = new NullColor();
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
 	public int currentTabIndex = NO_INT_VALUE;
30
 	public int currentTabIndex = NO_INT_VALUE;
30
 	public Text currentTabId = new NullText();
31
 	public Text currentTabId = new NullText();
31
     public Text testId = new NullText();
32
     public Text testId = new NullText();
37
 		if (NO_INT_VALUE != other.currentTabIndex) {
38
 		if (NO_INT_VALUE != other.currentTabIndex) {
38
             currentTabIndex = other.currentTabIndex;
39
             currentTabIndex = other.currentTabIndex;
39
 		}
40
 		}
40
-		if (other.visible != BooleanOptions.NoValue) {
41
+		if (other.visible.hasValue()) {
41
 			visible = other.visible;
42
 			visible = other.visible;
42
 		}
43
 		}
43
-		if (other.animateHide != BooleanOptions.NoValue) {
44
+		if (other.animateHide.hasValue()) {
44
 			animateHide = other.animateHide;
45
 			animateHide = other.animateHide;
45
 		}
46
 		}
46
         if (other.color.hasValue()) {
47
         if (other.color.hasValue()) {
58
         if (NO_INT_VALUE == currentTabIndex) {
59
         if (NO_INT_VALUE == currentTabIndex) {
59
             currentTabIndex = defaultOptions.currentTabIndex;
60
             currentTabIndex = defaultOptions.currentTabIndex;
60
         }
61
         }
61
-        if (visible == BooleanOptions.NoValue) {
62
+        if (!visible.hasValue()) {
62
             visible = defaultOptions.visible;
63
             visible = defaultOptions.visible;
63
         }
64
         }
64
-        if (animateHide == BooleanOptions.NoValue) {
65
+        if (!animateHide.hasValue()) {
65
             animateHide = defaultOptions.animateHide;
66
             animateHide = defaultOptions.animateHide;
66
         }
67
         }
67
         if (!color.hasValue()) {
68
         if (!color.hasValue()) {

+ 8
- 5
lib/android/app/src/main/java/com/reactnativenavigation/parse/Button.java View File

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

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

2
 
2
 
3
 import android.support.annotation.CheckResult;
3
 import android.support.annotation.CheckResult;
4
 import android.support.annotation.NonNull;
4
 import android.support.annotation.NonNull;
5
-import android.text.TextUtils;
6
 
5
 
7
 import com.reactnativenavigation.utils.TypefaceLoader;
6
 import com.reactnativenavigation.utils.TypefaceLoader;
8
 
7
 
10
 
9
 
11
 public class Options implements DEFAULT_VALUES {
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
     @NonNull
12
     @NonNull
27
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {
13
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {
28
         return parse(typefaceManager, json, new Options());
14
         return parse(typefaceManager, json, new Options());
56
 
42
 
57
     @CheckResult
43
     @CheckResult
58
     public Options copy() {
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
     @CheckResult
54
     @CheckResult
63
 	public Options mergeWith(final Options other) {
55
 	public Options mergeWith(final Options other) {
64
-        Options result = new Options();
56
+        Options result = copy();
65
         result.topBarOptions.mergeWith(other.topBarOptions);
57
         result.topBarOptions.mergeWith(other.topBarOptions);
66
         result.topTabsOptions.mergeWith(other.topTabsOptions);
58
         result.topTabsOptions.mergeWith(other.topTabsOptions);
67
         result.topTabOptions.mergeWith(other.topTabOptions);
59
         result.topTabOptions.mergeWith(other.topTabOptions);

+ 6
- 2
lib/android/app/src/main/java/com/reactnativenavigation/parse/OverlayOptions.java View File

1
 package com.reactnativenavigation.parse;
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
 import org.json.JSONObject;
7
 import org.json.JSONObject;
4
 
8
 
5
 public class OverlayOptions {
9
 public class OverlayOptions {
6
-    public Options.BooleanOptions interceptTouchOutside = Options.BooleanOptions.False;
10
+    public Bool interceptTouchOutside = new NullBool();
7
 
11
 
8
     public static OverlayOptions parse(JSONObject json) {
12
     public static OverlayOptions parse(JSONObject json) {
9
         OverlayOptions options = new OverlayOptions();
13
         OverlayOptions options = new OverlayOptions();
10
         if (json == null) return options;
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
         return options;
17
         return options;
14
     }
18
     }
15
 }
19
 }

+ 21
- 17
lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarOptions.java View File

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

+ 25
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/params/Bool.java View File

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 View File

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 View File

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 View File

10
 
10
 
11
 import java.util.ArrayList;
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
 public class OptionsPresenter {
13
 public class OptionsPresenter {
17
     private TopBar topBar;
14
     private TopBar topBar;
18
     private ReactComponent component;
15
     private ReactComponent component;
37
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
34
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
38
 
35
 
39
         topBar.setTitleTypeface(options.textFontFamily);
36
         topBar.setTitleTypeface(options.textFontFamily);
40
-        if (options.hidden == True) {
37
+        if (options.hidden.isTrue()) {
41
             topBar.hide(options.animateHide);
38
             topBar.hide(options.animateHide);
42
         }
39
         }
43
-        if (options.hidden == False) {
40
+        if (options.hidden.isFalseOrUndefined()) {
44
             topBar.show(options.animateHide);
41
             topBar.show(options.animateHide);
45
         }
42
         }
46
-        if (options.drawBehind == True) {
43
+        if (options.drawBehind.isTrue()) {
47
             component.drawBehindTopBar();
44
             component.drawBehindTopBar();
48
-        } else if (options.drawBehind == False) {
45
+        } else if (options.drawBehind.isFalseOrUndefined()) {
49
             component.drawBelowTopBar(topBar);
46
             component.drawBelowTopBar(topBar);
50
         }
47
         }
51
 
48
 
52
-        if (options.hideOnScroll == True) {
49
+        if (options.hideOnScroll.isTrue()) {
53
             topBar.enableCollapse(component.getScrollEventListener());
50
             topBar.enableCollapse(component.getScrollEventListener());
54
-        } else if (options.hideOnScroll == False) {
51
+        } else if (options.hideOnScroll.isTrue()) {
55
             topBar.disableCollapse();
52
             topBar.disableCollapse();
56
         }
53
         }
57
     }
54
     }

+ 12
- 7
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java View File

25
 		super(context);
25
 		super(context);
26
 		this.reactView = reactView;
26
 		this.reactView = reactView;
27
         addView(reactView.asView(), MATCH_PARENT, MATCH_PARENT);
27
         addView(reactView.asView(), MATCH_PARENT, MATCH_PARENT);
28
+        setContentDescription("ComponentLayout");
28
         touchDelegate = new OverlayTouchDelegate(reactView);
29
         touchDelegate = new OverlayTouchDelegate(reactView);
29
     }
30
     }
30
 
31
 
55
 
56
 
56
     @Override
57
     @Override
57
     public void applyOptions(Options options) {
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
     @Override
62
     @Override
75
 
76
 
76
     @Override
77
     @Override
77
     public void drawBehindTopBar() {
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
     @Override
86
     @Override
84
     public void drawBelowTopBar(TopBar topBar) {
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
     @Override
95
     @Override

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java View File

21
         topBar = new TopBar(context, this);
21
         topBar = new TopBar(context, this);
22
         topBar.setId(CompatUtils.generateViewId());
22
         topBar.setId(CompatUtils.generateViewId());
23
         createLayout();
23
         createLayout();
24
+        setContentDescription("StackLayout");
24
     }
25
     }
25
 
26
 
26
     void createLayout() {
27
     void createLayout() {

+ 3
- 4
lib/android/app/src/main/java/com/reactnativenavigation/views/TitleBarButton.java View File

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

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

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

+ 28
- 25
lib/android/app/src/test/java/com/reactnativenavigation/parse/OptionsTest.java View File

5
 
5
 
6
 import com.reactnativenavigation.*;
6
 import com.reactnativenavigation.*;
7
 import com.reactnativenavigation.mocks.*;
7
 import com.reactnativenavigation.mocks.*;
8
+import com.reactnativenavigation.parse.params.Bool;
8
 import com.reactnativenavigation.utils.*;
9
 import com.reactnativenavigation.utils.*;
9
 
10
 
10
 import org.json.*;
11
 import org.json.*;
11
 import org.junit.*;
12
 import org.junit.*;
12
 import org.mockito.*;
13
 import org.mockito.*;
13
 
14
 
14
-import static com.reactnativenavigation.parse.Options.BooleanOptions.*;
15
 import static org.assertj.core.api.Java6Assertions.*;
15
 import static org.assertj.core.api.Java6Assertions.*;
16
 
16
 
17
 public class OptionsTest extends BaseTest {
17
 public class OptionsTest extends BaseTest {
22
     private static final int TOP_BAR_FONT_SIZE = 18;
22
     private static final int TOP_BAR_FONT_SIZE = 18;
23
     private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
23
     private static final String TOP_BAR_FONT_FAMILY = "HelveticaNeue-CondensedBold";
24
     private static final Typeface TOP_BAR_TYPEFACE = Typeface.create("HelveticaNeue-CondensedBold", Typeface.BOLD);
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
     private static final String BOTTOM_TABS_BADGE = "3";
30
     private static final String BOTTOM_TABS_BADGE = "3";
31
     private static final String BOTTOM_TABS_CURRENT_TAB_ID = "ComponentId";
31
     private static final String BOTTOM_TABS_CURRENT_TAB_ID = "ComponentId";
32
     private static final int BOTTOM_TABS_CURRENT_TAB_INDEX = 1;
32
     private static final int BOTTOM_TABS_CURRENT_TAB_INDEX = 1;
46
     @Test
46
     @Test
47
     public void parsesJson() throws Exception {
47
     public void parsesJson() throws Exception {
48
         JSONObject json = new JSONObject()
48
         JSONObject json = new JSONObject()
49
-                .put("topBar", createTopBar(TOP_BAR_HIDDEN))
49
+                .put("topBar", createTopBar(TOP_BAR_HIDDEN.get()))
50
                 .put("bottomTabs", createBottomTabs());
50
                 .put("bottomTabs", createBottomTabs());
51
         Options result = Options.parse(mockLoader, json);
51
         Options result = Options.parse(mockLoader, json);
52
         assertResult(result);
52
         assertResult(result);
58
         assertThat(result.topBarOptions.textColor.get()).isEqualTo(TOP_BAR_TEXT_COLOR);
58
         assertThat(result.topBarOptions.textColor.get()).isEqualTo(TOP_BAR_TEXT_COLOR);
59
         assertThat(result.topBarOptions.textFontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE);
59
         assertThat(result.topBarOptions.textFontSize.get()).isEqualTo(TOP_BAR_FONT_SIZE);
60
         assertThat(result.topBarOptions.textFontFamily).isEqualTo(TOP_BAR_TYPEFACE);
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
         assertThat(result.bottomTabsOptions.currentTabId.get()).isEqualTo(BOTTOM_TABS_CURRENT_TAB_ID);
66
         assertThat(result.bottomTabsOptions.currentTabId.get()).isEqualTo(BOTTOM_TABS_CURRENT_TAB_ID);
67
         assertThat(result.bottomTabsOptions.currentTabIndex).isEqualTo(BOTTOM_TABS_CURRENT_TAB_INDEX);
67
         assertThat(result.bottomTabsOptions.currentTabIndex).isEqualTo(BOTTOM_TABS_CURRENT_TAB_INDEX);
68
     }
68
     }
72
         return new JSONObject()
72
         return new JSONObject()
73
                 .put("currentTabId", BOTTOM_TABS_CURRENT_TAB_ID)
73
                 .put("currentTabId", BOTTOM_TABS_CURRENT_TAB_ID)
74
                 .put("currentTabIndex", BOTTOM_TABS_CURRENT_TAB_INDEX)
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
     @NonNull
79
     @NonNull
80
-    private JSONObject createTopBar(Options.BooleanOptions hidden) throws JSONException {
80
+    private JSONObject createTopBar(boolean hidden) throws JSONException {
81
         return new JSONObject()
81
         return new JSONObject()
82
                 .put("title", "the title")
82
                 .put("title", "the title")
83
                 .put("backgroundColor", TOP_BAR_BACKGROUND_COLOR)
83
                 .put("backgroundColor", TOP_BAR_BACKGROUND_COLOR)
85
                 .put("textFontSize", TOP_BAR_FONT_SIZE)
85
                 .put("textFontSize", TOP_BAR_FONT_SIZE)
86
                 .put("textFontFamily", TOP_BAR_FONT_FAMILY)
86
                 .put("textFontFamily", TOP_BAR_FONT_FAMILY)
87
                 .put("hidden", hidden)
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
     @NonNull
92
     @NonNull
113
     @Test
113
     @Test
114
     public void mergeDoesNotMutate() throws Exception {
114
     public void mergeDoesNotMutate() throws Exception {
115
         JSONObject json1 = new JSONObject();
115
         JSONObject json1 = new JSONObject();
116
-        json1.put("topBar", createTopBar(Options.BooleanOptions.True));
116
+        json1.put("topBar", createTopBar(true));
117
         Options options1 = Options.parse(mockLoader, json1);
117
         Options options1 = Options.parse(mockLoader, json1);
118
+        options1.topBarOptions.title = new Text("some title");
118
 
119
 
119
 
120
 
120
         JSONObject json2 = new JSONObject();
121
         JSONObject json2 = new JSONObject();
121
-        json2.put("topBar", createTopBar(Options.BooleanOptions.False));
122
+        json2.put("topBar", createTopBar(false));
122
         Options options2 = Options.parse(mockLoader, json2);
123
         Options options2 = Options.parse(mockLoader, json2);
124
+        options2.topBarOptions.title = new NullText();
123
 
125
 
124
         Options merged = options1.mergeWith(options2);
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
     @Test
132
     @Test
130
     public void mergeDefaultOptions() throws Exception {
133
     public void mergeDefaultOptions() throws Exception {
131
         JSONObject json = new JSONObject();
134
         JSONObject json = new JSONObject();
132
-        json.put("topBar", createTopBar(TOP_BAR_HIDDEN));
135
+        json.put("topBar", createTopBar(TOP_BAR_HIDDEN.get()));
133
         json.put("bottomTabs", createBottomTabs());
136
         json.put("bottomTabs", createBottomTabs());
134
         Options defaultOptions = Options.parse(mockLoader, json);
137
         Options defaultOptions = Options.parse(mockLoader, json);
135
         Options options = new Options();
138
         Options options = new Options();
145
         Options defaultOptions = Options.parse(mockLoader, defaultJson);
148
         Options defaultOptions = Options.parse(mockLoader, defaultJson);
146
 
149
 
147
         JSONObject json = new JSONObject()
150
         JSONObject json = new JSONObject()
148
-                .put("topBar", createTopBar(TOP_BAR_HIDDEN))
151
+                .put("topBar", createTopBar(TOP_BAR_HIDDEN.get()))
149
                 .put("bottomTabs", createBottomTabs());
152
                 .put("bottomTabs", createBottomTabs());
150
         Options options = Options.parse(mockLoader, json);
153
         Options options = Options.parse(mockLoader, json);
151
         options.withDefaultOptions(defaultOptions);
154
         options.withDefaultOptions(defaultOptions);
161
     @Test
164
     @Test
162
     public void topBar_defaultOptions() throws Exception {
165
     public void topBar_defaultOptions() throws Exception {
163
         Options uut = new Options();
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 View File

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

+ 1
- 1
playground/src/screens/ScrollViewScreen.js View File

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