|
@@ -1,7 +1,6 @@
|
1
|
1
|
package com.reactnativenavigation.viewcontrollers;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
|
-import android.graphics.Color;
|
5
|
4
|
import android.graphics.drawable.Drawable;
|
6
|
5
|
import android.support.annotation.IntRange;
|
7
|
6
|
import android.support.annotation.NonNull;
|
|
@@ -11,13 +10,11 @@ import android.widget.RelativeLayout;
|
11
|
10
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
|
12
|
11
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
|
13
|
12
|
import com.reactnativenavigation.parse.BottomTabOptions;
|
14
|
|
-import com.reactnativenavigation.parse.BottomTabsOptions;
|
15
|
13
|
import com.reactnativenavigation.parse.Options;
|
16
|
14
|
import com.reactnativenavigation.parse.Text;
|
17
|
15
|
import com.reactnativenavigation.presentation.BottomTabOptionsPresenter;
|
18
|
16
|
import com.reactnativenavigation.presentation.NavigationOptionsListener;
|
19
|
17
|
import com.reactnativenavigation.utils.ImageLoader;
|
20
|
|
-import com.reactnativenavigation.utils.UiUtils;
|
21
|
18
|
import com.reactnativenavigation.views.BottomTabs;
|
22
|
19
|
import com.reactnativenavigation.views.ReactComponent;
|
23
|
20
|
|
|
@@ -29,7 +26,6 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
29
|
26
|
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
|
30
|
27
|
import static android.widget.RelativeLayout.ABOVE;
|
31
|
28
|
import static android.widget.RelativeLayout.ALIGN_PARENT_BOTTOM;
|
32
|
|
-import static com.reactnativenavigation.parse.DEFAULT_VALUES.NO_INT_VALUE;
|
33
|
29
|
|
34
|
30
|
public class BottomTabsController extends ParentController implements AHBottomNavigation.OnTabSelectedListener, NavigationOptionsListener {
|
35
|
31
|
private BottomTabs bottomTabs;
|
|
@@ -45,7 +41,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
45
|
41
|
@Override
|
46
|
42
|
protected ViewGroup createView() {
|
47
|
43
|
RelativeLayout root = new RelativeLayout(getActivity());
|
48
|
|
- bottomTabs = new BottomTabs(getActivity(), options.bottomTabsOptions);
|
|
44
|
+ bottomTabs = new BottomTabs(getActivity());
|
49
|
45
|
bottomTabs.setOnTabSelectedListener(this);
|
50
|
46
|
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT);
|
51
|
47
|
lp.addRule(ALIGN_PARENT_BOTTOM);
|
|
@@ -53,6 +49,12 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
53
|
49
|
return root;
|
54
|
50
|
}
|
55
|
51
|
|
|
52
|
+ @Override
|
|
53
|
+ public void applyOptions(Options options) {
|
|
54
|
+ super.applyOptions(options);
|
|
55
|
+ new BottomTabOptionsPresenter(bottomTabs).present(options);
|
|
56
|
+ }
|
|
57
|
+
|
56
|
58
|
@Override
|
57
|
59
|
public void applyOptions(Options options, ReactComponent childComponent) {
|
58
|
60
|
super.applyOptions(options, childComponent);
|
|
@@ -92,19 +94,18 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
92
|
94
|
getView();
|
93
|
95
|
for (int i = 0; i < tabs.size(); i++) {
|
94
|
96
|
tabs.get(i).setParentController(this);
|
95
|
|
- createTab(i, tabs.get(i).options.bottomTabOptions, tabs.get(i).options.bottomTabsOptions);
|
|
97
|
+ createTab(i, tabs.get(i).options.bottomTabOptions);
|
96
|
98
|
}
|
97
|
99
|
selectTabAtIndex(0);
|
98
|
100
|
}
|
99
|
101
|
|
100
|
|
- private void createTab(int index, final BottomTabOptions tabOptions, final BottomTabsOptions bottomTabsOptions) {
|
|
102
|
+ private void createTab(int index, final BottomTabOptions tabOptions) {
|
101
|
103
|
if (!tabOptions.icon.hasValue()) {
|
102
|
104
|
throw new RuntimeException("BottomTab must have an icon");
|
103
|
105
|
}
|
104
|
106
|
imageLoader.loadIcon(getActivity(), tabOptions.icon.get(), new ImageLoader.ImageLoadingListener() {
|
105
|
107
|
@Override
|
106
|
108
|
public void onComplete(@NonNull Drawable drawable) {
|
107
|
|
- setIconColor(drawable, bottomTabsOptions);
|
108
|
109
|
AHBottomNavigationItem item = new AHBottomNavigationItem(tabOptions.title.get(""), drawable);
|
109
|
110
|
bottomTabs.addItem(item);
|
110
|
111
|
bottomTabs.post(() -> bottomTabs.setTabTag(index, tabOptions.testId));
|
|
@@ -120,10 +121,6 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
120
|
121
|
params.addRule(ABOVE, bottomTabs.getId());
|
121
|
122
|
}
|
122
|
123
|
|
123
|
|
- private void setIconColor(Drawable drawable, BottomTabsOptions options) {
|
124
|
|
- UiUtils.tintDrawable(drawable, Color.RED);
|
125
|
|
- }
|
126
|
|
-
|
127
|
124
|
int getSelectedIndex() {
|
128
|
125
|
return bottomTabs.getCurrentItem();
|
129
|
126
|
}
|
|
@@ -137,8 +134,8 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
137
|
134
|
@Override
|
138
|
135
|
public void mergeOptions(Options options) {
|
139
|
136
|
this.options = this.options.mergeWith(options);
|
140
|
|
- if (options.bottomTabsOptions.currentTabIndex != NO_INT_VALUE) {
|
141
|
|
- selectTabAtIndex(options.bottomTabsOptions.currentTabIndex);
|
|
137
|
+ if (options.bottomTabsOptions.currentTabIndex.hasValue()) {
|
|
138
|
+ selectTabAtIndex(options.bottomTabsOptions.currentTabIndex.get());
|
142
|
139
|
}
|
143
|
140
|
if (options.bottomTabsOptions.currentTabId.hasValue()) {
|
144
|
141
|
Text id = options.bottomTabsOptions.currentTabId;
|