Browse Source

Implement topBar.height and title.height

This commit add support for changing the TopBar height as well as changing
the height of custom component used as background
Guy Carmeli 6 years ago
parent
commit
4df7426fd1

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

7
 import com.reactnativenavigation.parse.params.Fraction;
7
 import com.reactnativenavigation.parse.params.Fraction;
8
 import com.reactnativenavigation.parse.params.NullColor;
8
 import com.reactnativenavigation.parse.params.NullColor;
9
 import com.reactnativenavigation.parse.params.NullFraction;
9
 import com.reactnativenavigation.parse.params.NullFraction;
10
+import com.reactnativenavigation.parse.params.NullNumber;
10
 import com.reactnativenavigation.parse.params.NullText;
11
 import com.reactnativenavigation.parse.params.NullText;
12
+import com.reactnativenavigation.parse.params.Number;
11
 import com.reactnativenavigation.parse.params.Text;
13
 import com.reactnativenavigation.parse.params.Text;
12
 import com.reactnativenavigation.parse.parsers.ColorParser;
14
 import com.reactnativenavigation.parse.parsers.ColorParser;
13
 import com.reactnativenavigation.parse.parsers.FractionParser;
15
 import com.reactnativenavigation.parse.parsers.FractionParser;
38
     public Alignment alignment = Alignment.Default;
40
     public Alignment alignment = Alignment.Default;
39
     @Nullable public Typeface fontFamily;
41
     @Nullable public Typeface fontFamily;
40
     public Component component = new Component();
42
     public Component component = new Component();
43
+    public Number height = new NullNumber();
41
 
44
 
42
     void mergeWith(final TitleOptions other) {
45
     void mergeWith(final TitleOptions other) {
43
         if (other.text.hasValue()) text = other.text;
46
         if (other.text.hasValue()) text = other.text;
46
         if (other.fontFamily != null) fontFamily = other.fontFamily;
49
         if (other.fontFamily != null) fontFamily = other.fontFamily;
47
         if (other.alignment != Alignment.Default) alignment = other.alignment;
50
         if (other.alignment != Alignment.Default) alignment = other.alignment;
48
         if (other.component.hasValue()) component = other.component;
51
         if (other.component.hasValue()) component = other.component;
52
+        if (other.height.hasValue()) height = other.height;
49
     }
53
     }
50
 
54
 
51
     void mergeWithDefault(TitleOptions defaultOptions) {
55
     void mergeWithDefault(TitleOptions defaultOptions) {
55
         if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
59
         if (fontFamily == null) fontFamily = defaultOptions.fontFamily;
56
         if (alignment == Alignment.Default) alignment = defaultOptions.alignment;
60
         if (alignment == Alignment.Default) alignment = defaultOptions.alignment;
57
         component.mergeWithDefault(defaultOptions.component);
61
         component.mergeWithDefault(defaultOptions.component);
62
+        if (!height.hasValue()) height = defaultOptions.height;
58
     }
63
     }
59
 }
64
 }

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

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.NullBool;
10
 import com.reactnativenavigation.parse.params.NullBool;
11
+import com.reactnativenavigation.parse.params.NullNumber;
11
 import com.reactnativenavigation.parse.params.NullText;
12
 import com.reactnativenavigation.parse.params.NullText;
13
+import com.reactnativenavigation.parse.params.Number;
12
 import com.reactnativenavigation.parse.params.Text;
14
 import com.reactnativenavigation.parse.params.Text;
13
 import com.reactnativenavigation.parse.parsers.BoolParser;
15
 import com.reactnativenavigation.parse.parsers.BoolParser;
16
+import com.reactnativenavigation.parse.parsers.NumberParser;
14
 import com.reactnativenavigation.parse.parsers.TextParser;
17
 import com.reactnativenavigation.parse.parsers.TextParser;
15
 import com.reactnativenavigation.utils.TypefaceLoader;
18
 import com.reactnativenavigation.utils.TypefaceLoader;
16
 
19
 
34
         options.rightButtons = Button.parseJsonArray(json.optJSONArray("rightButtons"), typefaceLoader);
37
         options.rightButtons = Button.parseJsonArray(json.optJSONArray("rightButtons"), typefaceLoader);
35
         options.leftButtons = Button.parseJsonArray(json.optJSONArray("leftButtons"), typefaceLoader);
38
         options.leftButtons = Button.parseJsonArray(json.optJSONArray("leftButtons"), typefaceLoader);
36
         options.testId = TextParser.parse(json, "testID");
39
         options.testId = TextParser.parse(json, "testID");
40
+        options.height = NumberParser.parse(json, "height");
37
 
41
 
38
         options.validate();
42
         options.validate();
39
         return options;
43
         return options;
47
     public Bool animate = new NullBool();
51
     public Bool animate = new NullBool();
48
     public Bool hideOnScroll = new NullBool();
52
     public Bool hideOnScroll = new NullBool();
49
     public Bool drawBehind = new NullBool();
53
     public Bool drawBehind = new NullBool();
54
+    public Number height = new NullNumber();
50
     @Nullable public ArrayList<Button> leftButtons;
55
     @Nullable public ArrayList<Button> leftButtons;
51
     @Nullable public ArrayList<Button> rightButtons;
56
     @Nullable public ArrayList<Button> rightButtons;
52
 
57
 
61
         if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
66
         if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
62
         if (other.leftButtons != null) leftButtons = other.leftButtons;
67
         if (other.leftButtons != null) leftButtons = other.leftButtons;
63
         if (other.rightButtons != null) rightButtons = other.rightButtons;
68
         if (other.rightButtons != null) rightButtons = other.rightButtons;
69
+        if (other.height.hasValue()) height = other.height;
64
         validate();
70
         validate();
65
     }
71
     }
66
 
72
 
75
         if (leftButtons == null) leftButtons = defaultOptions.leftButtons;
81
         if (leftButtons == null) leftButtons = defaultOptions.leftButtons;
76
         if (rightButtons == null) rightButtons = defaultOptions.rightButtons;
82
         if (rightButtons == null) rightButtons = defaultOptions.rightButtons;
77
         if (!testId.hasValue()) testId = defaultOptions.testId;
83
         if (!testId.hasValue()) testId = defaultOptions.testId;
84
+        if (!height.hasValue()) height = defaultOptions.height;
78
         validate();
85
         validate();
79
     }
86
     }
80
 
87
 

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

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.graphics.Color;
4
 import android.graphics.Color;
5
+import android.view.ViewGroup.LayoutParams;
5
 
6
 
6
 import com.reactnativenavigation.parse.AnimationsOptions;
7
 import com.reactnativenavigation.parse.AnimationsOptions;
7
 import com.reactnativenavigation.parse.Options;
8
 import com.reactnativenavigation.parse.Options;
44
     }
45
     }
45
 
46
 
46
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Options componentOptions) {
47
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Options componentOptions) {
48
+        topBar.setHeight(options.height.get(LayoutParams.WRAP_CONTENT));
49
+
50
+        topBar.setTitleHeight(options.title.height.get(LayoutParams.WRAP_CONTENT));
47
         topBar.setTitle(options.title.text.get(""));
51
         topBar.setTitle(options.title.text.get(""));
48
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component);
52
         if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component);
49
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));
53
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

74
         }
74
         }
75
         return false;
75
         return false;
76
     }
76
     }
77
+
78
+    public static int getPreferredHeight(View view) {
79
+        return view.getLayoutParams().height < 0 ? view.getHeight() : view.getLayoutParams().height;
80
+    }
77
 }
81
 }

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

9
 
9
 
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.utils.ViewUtils;
12
 import com.reactnativenavigation.viewcontrollers.IReactView;
13
 import com.reactnativenavigation.viewcontrollers.IReactView;
13
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
14
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
14
 import com.reactnativenavigation.views.topbar.TopBar;
15
 import com.reactnativenavigation.views.topbar.TopBar;
87
     public void drawBelowTopBar(TopBar topBar) {
88
     public void drawBelowTopBar(TopBar topBar) {
88
         if (getParent() instanceof RelativeLayout) {
89
         if (getParent() instanceof RelativeLayout) {
89
             RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
90
             RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) getLayoutParams();
90
-            layoutParams.topMargin = topBar.getHeight();
91
+            layoutParams.topMargin = ViewUtils.getPreferredHeight(topBar);
91
             setLayoutParams(layoutParams);
92
             setLayoutParams(layoutParams);
92
         }
93
         }
93
     }
94
     }

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

7
 import android.support.v7.widget.Toolbar;
7
 import android.support.v7.widget.Toolbar;
8
 import android.util.Log;
8
 import android.util.Log;
9
 import android.view.Gravity;
9
 import android.view.Gravity;
10
+import android.view.ViewGroup;
10
 import android.widget.TextView;
11
 import android.widget.TextView;
11
 
12
 
12
 import com.reactnativenavigation.parse.Alignment;
13
 import com.reactnativenavigation.parse.Alignment;
213
         }
214
         }
214
         return lp;
215
         return lp;
215
     }
216
     }
217
+
218
+    public void setHeight(int height) {
219
+        ViewGroup.LayoutParams lp = getLayoutParams();
220
+        lp.height = (int) UiUtils.dpToPx(getContext(), height);
221
+        setLayoutParams(lp);
222
+    }
216
 }
223
 }

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

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.View;
12
 import android.view.View;
13
+import android.view.ViewGroup;
13
 import android.widget.RelativeLayout;
14
 import android.widget.RelativeLayout;
14
 import android.widget.TextView;
15
 import android.widget.TextView;
15
 
16
 
23
 import com.reactnativenavigation.parse.params.Color;
24
 import com.reactnativenavigation.parse.params.Color;
24
 import com.reactnativenavigation.parse.params.Number;
25
 import com.reactnativenavigation.parse.params.Number;
25
 import com.reactnativenavigation.utils.CompatUtils;
26
 import com.reactnativenavigation.utils.CompatUtils;
27
+import com.reactnativenavigation.utils.UiUtils;
28
+import com.reactnativenavigation.utils.ViewUtils;
26
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
29
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
27
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
30
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
28
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
31
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
70
         return new TitleBar(context, buttonCreator, reactViewCreator, onClickListener);
73
         return new TitleBar(context, buttonCreator, reactViewCreator, onClickListener);
71
     }
74
     }
72
 
75
 
76
+    public void setHeight(int height) {
77
+        ViewGroup.LayoutParams lp = getLayoutParams();
78
+        lp.height = (int) UiUtils.dpToPx(getContext(), height);
79
+        setLayoutParams(lp);
80
+    }
81
+
82
+    public void setTitleHeight(int height) {
83
+        titleBar.setHeight(height);
84
+    }
85
+
73
     public void setTitle(String title) {
86
     public void setTitle(String title) {
74
         titleBar.setTitle(title);
87
         titleBar.setTitle(title);
75
     }
88
     }
125
     public void setBackgroundComponent(Component component) {
138
     public void setBackgroundComponent(Component component) {
126
         if (component.hasValue()) {
139
         if (component.hasValue()) {
127
             topBarBackgroundViewController.setComponent(component);
140
             topBarBackgroundViewController.setComponent(component);
128
-            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, getHeight());
141
+            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, ViewUtils.getPreferredHeight(this));
129
             root.addView(topBarBackgroundViewController.getView(), 0, lp);
142
             root.addView(topBarBackgroundViewController.getView(), 0, lp);
130
         }
143
         }
131
     }
144
     }
213
         if (visibility == View.GONE) {
226
         if (visibility == View.GONE) {
214
             this.parentView.removeView(this);
227
             this.parentView.removeView(this);
215
         } else if (visibility == View.VISIBLE && this.getParent() == null) {
228
         } else if (visibility == View.VISIBLE && this.getParent() == null) {
216
-            this.parentView.addView(this, MATCH_PARENT, WRAP_CONTENT);
229
+            this.parentView.addView(this);
217
         }
230
         }
218
     }
231
     }
219
 
232