|
@@ -1,6 +1,7 @@
|
1
|
1
|
package com.reactnativenavigation.layouts;
|
2
|
2
|
|
3
|
3
|
import android.support.annotation.NonNull;
|
|
4
|
+import android.support.annotation.Nullable;
|
4
|
5
|
import android.support.v7.app.AppCompatActivity;
|
5
|
6
|
import android.view.View;
|
6
|
7
|
import android.widget.RelativeLayout;
|
|
@@ -8,10 +9,12 @@ import android.widget.RelativeLayout;
|
8
|
9
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
|
9
|
10
|
import com.reactnativenavigation.params.ActivityParams;
|
10
|
11
|
import com.reactnativenavigation.params.ScreenParams;
|
|
12
|
+import com.reactnativenavigation.params.SideMenuParams;
|
11
|
13
|
import com.reactnativenavigation.params.TitleBarButtonParams;
|
12
|
14
|
import com.reactnativenavigation.params.TitleBarLeftButtonParams;
|
13
|
15
|
import com.reactnativenavigation.screens.ScreenStack;
|
14
|
16
|
import com.reactnativenavigation.views.BottomTabs;
|
|
17
|
+import com.reactnativenavigation.views.SideMenu;
|
15
|
18
|
|
16
|
19
|
import java.util.List;
|
17
|
20
|
|
|
@@ -24,23 +27,37 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
|
24
|
27
|
private ActivityParams params;
|
25
|
28
|
private BottomTabs bottomTabs;
|
26
|
29
|
private ScreenStack[] screenStacks;
|
|
30
|
+ private final SideMenuParams sideMenuParams;
|
|
31
|
+ private @Nullable SideMenu sideMenu;
|
27
|
32
|
private int currentStackIndex = 0;
|
28
|
33
|
|
29
|
34
|
public BottomTabsLayout(AppCompatActivity activity, ActivityParams params) {
|
30
|
35
|
super(activity);
|
31
|
36
|
this.activity = activity;
|
32
|
37
|
this.params = params;
|
|
38
|
+ this.sideMenuParams = params.sideMenuParams;
|
33
|
39
|
screenStacks = new ScreenStack[params.tabParams.size()];
|
34
|
40
|
createLayout();
|
35
|
41
|
}
|
36
|
42
|
|
37
|
43
|
private void createLayout() {
|
|
44
|
+ createSideMenu();
|
38
|
45
|
createBottomTabs();
|
39
|
|
- addBottomTabsToScreen();
|
|
46
|
+ addBottomTabs();
|
40
|
47
|
addScreenStacks();
|
41
|
48
|
showInitialScreenStack();
|
42
|
49
|
}
|
43
|
50
|
|
|
51
|
+ private void createSideMenu() {
|
|
52
|
+ if (sideMenuParams == null) {
|
|
53
|
+ return;
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ sideMenu = new SideMenu(getContext(), sideMenuParams);
|
|
57
|
+ RelativeLayout.LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
|
58
|
+ addView(sideMenu, lp);
|
|
59
|
+ }
|
|
60
|
+
|
44
|
61
|
private void addScreenStacks() {
|
45
|
62
|
for (int i = 0; i < screenStacks.length; i++) {
|
46
|
63
|
createAndAddScreens(i);
|
|
@@ -48,12 +65,16 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
|
48
|
65
|
}
|
49
|
66
|
|
50
|
67
|
private void createAndAddScreens(int position) {
|
51
|
|
- ScreenStack newStack = new ScreenStack(activity, this, this);
|
|
68
|
+ ScreenStack newStack = new ScreenStack(activity, getContentContainer(), this);
|
52
|
69
|
ScreenParams screenParams = params.tabParams.get(position);
|
53
|
70
|
newStack.pushInitialScreen(screenParams, createScreenLayoutParams(screenParams));
|
54
|
71
|
screenStacks[position] = newStack;
|
55
|
72
|
}
|
56
|
73
|
|
|
74
|
+ private RelativeLayout getContentContainer() {
|
|
75
|
+ return sideMenu == null ? this : sideMenu.getContentContainer();
|
|
76
|
+ }
|
|
77
|
+
|
57
|
78
|
@NonNull
|
58
|
79
|
private LayoutParams createScreenLayoutParams(ScreenParams params) {
|
59
|
80
|
LayoutParams lp = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
|
@@ -68,10 +89,10 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
|
68
|
89
|
bottomTabs.addTabs(params.tabParams, this);
|
69
|
90
|
}
|
70
|
91
|
|
71
|
|
- private void addBottomTabsToScreen() {
|
|
92
|
+ private void addBottomTabs() {
|
72
|
93
|
LayoutParams lp = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
|
73
|
94
|
lp.addRule(ALIGN_PARENT_BOTTOM);
|
74
|
|
- addView(bottomTabs, lp);
|
|
95
|
+ getContentContainer().addView(bottomTabs, lp);
|
75
|
96
|
}
|
76
|
97
|
|
77
|
98
|
private void showInitialScreenStack() {
|
|
@@ -128,12 +149,16 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
|
128
|
149
|
|
129
|
150
|
@Override
|
130
|
151
|
public void toggleSideMenuVisible(boolean animated) {
|
131
|
|
-
|
|
152
|
+ if (sideMenu != null) {
|
|
153
|
+ sideMenu.toggleVisible(animated);
|
|
154
|
+ }
|
132
|
155
|
}
|
133
|
156
|
|
134
|
157
|
@Override
|
135
|
158
|
public void setSideMenuVisible(boolean animated, boolean visible) {
|
136
|
|
-
|
|
159
|
+ if (sideMenu != null) {
|
|
160
|
+ sideMenu.setVisible(visible, animated);
|
|
161
|
+ }
|
137
|
162
|
}
|
138
|
163
|
|
139
|
164
|
@Override
|
|
@@ -177,6 +202,10 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
|
177
|
202
|
for (ScreenStack screenStack : screenStacks) {
|
178
|
203
|
screenStack.destroy();
|
179
|
204
|
}
|
|
205
|
+
|
|
206
|
+ if (sideMenu != null) {
|
|
207
|
+ sideMenu.destroy();
|
|
208
|
+ }
|
180
|
209
|
}
|
181
|
210
|
|
182
|
211
|
@Override
|
|
@@ -225,6 +254,8 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
|
225
|
254
|
|
226
|
255
|
@Override
|
227
|
256
|
public void onSideMenuButtonClick() {
|
228
|
|
-
|
|
257
|
+ if (sideMenu != null) {
|
|
258
|
+ sideMenu.openDrawer();
|
|
259
|
+ }
|
229
|
260
|
}
|
230
|
261
|
}
|