|
@@ -5,7 +5,11 @@ import android.graphics.drawable.Drawable;
|
5
|
5
|
import android.os.AsyncTask;
|
6
|
6
|
import android.os.Bundle;
|
7
|
7
|
import android.support.design.widget.CoordinatorLayout;
|
|
8
|
+import android.util.Log;
|
8
|
9
|
import android.view.View;
|
|
10
|
+import android.view.ViewGroup;
|
|
11
|
+import android.view.ViewTreeObserver;
|
|
12
|
+import android.widget.ScrollView;
|
9
|
13
|
|
10
|
14
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
|
11
|
15
|
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
|
|
@@ -15,6 +19,8 @@ import com.reactnativenavigation.core.RctManager;
|
15
|
19
|
import com.reactnativenavigation.core.objects.Drawer;
|
16
|
20
|
import com.reactnativenavigation.core.objects.Screen;
|
17
|
21
|
import com.reactnativenavigation.utils.StyleHelper;
|
|
22
|
+import com.reactnativenavigation.views.BottomNavigation;
|
|
23
|
+import com.reactnativenavigation.views.RctView;
|
18
|
24
|
import com.reactnativenavigation.views.RnnToolBar;
|
19
|
25
|
import com.reactnativenavigation.views.ScreenStack;
|
20
|
26
|
|
|
@@ -23,6 +29,7 @@ import java.util.HashMap;
|
23
|
29
|
import java.util.Map;
|
24
|
30
|
|
25
|
31
|
public class BottomTabActivity extends BaseReactActivity implements AHBottomNavigation.OnTabSelectedListener {
|
|
32
|
+ private static final String TAG = "BottomTabActivity";
|
26
|
33
|
public static final String DRAWER_PARAMS = "drawerParams";
|
27
|
34
|
public static final String EXTRA_SCREENS = "extraScreens";
|
28
|
35
|
|
|
@@ -36,11 +43,38 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
|
36
|
43
|
private static int DEFAULT_TAB_SELECTED_COLOR = 0xFF0000FF;
|
37
|
44
|
private static boolean DEFAULT_TAB_INACTIVE_TITLES = true;
|
38
|
45
|
|
39
|
|
- private AHBottomNavigation mBottomNavigation;
|
|
46
|
+ private BottomNavigation mBottomNavigation;
|
40
|
47
|
private CoordinatorLayout mContentFrame;
|
41
|
48
|
private ArrayList<ScreenStack> mScreenStacks;
|
42
|
49
|
private int mCurrentStackPosition = -1;
|
43
|
50
|
|
|
51
|
+ private ScrollView mScrollView;
|
|
52
|
+ private ViewTreeObserver.OnScrollChangedListener mScrollChangedListener;
|
|
53
|
+ private final View.OnAttachStateChangeListener mScrollViewStateChangeListener =
|
|
54
|
+ new View.OnAttachStateChangeListener() {
|
|
55
|
+ @Override
|
|
56
|
+ public void onViewAttachedToWindow(View v) {
|
|
57
|
+
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Override
|
|
61
|
+ public void onViewDetachedFromWindow(View detachedScrollView) {
|
|
62
|
+ detachedScrollView.getViewTreeObserver().removeOnScrollChangedListener(mScrollChangedListener);
|
|
63
|
+ detachedScrollView.removeOnAttachStateChangeListener(this);
|
|
64
|
+
|
|
65
|
+ mContentFrame.post(new Runnable() {
|
|
66
|
+ @Override
|
|
67
|
+ public void run() {
|
|
68
|
+ mScrollView = getScrollView(mContentFrame);
|
|
69
|
+ if (mScrollView != null) {
|
|
70
|
+ mScrollView.addOnAttachStateChangeListener(mScrollViewStateChangeListener);
|
|
71
|
+ addScrollListener(mScrollView);
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+ });
|
|
75
|
+ }
|
|
76
|
+ };
|
|
77
|
+
|
44
|
78
|
@Override
|
45
|
79
|
protected void handleOnCreate() {
|
46
|
80
|
super.handleOnCreate();
|
|
@@ -48,7 +82,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
|
48
|
82
|
|
49
|
83
|
setContentView(R.layout.bottom_tab_activity);
|
50
|
84
|
mToolbar = (RnnToolBar) findViewById(R.id.toolbar);
|
51
|
|
- mBottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_tab_bar);
|
|
85
|
+ mBottomNavigation = (BottomNavigation) findViewById(R.id.bottom_tab_bar);
|
52
|
86
|
mContentFrame = (CoordinatorLayout) findViewById(R.id.contentFrame);
|
53
|
87
|
|
54
|
88
|
final ArrayList<Screen> screens = (ArrayList<Screen>) getIntent().getSerializableExtra(EXTRA_SCREENS);
|
|
@@ -65,6 +99,18 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
|
65
|
99
|
setupToolbar(screens);
|
66
|
100
|
}
|
67
|
101
|
});
|
|
102
|
+
|
|
103
|
+ mContentFrame.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
|
|
104
|
+ @Override
|
|
105
|
+ public void onChildViewAdded(View parent, View child) {
|
|
106
|
+ Log.i(TAG, "onChildViewAdded: " + child.getClass());
|
|
107
|
+ }
|
|
108
|
+
|
|
109
|
+ @Override
|
|
110
|
+ public void onChildViewRemoved(View parent, View child) {
|
|
111
|
+ Log.d(TAG, "onChildViewRemoved: " + child.getClass());
|
|
112
|
+ }
|
|
113
|
+ });
|
68
|
114
|
}
|
69
|
115
|
|
70
|
116
|
private void setupPages(ArrayList<Screen> screens) {
|
|
@@ -80,8 +126,44 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
|
80
|
126
|
|
81
|
127
|
private void setupBottomTabs(Screen initialScreen) {
|
82
|
128
|
if (initialScreen.bottomTabsHiddenOnScroll) {
|
|
129
|
+ mScrollView = getScrollView(mContentFrame);
|
|
130
|
+ if (mScrollView != null) {
|
|
131
|
+ attachStateChangeListener(mScrollView);
|
|
132
|
+ addScrollListener(mScrollView);
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ private void attachStateChangeListener(ScrollView scrollView) {
|
|
138
|
+ scrollView.addOnAttachStateChangeListener(mScrollViewStateChangeListener);
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+ private void addScrollListener(final ScrollView scrollView) {
|
|
142
|
+ mScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
|
|
143
|
+ @Override
|
|
144
|
+ public void onScrollChanged() {
|
|
145
|
+ if (scrollView.getViewTreeObserver().isAlive()) {
|
|
146
|
+ Log.i(TAG, "onScrollChanged: " + scrollView.getScrollY());
|
|
147
|
+ }
|
|
148
|
+ }
|
|
149
|
+ };
|
|
150
|
+ scrollView.getViewTreeObserver().addOnScrollChangedListener(mScrollChangedListener);
|
|
151
|
+ }
|
|
152
|
+
|
|
153
|
+ private ScrollView getScrollView(ViewGroup parent) {
|
|
154
|
+ for (int i = 0; i < parent.getChildCount(); i++) {
|
|
155
|
+ View child = parent.getChildAt(i);
|
|
156
|
+
|
|
157
|
+ if (child instanceof ScrollView) {
|
|
158
|
+ return (ScrollView) child;
|
|
159
|
+ }
|
83
|
160
|
|
|
161
|
+ if (child instanceof ViewGroup) {
|
|
162
|
+ return getScrollView((ViewGroup) child);
|
|
163
|
+ }
|
84
|
164
|
}
|
|
165
|
+
|
|
166
|
+ return null;
|
85
|
167
|
}
|
86
|
168
|
|
87
|
169
|
@Override
|
|
@@ -300,9 +382,21 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
|
300
|
382
|
|
301
|
383
|
private void setTabsWithIcons(ArrayList<Screen> screens, Map<Screen, Drawable> icons) {
|
302
|
384
|
mScreenStacks = new ArrayList<>();
|
303
|
|
- for (Screen screen : screens) {
|
|
385
|
+ for (int i = 0; i < screens.size(); i++) {
|
|
386
|
+ final Screen screen = screens.get(i);
|
304
|
387
|
ScreenStack stack = new ScreenStack(this);
|
305
|
|
- stack.push(screen);
|
|
388
|
+
|
|
389
|
+ if (i == 0) {
|
|
390
|
+ stack.push(screen, new RctView.OnDisplayedListener() {
|
|
391
|
+ @Override
|
|
392
|
+ public void onDisplayed() {
|
|
393
|
+ setupBottomTabs(screen);
|
|
394
|
+ }
|
|
395
|
+ });
|
|
396
|
+ } else {
|
|
397
|
+ stack.push(screen);
|
|
398
|
+ }
|
|
399
|
+
|
306
|
400
|
mScreenStacks.add(stack);
|
307
|
401
|
AHBottomNavigationItem item = new AHBottomNavigationItem(screen.label, icons.get(screen), Color.GRAY);
|
308
|
402
|
mBottomNavigation.addItem(item);
|