|
@@ -1,8 +1,7 @@
|
1
|
|
-package com.reactnativenavigation.viewcontrollers;
|
|
1
|
+package com.reactnativenavigation.viewcontrollers.bottomtabs;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
4
|
import android.graphics.drawable.Drawable;
|
5
|
|
-import android.support.annotation.IntRange;
|
6
|
5
|
import android.support.annotation.NonNull;
|
7
|
6
|
import android.view.ViewGroup;
|
8
|
7
|
import android.widget.RelativeLayout;
|
|
@@ -11,10 +10,11 @@ import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
|
11
|
10
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
|
12
|
11
|
import com.reactnativenavigation.parse.BottomTabOptions;
|
13
|
12
|
import com.reactnativenavigation.parse.Options;
|
14
|
|
-import com.reactnativenavigation.parse.params.Text;
|
15
|
|
-import com.reactnativenavigation.presentation.BottomTabOptionsPresenter;
|
|
13
|
+import com.reactnativenavigation.presentation.BottomTabsOptionsPresenter;
|
16
|
14
|
import com.reactnativenavigation.presentation.NavigationOptionsListener;
|
17
|
15
|
import com.reactnativenavigation.utils.ImageLoader;
|
|
16
|
+import com.reactnativenavigation.viewcontrollers.ParentController;
|
|
17
|
+import com.reactnativenavigation.viewcontrollers.ViewController;
|
18
|
18
|
import com.reactnativenavigation.views.BottomTabs;
|
19
|
19
|
import com.reactnativenavigation.views.ReactComponent;
|
20
|
20
|
|
|
@@ -31,6 +31,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
31
|
31
|
private BottomTabs bottomTabs;
|
32
|
32
|
private List<ViewController> tabs = new ArrayList<>();
|
33
|
33
|
private ImageLoader imageLoader;
|
|
34
|
+ private BottomTabFinder bottomTabFinder = new BottomTabFinder();
|
34
|
35
|
|
35
|
36
|
public BottomTabsController(final Activity activity, ImageLoader imageLoader, final String id, Options initialOptions) {
|
36
|
37
|
super(activity, id, initialOptions);
|
|
@@ -52,14 +53,14 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
52
|
53
|
@Override
|
53
|
54
|
public void applyOptions(Options options) {
|
54
|
55
|
super.applyOptions(options);
|
55
|
|
- new BottomTabOptionsPresenter(bottomTabs).present(options);
|
|
56
|
+ new BottomTabsOptionsPresenter(bottomTabs, bottomTabFinder).present(options);
|
56
|
57
|
}
|
57
|
58
|
|
58
|
59
|
@Override
|
59
|
60
|
public void applyOptions(Options options, ReactComponent childComponent) {
|
60
|
61
|
super.applyOptions(options, childComponent);
|
61
|
|
- int tabIndex = findTabContainingComponent(childComponent);
|
62
|
|
- if (tabIndex >= 0) new BottomTabOptionsPresenter(bottomTabs).present(options, tabIndex);
|
|
62
|
+ int tabIndex = bottomTabFinder.findByComponent(childComponent);
|
|
63
|
+ if (tabIndex >= 0) new BottomTabsOptionsPresenter(bottomTabs, bottomTabFinder).present(this.options, tabIndex);
|
63
|
64
|
applyOnParentController(parentController ->
|
64
|
65
|
((ParentController) parentController).applyOptions(this.options.copy().clearBottomTabsOptions().clearBottomTabOptions(), childComponent)
|
65
|
66
|
);
|
|
@@ -91,7 +92,8 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
91
|
92
|
throw new RuntimeException("Too many tabs!");
|
92
|
93
|
}
|
93
|
94
|
this.tabs = tabs;
|
94
|
|
- getView();
|
|
95
|
+ bottomTabFinder.setTabs(tabs);
|
|
96
|
+ getView();
|
95
|
97
|
for (int i = 0; i < tabs.size(); i++) {
|
96
|
98
|
tabs.get(i).setParentController(this);
|
97
|
99
|
createTab(i, tabs.get(i).options.bottomTabOptions);
|
|
@@ -121,7 +123,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
121
|
123
|
params.addRule(ABOVE, bottomTabs.getId());
|
122
|
124
|
}
|
123
|
125
|
|
124
|
|
- int getSelectedIndex() {
|
|
126
|
+ public int getSelectedIndex() {
|
125
|
127
|
return bottomTabs.getCurrentItem();
|
126
|
128
|
}
|
127
|
129
|
|
|
@@ -134,25 +136,10 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
134
|
136
|
@Override
|
135
|
137
|
public void mergeOptions(Options options) {
|
136
|
138
|
this.options = this.options.mergeWith(options);
|
137
|
|
- if (options.bottomTabsOptions.currentTabIndex.hasValue()) {
|
138
|
|
- selectTabAtIndex(options.bottomTabsOptions.currentTabIndex.get());
|
139
|
|
- }
|
140
|
|
- if (options.bottomTabsOptions.currentTabId.hasValue()) {
|
141
|
|
- Text id = options.bottomTabsOptions.currentTabId;
|
142
|
|
- for (ViewController controller : tabs) {
|
143
|
|
- if (controller.getId().equals(id.get())) {
|
144
|
|
- selectTabAtIndex(tabs.indexOf(controller));
|
145
|
|
- }
|
146
|
|
- if (controller instanceof StackController) {
|
147
|
|
- if (hasControlWithId((StackController) controller, id.get())) {
|
148
|
|
- selectTabAtIndex(tabs.indexOf(controller));
|
149
|
|
- }
|
150
|
|
- }
|
151
|
|
- }
|
152
|
|
- }
|
|
139
|
+ new BottomTabsOptionsPresenter(bottomTabs, bottomTabFinder).present(this.options);
|
153
|
140
|
}
|
154
|
141
|
|
155
|
|
- void selectTabAtIndex(final int newIndex) {
|
|
142
|
+ public void selectTabAtIndex(final int newIndex) {
|
156
|
143
|
getView().removeView(getCurrentView());
|
157
|
144
|
bottomTabs.setCurrentItem(newIndex, false);
|
158
|
145
|
getView().addView(getCurrentView());
|
|
@@ -162,26 +149,4 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
162
|
149
|
private ViewGroup getCurrentView() {
|
163
|
150
|
return tabs.get(bottomTabs.getCurrentItem()).getView();
|
164
|
151
|
}
|
165
|
|
-
|
166
|
|
- private boolean hasControlWithId(StackController controller, String id) {
|
167
|
|
- for (ViewController child : controller.getChildControllers()) {
|
168
|
|
- if (id.equals(child.getId())) {
|
169
|
|
- return true;
|
170
|
|
- }
|
171
|
|
- if (child instanceof StackController) {
|
172
|
|
- return hasControlWithId((StackController) child, id);
|
173
|
|
- }
|
174
|
|
- }
|
175
|
|
- return false;
|
176
|
|
- }
|
177
|
|
-
|
178
|
|
- @IntRange(from = -1)
|
179
|
|
- private int findTabContainingComponent(ReactComponent component) {
|
180
|
|
- for (int i = 0; i < tabs.size(); i++) {
|
181
|
|
- if (tabs.get(i).containsComponent(component)) {
|
182
|
|
- return i;
|
183
|
|
- }
|
184
|
|
- }
|
185
|
|
- return -1;
|
186
|
|
- }
|
187
|
152
|
}
|