Browse Source

remove default values (#2942)

* remove default values

* fix test
Roman Kozlov 6 years ago
parent
commit
0e8f26dd2b

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

6
 
6
 
7
 import org.json.JSONObject;
7
 import org.json.JSONObject;
8
 
8
 
9
-public class BottomTabOptions implements DEFAULT_VALUES {
9
+public class BottomTabOptions {
10
 
10
 
11
     public static BottomTabOptions parse(JSONObject json) {
11
     public static BottomTabOptions parse(JSONObject json) {
12
         BottomTabOptions options = new BottomTabOptions();
12
         BottomTabOptions options = new BottomTabOptions();

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

15
 
15
 
16
 import org.json.JSONObject;
16
 import org.json.JSONObject;
17
 
17
 
18
-public class BottomTabsOptions implements DEFAULT_VALUES {
18
+public class BottomTabsOptions {
19
 
19
 
20
 	public static BottomTabsOptions parse(JSONObject json) {
20
 	public static BottomTabsOptions parse(JSONObject json) {
21
 		BottomTabsOptions options = new BottomTabsOptions();
21
 		BottomTabsOptions options = new BottomTabsOptions();

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

1
-package com.reactnativenavigation.parse;
2
-
3
-
4
-public interface DEFAULT_VALUES {
5
-	int NO_INT_VALUE = Integer.MIN_VALUE;
6
-}

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

16
 
16
 
17
 import java.util.ArrayList;
17
 import java.util.ArrayList;
18
 
18
 
19
-public class FabOptions implements DEFAULT_VALUES {
19
+public class FabOptions {
20
 
20
 
21
     public static FabOptions parse(JSONObject json) {
21
     public static FabOptions parse(JSONObject json) {
22
         FabOptions options = new FabOptions();
22
         FabOptions options = new FabOptions();

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

7
 
7
 
8
 import org.json.JSONObject;
8
 import org.json.JSONObject;
9
 
9
 
10
-public class Options implements DEFAULT_VALUES {
10
+public class Options {
11
 
11
 
12
     @NonNull
12
     @NonNull
13
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {
13
     public static Options parse(TypefaceLoader typefaceManager, JSONObject json) {

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

16
 
16
 
17
 import java.util.ArrayList;
17
 import java.util.ArrayList;
18
 
18
 
19
-public class TopBarOptions implements DEFAULT_VALUES {
19
+public class TopBarOptions {
20
 
20
 
21
     public static TopBarOptions parse(TypefaceLoader typefaceManager, JSONObject json) {
21
     public static TopBarOptions parse(TypefaceLoader typefaceManager, JSONObject json) {
22
         TopBarOptions options = new TopBarOptions();
22
         TopBarOptions options = new TopBarOptions();

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

10
 
10
 
11
 import org.json.JSONObject;
11
 import org.json.JSONObject;
12
 
12
 
13
-public class TopTabOptions implements DEFAULT_VALUES {
13
+public class TopTabOptions {
14
     public Text title = new NullText();
14
     public Text title = new NullText();
15
     @Nullable public Typeface fontFamily;
15
     @Nullable public Typeface fontFamily;
16
     public int tabIndex;
16
     public int tabIndex;

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

15
 
15
 
16
 import org.json.JSONObject;
16
 import org.json.JSONObject;
17
 
17
 
18
-public class TopTabsOptions implements DEFAULT_VALUES {
18
+public class TopTabsOptions {
19
 
19
 
20
     @NonNull public Color selectedTabColor = new NullColor();
20
     @NonNull public Color selectedTabColor = new NullColor();
21
     @NonNull public Color unselectedTabColor = new NullColor();
21
     @NonNull public Color unselectedTabColor = new NullColor();

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

17
 
17
 
18
 import org.json.JSONObject;
18
 import org.json.JSONObject;
19
 
19
 
20
-public class ValueAnimationOptions implements DEFAULT_VALUES {
20
+public class ValueAnimationOptions {
21
 
21
 
22
     public static ValueAnimationOptions parse(JSONObject json, Property<View, Float> property) {
22
     public static ValueAnimationOptions parse(JSONObject json, Property<View, Float> property) {
23
         ValueAnimationOptions options = new ValueAnimationOptions();
23
         ValueAnimationOptions options = new ValueAnimationOptions();

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

1
 package com.reactnativenavigation.parse.params;
1
 package com.reactnativenavigation.parse.params;
2
 
2
 
3
-import android.support.annotation.ColorInt;
4
 import android.view.MenuItem;
3
 import android.view.MenuItem;
5
 
4
 
6
 import com.reactnativenavigation.parse.parsers.BoolParser;
5
 import com.reactnativenavigation.parse.parsers.BoolParser;
6
+import com.reactnativenavigation.parse.parsers.ColorParser;
7
+import com.reactnativenavigation.parse.parsers.NumberParser;
7
 import com.reactnativenavigation.parse.parsers.TextParser;
8
 import com.reactnativenavigation.parse.parsers.TextParser;
8
 
9
 
9
 import org.json.JSONArray;
10
 import org.json.JSONArray;
11
 
12
 
12
 import java.util.ArrayList;
13
 import java.util.ArrayList;
13
 
14
 
14
-import static com.reactnativenavigation.parse.Options.NO_INT_VALUE;
15
-
16
 public class Button {
15
 public class Button {
17
-	public String id;
18
-	public Text title = new NullText();
19
-	public Bool enabled = new NullBool();
20
-	public Bool disableIconTint = new NullBool();
21
-	public int showAsAction;
22
-	@ColorInt public int buttonColor;
23
-	public int buttonFontSize;
24
-	private Text buttonFontWeight = new NullText();
25
-	public Text icon = new NullText();
26
-	public Text testId = new NullText();
16
+    public String id;
17
+    public Text title = new NullText();
18
+    public Bool enabled = new NullBool();
19
+    public Bool disableIconTint = new NullBool();
20
+    public int showAsAction;
21
+    public Color buttonColor = new NullColor();
22
+    public Number buttonFontSize = new NullNumber();
23
+    private Text buttonFontWeight = new NullText();
24
+    public Text icon = new NullText();
25
+    public Text testId = new NullText();
27
     public Text component = new NullText();
26
     public Text component = new NullText();
28
 
27
 
29
-	private static Button parseJson(JSONObject json)  {
30
-		Button button = new Button();
31
-		button.id = json.optString("id");
32
-		button.title = TextParser.parse(json, "title");
33
-		button.enabled = BoolParser.parse(json,"enabled");
34
-		button.disableIconTint = BoolParser.parse(json,"disableIconTint");
35
-		button.showAsAction = parseShowAsAction(json);
36
-		button.buttonColor = json.optInt("buttonColor", NO_INT_VALUE);
37
-		button.buttonFontSize = json.optInt("buttonFontSize", NO_INT_VALUE);
38
-		button.buttonFontWeight = TextParser.parse(json, "buttonFontWeight");
28
+    private static Button parseJson(JSONObject json) {
29
+        Button button = new Button();
30
+        button.id = json.optString("id");
31
+        button.title = TextParser.parse(json, "title");
32
+        button.enabled = BoolParser.parse(json, "enabled");
33
+        button.disableIconTint = BoolParser.parse(json, "disableIconTint");
34
+        button.showAsAction = parseShowAsAction(json);
35
+        button.buttonColor = ColorParser.parse(json, "buttonColor");
36
+        button.buttonFontSize = NumberParser.parse(json, "buttonFontSize");
37
+        button.buttonFontWeight = TextParser.parse(json, "buttonFontWeight");
39
         button.testId = TextParser.parse(json, "testID");
38
         button.testId = TextParser.parse(json, "testID");
40
         button.component = TextParser.parse(json, "component");
39
         button.component = TextParser.parse(json, "component");
41
 
40
 
42
-		if (json.has("icon")) {
43
-			button.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
44
-		}
41
+        if (json.has("icon")) {
42
+            button.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
43
+        }
45
 
44
 
46
-		return button;
47
-	}
45
+        return button;
46
+    }
48
 
47
 
49
-	public static ArrayList<Button> parseJsonArray(JSONArray jsonArray) {
50
-		ArrayList<Button> buttons = new ArrayList<>();
48
+    public static ArrayList<Button> parseJsonArray(JSONArray jsonArray) {
49
+        ArrayList<Button> buttons = new ArrayList<>();
51
 
50
 
52
-		if (jsonArray == null) {
53
-			return null;
54
-		}
51
+        if (jsonArray == null) {
52
+            return null;
53
+        }
55
 
54
 
56
-		for (int i = 0; i < jsonArray.length(); i++) {
57
-			JSONObject json = jsonArray.optJSONObject(i);
58
-			Button button =	Button.parseJson(json);
59
-			buttons.add(button);
60
-		}
55
+        for (int i = 0; i < jsonArray.length(); i++) {
56
+            JSONObject json = jsonArray.optJSONObject(i);
57
+            Button button = Button.parseJson(json);
58
+            buttons.add(button);
59
+        }
61
 
60
 
62
-		return buttons;
63
-	}
61
+        return buttons;
62
+    }
64
 
63
 
65
     public boolean hasComponent() {
64
     public boolean hasComponent() {
66
         return component.hasValue();
65
         return component.hasValue();
70
         return icon.hasValue();
69
         return icon.hasValue();
71
     }
70
     }
72
 
71
 
73
-	private static int parseShowAsAction(JSONObject json) {
74
-	    final Text showAsAction = TextParser.parse(json, "showAsAction");
75
-		if (!showAsAction.hasValue()) {
76
-			return MenuItem.SHOW_AS_ACTION_IF_ROOM;
77
-		}
78
-
79
-		switch (showAsAction.get()) {
80
-			case "always":
81
-				return MenuItem.SHOW_AS_ACTION_ALWAYS;
82
-			case "never":
83
-				return MenuItem.SHOW_AS_ACTION_NEVER;
84
-			case "withText":
85
-				return MenuItem.SHOW_AS_ACTION_WITH_TEXT;
86
-			case "ifRoom":
87
-			default:
88
-				return MenuItem.SHOW_AS_ACTION_IF_ROOM;
89
-		}
90
-	}
72
+    private static int parseShowAsAction(JSONObject json) {
73
+        final Text showAsAction = TextParser.parse(json, "showAsAction");
74
+        if (!showAsAction.hasValue()) {
75
+            return MenuItem.SHOW_AS_ACTION_IF_ROOM;
76
+        }
77
+
78
+        switch (showAsAction.get()) {
79
+            case "always":
80
+                return MenuItem.SHOW_AS_ACTION_ALWAYS;
81
+            case "never":
82
+                return MenuItem.SHOW_AS_ACTION_NEVER;
83
+            case "withText":
84
+                return MenuItem.SHOW_AS_ACTION_WITH_TEXT;
85
+            case "ifRoom":
86
+            default:
87
+                return MenuItem.SHOW_AS_ACTION_IF_ROOM;
88
+        }
89
+    }
91
 }
90
 }

+ 10
- 7
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/TopBarButtonController.java View File

18
 import com.reactnativenavigation.parse.Options;
18
 import com.reactnativenavigation.parse.Options;
19
 import com.reactnativenavigation.parse.params.Button;
19
 import com.reactnativenavigation.parse.params.Button;
20
 import com.reactnativenavigation.parse.params.Text;
20
 import com.reactnativenavigation.parse.params.Text;
21
-import com.reactnativenavigation.views.titlebar.TitleBarReactButtonView;
22
 import com.reactnativenavigation.utils.ArrayUtils;
21
 import com.reactnativenavigation.utils.ArrayUtils;
23
 import com.reactnativenavigation.utils.ImageLoader;
22
 import com.reactnativenavigation.utils.ImageLoader;
24
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
23
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
25
 import com.reactnativenavigation.utils.UiUtils;
24
 import com.reactnativenavigation.utils.UiUtils;
26
 import com.reactnativenavigation.utils.ViewUtils;
25
 import com.reactnativenavigation.utils.ViewUtils;
26
+import com.reactnativenavigation.views.titlebar.TitleBarReactButtonView;
27
 
27
 
28
 import java.util.ArrayList;
28
 import java.util.ArrayList;
29
 import java.util.List;
29
 import java.util.List;
136
     }
136
     }
137
 
137
 
138
     private void setIconColor(Drawable icon) {
138
     private void setIconColor(Drawable icon) {
139
-        if (button.enabled.isTrueOrUndefined()) {
140
-            UiUtils.tintDrawable(icon, button.buttonColor);
139
+        if (button.enabled.isTrueOrUndefined() && button.buttonColor.hasValue()) {
140
+            UiUtils.tintDrawable(icon, button.buttonColor.get());
141
             return;
141
             return;
142
         }
142
         }
143
-        if (button.disableIconTint.isTrue()) {
144
-            UiUtils.tintDrawable(icon, button.buttonColor);
143
+        if (button.disableIconTint.isTrue() && button.buttonColor.hasValue()) {
144
+            UiUtils.tintDrawable(icon, button.buttonColor.get());
145
         } else {
145
         } else {
146
             UiUtils.tintDrawable(icon, Color.LTGRAY);
146
             UiUtils.tintDrawable(icon, Color.LTGRAY);
147
         }
147
         }
163
 
163
 
164
     private void setTextColorForFoundButtonViews(ArrayList<View> buttons) {
164
     private void setTextColorForFoundButtonViews(ArrayList<View> buttons) {
165
         for (View button : buttons) {
165
         for (View button : buttons) {
166
-            ((TextView) button).setTextColor(this.button.buttonColor);
166
+            if (this.button.buttonColor.hasValue())
167
+                ((TextView) button).setTextColor(this.button.buttonColor.get());
167
         }
168
         }
168
     }
169
     }
169
 
170
 
170
     private void setFontSize(MenuItem menuItem) {
171
     private void setFontSize(MenuItem menuItem) {
171
         SpannableString spanString = new SpannableString(button.title.get());
172
         SpannableString spanString = new SpannableString(button.title.get());
172
-        spanString.setSpan(new AbsoluteSizeSpan(button.buttonFontSize, true), 0, button.title.get().length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
173
+        if (this.button.buttonFontSize.hasValue())
174
+            spanString.setSpan(new AbsoluteSizeSpan(button.buttonFontSize.get(), true),
175
+                    0, button.title.get().length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
173
         menuItem.setTitleCondensed(spanString);
176
         menuItem.setTitleCondensed(spanString);
174
     }
177
     }
175
 
178