|
@@ -1,8 +1,10 @@
|
1
|
1
|
package com.reactnativenavigation.presentation;
|
2
|
2
|
|
|
3
|
+import android.graphics.Color;
|
3
|
4
|
import android.view.ViewGroup;
|
4
|
5
|
import android.view.ViewGroup.MarginLayoutParams;
|
5
|
6
|
|
|
7
|
+import com.aurelhubert.ahbottomnavigation.AHBottomNavigation.TitleState;
|
6
|
8
|
import com.reactnativenavigation.anim.BottomTabsAnimator;
|
7
|
9
|
import com.reactnativenavigation.parse.AnimationsOptions;
|
8
|
10
|
import com.reactnativenavigation.parse.BottomTabsOptions;
|
|
@@ -50,13 +52,54 @@ public class BottomTabsOptionsPresenter {
|
50
|
52
|
applyBottomTabsOptions(withDefaultOptions.bottomTabsOptions, withDefaultOptions.animations);
|
51
|
53
|
}
|
52
|
54
|
|
53
|
|
- public void presentChildOptions(Options options, Component child) {
|
|
55
|
+ public void applyChildOptions(Options options, Component child) {
|
54
|
56
|
Options withDefaultOptions = options.copy().withDefaultOptions(defaultOptions);
|
55
|
57
|
applyBottomTabsOptions(withDefaultOptions.bottomTabsOptions, withDefaultOptions.animations);
|
56
|
58
|
int tabIndex = bottomTabFinder.findByComponent(child);
|
57
|
59
|
applyDrawBehind(withDefaultOptions.bottomTabsOptions, tabIndex);
|
58
|
60
|
}
|
59
|
61
|
|
|
62
|
+ public void mergeChildOptions(Options options, Component child) {
|
|
63
|
+ Options withDefault = options.copy().withDefaultOptions(defaultOptions);
|
|
64
|
+ mergeBottomTabsOptions(withDefault.bottomTabsOptions, withDefault.animations);
|
|
65
|
+ int tabIndex = bottomTabFinder.findByComponent(child);
|
|
66
|
+ mergeDrawBehind(withDefault.bottomTabsOptions, tabIndex);
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ private void mergeBottomTabsOptions(BottomTabsOptions options, AnimationsOptions animations) {
|
|
70
|
+ if (options.titleDisplayMode.hasValue()) {
|
|
71
|
+ bottomTabs.setTitleState(options.titleDisplayMode.toState());
|
|
72
|
+ }
|
|
73
|
+ if (options.backgroundColor.hasValue()) {
|
|
74
|
+ bottomTabs.setBackgroundColor(options.backgroundColor.get());
|
|
75
|
+ }
|
|
76
|
+ if (options.currentTabIndex.hasValue()) {
|
|
77
|
+ int tabIndex = options.currentTabIndex.get();
|
|
78
|
+ if (tabIndex >= 0) tabSelector.selectTab(tabIndex);
|
|
79
|
+ }
|
|
80
|
+ if (options.testId.hasValue()) {
|
|
81
|
+ bottomTabs.setTag(options.testId.get());
|
|
82
|
+ }
|
|
83
|
+ if (options.currentTabId.hasValue()) {
|
|
84
|
+ int tabIndex = bottomTabFinder.findByControllerId(options.currentTabId.get());
|
|
85
|
+ if (tabIndex >= 0) tabSelector.selectTab(tabIndex);
|
|
86
|
+ }
|
|
87
|
+ if (options.visible.isTrueOrUndefined()) {
|
|
88
|
+ if (options.animate.isTrueOrUndefined()) {
|
|
89
|
+ animator.show(animations);
|
|
90
|
+ } else {
|
|
91
|
+ bottomTabs.restoreBottomNavigation(false);
|
|
92
|
+ }
|
|
93
|
+ }
|
|
94
|
+ if (options.visible.isFalse()) {
|
|
95
|
+ if (options.animate.isTrueOrUndefined()) {
|
|
96
|
+ animator.hide(animations);
|
|
97
|
+ } else {
|
|
98
|
+ bottomTabs.hideBottomNavigation(false);
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+ }
|
|
102
|
+
|
60
|
103
|
private void applyDrawBehind(BottomTabsOptions options, int tabIndex) {
|
61
|
104
|
ViewGroup tab = tabs.get(tabIndex).getView();
|
62
|
105
|
MarginLayoutParams lp = (MarginLayoutParams) tab.getLayoutParams();
|
|
@@ -72,20 +115,29 @@ public class BottomTabsOptionsPresenter {
|
72
|
115
|
}
|
73
|
116
|
}
|
74
|
117
|
|
75
|
|
- private void applyBottomTabsOptions(BottomTabsOptions options, AnimationsOptions animationsOptions) {
|
76
|
|
- if (options.titleDisplayMode.hasValue()) {
|
77
|
|
- bottomTabs.setTitleState(options.titleDisplayMode.toState());
|
|
118
|
+ private void mergeDrawBehind(BottomTabsOptions options, int tabIndex) {
|
|
119
|
+ ViewGroup tab = tabs.get(tabIndex).getView();
|
|
120
|
+ MarginLayoutParams lp = (MarginLayoutParams) tab.getLayoutParams();
|
|
121
|
+ if (options.drawBehind.isTrue()) {
|
|
122
|
+ lp.bottomMargin = 0;
|
78
|
123
|
}
|
79
|
|
- if (options.backgroundColor.hasValue()) {
|
80
|
|
- bottomTabs.setBackgroundColor(options.backgroundColor.get());
|
|
124
|
+ if (options.visible.isTrue() && options.drawBehind.isFalse()) {
|
|
125
|
+ if (bottomTabs.getHeight() == 0) {
|
|
126
|
+ UiUtils.runOnPreDrawOnce(bottomTabs, () -> lp.bottomMargin = bottomTabs.getHeight());
|
|
127
|
+ } else {
|
|
128
|
+ lp.bottomMargin = bottomTabs.getHeight();
|
|
129
|
+ }
|
81
|
130
|
}
|
|
131
|
+ }
|
|
132
|
+
|
|
133
|
+ private void applyBottomTabsOptions(BottomTabsOptions options, AnimationsOptions animationsOptions) {
|
|
134
|
+ bottomTabs.setTitleState(options.titleDisplayMode.get(TitleState.SHOW_WHEN_ACTIVE));
|
|
135
|
+ bottomTabs.setBackgroundColor(options.backgroundColor.get(Color.WHITE));
|
82
|
136
|
if (options.currentTabIndex.hasValue()) {
|
83
|
137
|
int tabIndex = options.currentTabIndex.get();
|
84
|
138
|
if (tabIndex >= 0) tabSelector.selectTab(tabIndex);
|
85
|
139
|
}
|
86
|
|
- if (options.testId.hasValue()) {
|
87
|
|
- bottomTabs.setTag(options.testId.get());
|
88
|
|
- }
|
|
140
|
+ if (options.testId.hasValue()) bottomTabs.setTag(options.testId.get());
|
89
|
141
|
if (options.currentTabId.hasValue()) {
|
90
|
142
|
int tabIndex = bottomTabFinder.findByControllerId(options.currentTabId.get());
|
91
|
143
|
if (tabIndex >= 0) tabSelector.selectTab(tabIndex);
|