|
@@ -4,7 +4,6 @@ import android.app.Activity;
|
4
|
4
|
import android.graphics.Color;
|
5
|
5
|
import android.graphics.drawable.Drawable;
|
6
|
6
|
import android.support.annotation.NonNull;
|
7
|
|
-import android.view.View;
|
8
|
7
|
import android.view.ViewGroup;
|
9
|
8
|
import android.widget.RelativeLayout;
|
10
|
9
|
|
|
@@ -32,7 +31,6 @@ import static com.reactnativenavigation.parse.DEFAULT_VALUES.NO_INT_VALUE;
|
32
|
31
|
public class BottomTabsController extends ParentController implements AHBottomNavigation.OnTabSelectedListener, NavigationOptionsListener {
|
33
|
32
|
private BottomTabs bottomTabs;
|
34
|
33
|
private List<ViewController> tabs = new ArrayList<>();
|
35
|
|
- private int selectedIndex = 0;
|
36
|
34
|
private ImageLoader imageLoader;
|
37
|
35
|
|
38
|
36
|
public BottomTabsController(final Activity activity, ImageLoader imageLoader, final String id, Options initialOptions) {
|
|
@@ -54,21 +52,16 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
54
|
52
|
|
55
|
53
|
@Override
|
56
|
54
|
public boolean handleBack() {
|
57
|
|
- return !tabs.isEmpty() && tabs.get(selectedIndex).handleBack();
|
|
55
|
+ return !tabs.isEmpty() && tabs.get(bottomTabs.getCurrentItem()).handleBack();
|
58
|
56
|
}
|
59
|
57
|
|
60
|
58
|
@Override
|
61
|
59
|
public boolean onTabSelected(int index, boolean wasSelected) {
|
|
60
|
+ if (wasSelected) return false;
|
62
|
61
|
selectTabAtIndex(index);
|
63
|
62
|
return true;
|
64
|
63
|
}
|
65
|
64
|
|
66
|
|
- void selectTabAtIndex(final int newIndex) {
|
67
|
|
- tabs.get(selectedIndex).getView().setVisibility(View.GONE);
|
68
|
|
- selectedIndex = newIndex;
|
69
|
|
- tabs.get(selectedIndex).getView().setVisibility(View.VISIBLE);
|
70
|
|
- }
|
71
|
|
-
|
72
|
65
|
public void setTabs(final List<ViewController> tabs) {
|
73
|
66
|
if (tabs.size() > 5) {
|
74
|
67
|
throw new RuntimeException("Too many tabs!");
|
|
@@ -76,12 +69,12 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
76
|
69
|
this.tabs = tabs;
|
77
|
70
|
getView();
|
78
|
71
|
for (int i = 0; i < tabs.size(); i++) {
|
79
|
|
- createTab(i, tabs.get(i), tabs.get(i).options.bottomTabOptions, tabs.get(i).options.bottomTabsOptions);
|
|
72
|
+ createTab(i, tabs.get(i).options.bottomTabOptions, tabs.get(i).options.bottomTabsOptions);
|
80
|
73
|
}
|
81
|
74
|
selectTabAtIndex(0);
|
82
|
75
|
}
|
83
|
76
|
|
84
|
|
- private void createTab(int index, ViewController tab, final BottomTabOptions tabOptions, final BottomTabsOptions bottomTabsOptions) {
|
|
77
|
+ private void createTab(int index, final BottomTabOptions tabOptions, final BottomTabsOptions bottomTabsOptions) {
|
85
|
78
|
if (!tabOptions.icon.hasValue()) {
|
86
|
79
|
throw new RuntimeException("BottomTab must have an icon");
|
87
|
80
|
}
|
|
@@ -102,8 +95,6 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
102
|
95
|
|
103
|
96
|
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
104
|
97
|
params.addRule(ABOVE, bottomTabs.getId());
|
105
|
|
- tab.getView().setVisibility(View.GONE);
|
106
|
|
- getView().addView(tab.getView(), params);
|
107
|
98
|
}
|
108
|
99
|
|
109
|
100
|
private void setIconColor(Drawable drawable, BottomTabsOptions options) {
|
|
@@ -111,7 +102,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
111
|
102
|
}
|
112
|
103
|
|
113
|
104
|
int getSelectedIndex() {
|
114
|
|
- return selectedIndex;
|
|
105
|
+ return bottomTabs.getCurrentItem();
|
115
|
106
|
}
|
116
|
107
|
|
117
|
108
|
@NonNull
|
|
@@ -140,7 +131,18 @@ public class BottomTabsController extends ParentController implements AHBottomNa
|
140
|
131
|
}
|
141
|
132
|
}
|
142
|
133
|
|
143
|
|
- private boolean hasControlWithId(StackController controller, String id) {
|
|
134
|
+ void selectTabAtIndex(final int newIndex) {
|
|
135
|
+ getView().removeView(getCurrentView());
|
|
136
|
+ bottomTabs.setCurrentItem(newIndex, false);
|
|
137
|
+ getView().addView(getCurrentView());
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ @NonNull
|
|
141
|
+ private ViewGroup getCurrentView() {
|
|
142
|
+ return tabs.get(bottomTabs.getCurrentItem()).getView();
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ private boolean hasControlWithId(StackController controller, String id) {
|
144
|
146
|
for (ViewController child : controller.getChildControllers()) {
|
145
|
147
|
if (id.equals(child.getId())) {
|
146
|
148
|
return true;
|