Browse Source

Implement topBar.borderColor and topBar.borderHeight

Guy Carmeli 6 years ago
parent
commit
1b8e762d1d

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

7
 import com.reactnativenavigation.BuildConfig;
7
 import com.reactnativenavigation.BuildConfig;
8
 import com.reactnativenavigation.parse.params.Bool;
8
 import com.reactnativenavigation.parse.params.Bool;
9
 import com.reactnativenavigation.parse.params.Button;
9
 import com.reactnativenavigation.parse.params.Button;
10
+import com.reactnativenavigation.parse.params.Color;
11
+import com.reactnativenavigation.parse.params.Fraction;
10
 import com.reactnativenavigation.parse.params.NullBool;
12
 import com.reactnativenavigation.parse.params.NullBool;
13
+import com.reactnativenavigation.parse.params.NullColor;
14
+import com.reactnativenavigation.parse.params.NullFraction;
11
 import com.reactnativenavigation.parse.params.NullNumber;
15
 import com.reactnativenavigation.parse.params.NullNumber;
12
 import com.reactnativenavigation.parse.params.NullText;
16
 import com.reactnativenavigation.parse.params.NullText;
13
 import com.reactnativenavigation.parse.params.Number;
17
 import com.reactnativenavigation.parse.params.Number;
14
 import com.reactnativenavigation.parse.params.Text;
18
 import com.reactnativenavigation.parse.params.Text;
15
 import com.reactnativenavigation.parse.parsers.BoolParser;
19
 import com.reactnativenavigation.parse.parsers.BoolParser;
20
+import com.reactnativenavigation.parse.parsers.ColorParser;
21
+import com.reactnativenavigation.parse.parsers.FractionParser;
16
 import com.reactnativenavigation.parse.parsers.NumberParser;
22
 import com.reactnativenavigation.parse.parsers.NumberParser;
17
 import com.reactnativenavigation.parse.parsers.TextParser;
23
 import com.reactnativenavigation.parse.parsers.TextParser;
18
 import com.reactnativenavigation.utils.TypefaceLoader;
24
 import com.reactnativenavigation.utils.TypefaceLoader;
38
         options.leftButtons = Button.parseJsonArray(json.optJSONArray("leftButtons"), typefaceLoader);
44
         options.leftButtons = Button.parseJsonArray(json.optJSONArray("leftButtons"), typefaceLoader);
39
         options.testId = TextParser.parse(json, "testID");
45
         options.testId = TextParser.parse(json, "testID");
40
         options.height = NumberParser.parse(json, "height");
46
         options.height = NumberParser.parse(json, "height");
47
+        options.borderColor = ColorParser.parse(json, "borderColor");
48
+        options.borderHeight = FractionParser.parse(json, "borderHeight");
41
 
49
 
42
         options.validate();
50
         options.validate();
43
         return options;
51
         return options;
52
     public Bool hideOnScroll = new NullBool();
60
     public Bool hideOnScroll = new NullBool();
53
     public Bool drawBehind = new NullBool();
61
     public Bool drawBehind = new NullBool();
54
     public Number height = new NullNumber();
62
     public Number height = new NullNumber();
63
+    public Fraction borderHeight = new NullFraction();
64
+    public Color borderColor = new NullColor();
55
     @Nullable public ArrayList<Button> leftButtons;
65
     @Nullable public ArrayList<Button> leftButtons;
56
     @Nullable public ArrayList<Button> rightButtons;
66
     @Nullable public ArrayList<Button> rightButtons;
57
 
67
 
67
         if (other.leftButtons != null) leftButtons = other.leftButtons;
77
         if (other.leftButtons != null) leftButtons = other.leftButtons;
68
         if (other.rightButtons != null) rightButtons = other.rightButtons;
78
         if (other.rightButtons != null) rightButtons = other.rightButtons;
69
         if (other.height.hasValue()) height = other.height;
79
         if (other.height.hasValue()) height = other.height;
80
+        if (other.borderHeight.hasValue()) borderHeight = other.borderHeight;
81
+        if (other.borderColor.hasValue()) borderColor = other.borderColor;
70
         validate();
82
         validate();
71
     }
83
     }
72
 
84
 
82
         if (rightButtons == null) rightButtons = defaultOptions.rightButtons;
94
         if (rightButtons == null) rightButtons = defaultOptions.rightButtons;
83
         if (!testId.hasValue()) testId = defaultOptions.testId;
95
         if (!testId.hasValue()) testId = defaultOptions.testId;
84
         if (!height.hasValue()) height = defaultOptions.height;
96
         if (!height.hasValue()) height = defaultOptions.height;
97
+        if (!borderHeight.hasValue()) borderHeight = defaultOptions.borderHeight;
98
+        if (!borderColor.hasValue()) borderColor = defaultOptions.borderColor;
85
         validate();
99
         validate();
86
     }
100
     }
87
 
101
 

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

1
 package com.reactnativenavigation.parse.params;
1
 package com.reactnativenavigation.parse.params;
2
 
2
 
3
-public class Fraction extends Param<Float> {
4
-    public Fraction(float value) {
3
+public class Fraction extends Param<Double> {
4
+    public Fraction(double value) {
5
         super(value);
5
         super(value);
6
     }
6
     }
7
 }
7
 }

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

7
 
7
 
8
 public class FractionParser {
8
 public class FractionParser {
9
     public static Fraction parse(JSONObject json, String fraction) {
9
     public static Fraction parse(JSONObject json, String fraction) {
10
-        return json.has(fraction) ? new Fraction(json.optInt(fraction)) : new NullFraction();
10
+        return json.has(fraction) ? new Fraction(json.optDouble(fraction)) : new NullFraction();
11
     }
11
     }
12
 }
12
 }

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

21
 public class StackOptionsPresenter {
21
 public class StackOptionsPresenter {
22
     private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
22
     private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
23
     private static final int DEFAULT_SUBTITLE_COLOR = Color.GRAY;
23
     private static final int DEFAULT_SUBTITLE_COLOR = Color.GRAY;
24
-    private final float defaultTitleFontSize;
25
-    private final float defaultSubtitleFontSize;
24
+    private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
25
+    private final double defaultTitleFontSize;
26
+    private final double defaultSubtitleFontSize;
26
 
27
 
27
     private TopBar topBar;
28
     private TopBar topBar;
28
 
29
 
61
         topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
62
         topBar.setSubtitleFontFamily(options.subtitle.fontFamily);
62
         topBar.setSubtitleAlignment(options.subtitle.alignment);
63
         topBar.setSubtitleAlignment(options.subtitle.alignment);
63
 
64
 
65
+        topBar.setBorderHeight(options.borderHeight.get(0d));
66
+        topBar.setBorderColor(options.borderColor.get(DEFAULT_BORDER_COLOR));
67
+
64
         topBar.setBackgroundColor(options.background.color);
68
         topBar.setBackgroundColor(options.background.color);
65
         topBar.setBackgroundComponent(options.background.component);
69
         topBar.setBackgroundComponent(options.background.component);
66
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());
70
         if (options.testId.hasValue()) topBar.setTestId(options.testId.get());

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

74
         if (color.hasValue()) setBackgroundColor(color.get());
74
         if (color.hasValue()) setBackgroundColor(color.get());
75
     }
75
     }
76
 
76
 
77
-    public void setTitleFontSize(float size) {
77
+    public void setTitleFontSize(double size) {
78
         TextView titleTextView = findTitleTextView();
78
         TextView titleTextView = findTitleTextView();
79
-        if (titleTextView != null) titleTextView.setTextSize(size);
79
+        if (titleTextView != null) titleTextView.setTextSize((float) size);
80
     }
80
     }
81
 
81
 
82
     public void setTitleTypeface(Typeface typeface) {
82
     public void setTitleTypeface(Typeface typeface) {
95
         if (subtitleTextView != null) subtitleTextView.setTypeface(typeface);
95
         if (subtitleTextView != null) subtitleTextView.setTypeface(typeface);
96
     }
96
     }
97
 
97
 
98
-    public void setSubtitleFontSize(float size) {
98
+    public void setSubtitleFontSize(double size) {
99
         TextView subtitleTextView = findSubtitleTextView();
99
         TextView subtitleTextView = findSubtitleTextView();
100
-        if (subtitleTextView != null) subtitleTextView.setTextSize(size);
100
+        if (subtitleTextView != null) subtitleTextView.setTextSize((float) size);
101
     }
101
     }
102
 
102
 
103
     public void setSubtitleAlignment(Alignment alignment) {
103
     public void setSubtitleAlignment(Alignment alignment) {

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

9
 import android.support.design.widget.AppBarLayout;
9
 import android.support.design.widget.AppBarLayout;
10
 import android.support.v4.view.ViewPager;
10
 import android.support.v4.view.ViewPager;
11
 import android.support.v7.widget.Toolbar;
11
 import android.support.v7.widget.Toolbar;
12
+import android.view.Gravity;
12
 import android.view.View;
13
 import android.view.View;
13
 import android.view.ViewGroup;
14
 import android.view.ViewGroup;
15
+import android.widget.FrameLayout;
14
 import android.widget.RelativeLayout;
16
 import android.widget.RelativeLayout;
15
 import android.widget.TextView;
17
 import android.widget.TextView;
16
 
18
 
19
+import com.reactnativenavigation.BuildConfig;
17
 import com.reactnativenavigation.anim.TopBarAnimator;
20
 import com.reactnativenavigation.anim.TopBarAnimator;
18
 import com.reactnativenavigation.anim.TopBarCollapseBehavior;
21
 import com.reactnativenavigation.anim.TopBarCollapseBehavior;
19
 import com.reactnativenavigation.interfaces.ScrollEventListener;
22
 import com.reactnativenavigation.interfaces.ScrollEventListener;
45
     private final TopBarCollapseBehavior collapsingBehavior;
48
     private final TopBarCollapseBehavior collapsingBehavior;
46
     private TopBarAnimator animator;
49
     private TopBarAnimator animator;
47
     private TopTabs topTabs;
50
     private TopTabs topTabs;
48
-    private RelativeLayout root;
51
+    private FrameLayout root;
49
     private StackLayout parentView;
52
     private StackLayout parentView;
50
     private TopBarBackgroundViewController topBarBackgroundViewController;
53
     private TopBarBackgroundViewController topBarBackgroundViewController;
54
+    private View border;
51
 
55
 
52
     public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView) {
56
     public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView) {
53
         super(context);
57
         super(context);
60
     }
64
     }
61
 
65
 
62
     private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarButtonController.OnClickListener onClickListener) {
66
     private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarButtonController.OnClickListener onClickListener) {
67
+        setId(CompatUtils.generateViewId());
63
         topTabs = new TopTabs(getContext());
68
         topTabs = new TopTabs(getContext());
64
         titleBar = createTitleBar(getContext(), buttonCreator, titleBarReactViewCreator, onClickListener);
69
         titleBar = createTitleBar(getContext(), buttonCreator, titleBarReactViewCreator, onClickListener);
65
         titleBar.setId(CompatUtils.generateViewId());
70
         titleBar.setId(CompatUtils.generateViewId());
66
-        root = new RelativeLayout(getContext());
71
+        root = new FrameLayout(getContext());
72
+        root.setId(CompatUtils.generateViewId());
67
         root.addView(titleBar, MATCH_PARENT, WRAP_CONTENT);
73
         root.addView(titleBar, MATCH_PARENT, WRAP_CONTENT);
74
+        border = createBorder();
75
+        root.addView(border);
68
         addView(root, MATCH_PARENT, WRAP_CONTENT);
76
         addView(root, MATCH_PARENT, WRAP_CONTENT);
69
-        setContentDescription("TopBar");
77
+        if (BuildConfig.DEBUG) setContentDescription("TopBar");
78
+    }
79
+
80
+    private View createBorder() {
81
+        View border = new View(getContext());
82
+        border.setBackgroundColor(android.graphics.Color.TRANSPARENT);
83
+        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(MATCH_PARENT, 0);
84
+        lp.gravity = Gravity.BOTTOM;
85
+        border.setLayoutParams(lp);
86
+        return border;
70
     }
87
     }
71
 
88
 
72
     protected TitleBar createTitleBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator reactViewCreator, TopBarButtonController.OnClickListener onClickListener) {
89
     protected TitleBar createTitleBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator reactViewCreator, TopBarButtonController.OnClickListener onClickListener) {
104
         titleBar.setSubtitleTypeface(fontFamily);
121
         titleBar.setSubtitleTypeface(fontFamily);
105
     }
122
     }
106
 
123
 
107
-    public void setSubtitleFontSize(float size) {
124
+    public void setSubtitleFontSize(double size) {
108
         titleBar.setSubtitleFontSize(size);
125
         titleBar.setSubtitleFontSize(size);
109
     }
126
     }
110
 
127
 
120
         titleBar.setTitleTextColor(color);
137
         titleBar.setTitleTextColor(color);
121
     }
138
     }
122
 
139
 
123
-    public void setTitleFontSize(float size) {
140
+    public void setTitleFontSize(double size) {
124
         titleBar.setTitleFontSize(size);
141
         titleBar.setTitleFontSize(size);
125
     }
142
     }
126
 
143
 
266
         setRotationY(0);
283
         setRotationY(0);
267
         setRotation(0);
284
         setRotation(0);
268
     }
285
     }
286
+
287
+    public void setBorderHeight(double height) {
288
+        border.getLayoutParams().height = (int) UiUtils.dpToPx(getContext(), (float) height);
289
+    }
290
+
291
+    public void setBorderColor(int color) {
292
+        border.setBackgroundColor(color);
293
+    }
269
 }
294
 }

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsMergingTest.java View File

25
 
25
 
26
 import static org.mockito.ArgumentMatchers.any;
26
 import static org.mockito.ArgumentMatchers.any;
27
 import static org.mockito.ArgumentMatchers.anyBoolean;
27
 import static org.mockito.ArgumentMatchers.anyBoolean;
28
-import static org.mockito.ArgumentMatchers.anyFloat;
28
+import static org.mockito.ArgumentMatchers.anyDouble;
29
 import static org.mockito.ArgumentMatchers.anyInt;
29
 import static org.mockito.ArgumentMatchers.anyInt;
30
 import static org.mockito.Mockito.mock;
30
 import static org.mockito.Mockito.mock;
31
 import static org.mockito.Mockito.spy;
31
 import static org.mockito.Mockito.spy;
147
         verify(topBar, times(t)).setTitleComponent(any());
147
         verify(topBar, times(t)).setTitleComponent(any());
148
         verify(topBar, times(t)).setBackgroundColor(any());
148
         verify(topBar, times(t)).setBackgroundColor(any());
149
         verify(topBar, times(t)).setTitleTextColor(anyInt());
149
         verify(topBar, times(t)).setTitleTextColor(anyInt());
150
-        verify(topBar, times(t)).setTitleFontSize(anyFloat());
150
+        verify(topBar, times(t)).setTitleFontSize(anyDouble());
151
         verify(topBar, times(t)).setTitleTypeface(any());
151
         verify(topBar, times(t)).setTitleTypeface(any());
152
         verify(topBar, times(t)).setSubtitleColor(anyInt());
152
         verify(topBar, times(t)).setSubtitleColor(anyInt());
153
         verify(topBar, times(t)).setTestId(any());
153
         verify(topBar, times(t)).setTestId(any());

+ 2
- 0
playground/src/screens/OptionsScreen.js View File

52
         _height: TOPBAR_HEIGHT,
52
         _height: TOPBAR_HEIGHT,
53
         visible: true,
53
         visible: true,
54
         testID: testIDs.TOP_BAR_ELEMENT,
54
         testID: testIDs.TOP_BAR_ELEMENT,
55
+        borderColor: 'red',
56
+        borderHeight: 1,
55
         rightButtons: [
57
         rightButtons: [
56
           // {
58
           // {
57
           //   id: CUSTOM_BUTTON,
59
           //   id: CUSTOM_BUTTON,