|
@@ -1,7 +1,6 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers.bottomtabs;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
|
-import android.graphics.drawable.Drawable;
|
5
|
4
|
import android.support.annotation.NonNull;
|
6
|
5
|
import android.support.annotation.RestrictTo;
|
7
|
6
|
import android.view.View;
|
|
@@ -18,20 +17,20 @@ import com.reactnativenavigation.presentation.Presenter;
|
18
|
17
|
import com.reactnativenavigation.react.EventEmitter;
|
19
|
18
|
import com.reactnativenavigation.utils.CommandListener;
|
20
|
19
|
import com.reactnativenavigation.utils.ImageLoader;
|
21
|
|
-import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
|
22
|
20
|
import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
|
23
|
21
|
import com.reactnativenavigation.viewcontrollers.ParentController;
|
24
|
22
|
import com.reactnativenavigation.viewcontrollers.ViewController;
|
25
|
23
|
import com.reactnativenavigation.views.BottomTabs;
|
26
|
24
|
import com.reactnativenavigation.views.Component;
|
27
|
25
|
|
28
|
|
-import java.util.ArrayList;
|
29
|
26
|
import java.util.Collection;
|
30
|
27
|
import java.util.List;
|
31
|
28
|
|
32
|
29
|
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
33
|
30
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
34
|
31
|
import static android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM;
|
|
32
|
+import static com.reactnativenavigation.utils.CollectionUtils.forEach;
|
|
33
|
+import static com.reactnativenavigation.utils.CollectionUtils.map;
|
35
|
34
|
|
36
|
35
|
public class BottomTabsController extends ParentController implements AHBottomNavigation.OnTabSelectedListener, TabSelector {
|
37
|
36
|
|
|
@@ -49,6 +48,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
49
|
48
|
this.imageLoader = imageLoader;
|
50
|
49
|
this.presenter = bottomTabsPresenter;
|
51
|
50
|
this.tabPresenter = bottomTabPresenter;
|
|
51
|
+ forEach(tabs, (tab) -> tab.setParentController(this));
|
52
|
52
|
}
|
53
|
53
|
|
54
|
54
|
@Override
|
|
@@ -62,22 +62,30 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
62
|
62
|
@Override
|
63
|
63
|
protected ViewGroup createView() {
|
64
|
64
|
RelativeLayout root = new RelativeLayout(getActivity());
|
65
|
|
- bottomTabs = new BottomTabs(getActivity());
|
|
65
|
+ bottomTabs = createBottomTabs();
|
66
|
66
|
presenter.bindView(bottomTabs, this);
|
67
|
67
|
tabPresenter.bindView(bottomTabs);
|
68
|
68
|
bottomTabs.setOnTabSelectedListener(this);
|
69
|
69
|
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
|
70
|
70
|
lp.addRule(ALIGN_PARENT_BOTTOM);
|
71
|
71
|
root.addView(bottomTabs, lp);
|
72
|
|
- createTabs(root);
|
73
|
|
- return root;
|
|
72
|
+ bottomTabs.addItems(createTabs());
|
|
73
|
+ attachTabs(root);
|
|
74
|
+ return root;
|
74
|
75
|
}
|
75
|
76
|
|
|
77
|
+ @NonNull
|
|
78
|
+ protected BottomTabs createBottomTabs() {
|
|
79
|
+ return new BottomTabs(getActivity());
|
|
80
|
+ }
|
|
81
|
+
|
76
|
82
|
@Override
|
77
|
83
|
public void applyOptions(Options options) {
|
78
|
84
|
super.applyOptions(options);
|
79
|
|
- presenter.present(options);
|
80
|
|
- tabPresenter.present();
|
|
85
|
+ bottomTabs.disableItemsCreation();
|
|
86
|
+ presenter.applyOptions(options);
|
|
87
|
+ tabPresenter.applyOptions();
|
|
88
|
+ bottomTabs.enableItemsCreation();
|
81
|
89
|
this.options.bottomTabsOptions.clearOneTimeOptions();
|
82
|
90
|
this.initialOptions.bottomTabsOptions.clearOneTimeOptions();
|
83
|
91
|
}
|
|
@@ -135,43 +143,15 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
135
|
143
|
return false;
|
136
|
144
|
}
|
137
|
145
|
|
138
|
|
- private void createTabs(RelativeLayout root) {
|
139
|
|
- if (tabs.size() > 5) {
|
140
|
|
- throw new RuntimeException("Too many tabs!");
|
141
|
|
- }
|
142
|
|
- List<String> icons = new ArrayList<>();
|
143
|
|
- List<BottomTabOptions> bottomTabOptionsList = new ArrayList<>();
|
144
|
|
- for (int i = 0; i < tabs.size(); i++) {
|
145
|
|
- tabs.get(i).setParentController(this);
|
146
|
|
- BottomTabOptions tabOptions = tabs.get(i).resolveCurrentOptions().bottomTabOptions;
|
147
|
|
- if (!tabOptions.icon.hasValue()) {
|
148
|
|
- throw new RuntimeException("BottomTab must have an icon");
|
149
|
|
- }
|
150
|
|
- bottomTabOptionsList.add(tabOptions);
|
151
|
|
- icons.add(tabOptions.icon.get());
|
152
|
|
- }
|
153
|
|
-
|
154
|
|
- imageLoader.loadIcons(getActivity(), icons, new ImageLoadingListenerAdapter() {
|
155
|
|
-
|
156
|
|
- @Override
|
157
|
|
- public void onComplete(@NonNull List<Drawable> drawables) {
|
158
|
|
- List<AHBottomNavigationItem> tabs = new ArrayList<>();
|
159
|
|
- for (int i = 0; i < drawables.size(); i++) {
|
160
|
|
- tabs.add(new AHBottomNavigationItem(bottomTabOptionsList.get(i).text.get(""), drawables.get(i)));
|
161
|
|
- }
|
162
|
|
- bottomTabs.addItems(tabs);
|
163
|
|
- bottomTabs.post(() -> {
|
164
|
|
- for (int i = 0; i < bottomTabOptionsList.size(); i++) {
|
165
|
|
- bottomTabs.setTabTestId(i, bottomTabOptionsList.get(i).testId);
|
166
|
|
- }
|
167
|
|
- });
|
168
|
|
- attachTabs(root);
|
169
|
|
- }
|
170
|
|
-
|
171
|
|
- @Override
|
172
|
|
- public void onError(Throwable error) {
|
173
|
|
- error.printStackTrace();
|
174
|
|
- }
|
|
146
|
+ private List<AHBottomNavigationItem> createTabs() {
|
|
147
|
+ if (tabs.size() > 5) throw new RuntimeException("Too many tabs!");
|
|
148
|
+ return map(tabs, tab -> {
|
|
149
|
+ BottomTabOptions options = tab.resolveCurrentOptions().bottomTabOptions;
|
|
150
|
+ return new AHBottomNavigationItem(
|
|
151
|
+ options.text.get(""),
|
|
152
|
+ imageLoader.loadIcon(getActivity(), options.icon.get()),
|
|
153
|
+ options.testId.get("")
|
|
154
|
+ );
|
175
|
155
|
});
|
176
|
156
|
}
|
177
|
157
|
|