Guy Carmeli 8 vuotta sitten
vanhempi
commit
337ab33d5e

+ 8
- 17
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java Näytä tiedosto

@@ -5,7 +5,6 @@ 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.view.View;
9 8
 
10 9
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
11 10
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
@@ -115,7 +114,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
115 114
         StyleHelper.updateStyles(mToolbar, getCurrentScreen());
116 115
 
117 116
         if (shouldToggleTabs(screen)) {
118
-            toggleTabs(screen.bottomTabsHidden, false);
117
+            mBottomNavigation.toggleTabs(screen.bottomTabsHidden, false);
119 118
         }
120 119
     }
121 120
 
@@ -129,7 +128,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
129 128
                 StyleHelper.updateStyles(mToolbar, currentScreen);
130 129
 
131 130
                 if (shouldToggleTabs(currentScreen)) {
132
-                    toggleTabs(currentScreen.bottomTabsHidden, false);
131
+                    mBottomNavigation.toggleTabs(currentScreen.bottomTabsHidden, false);
133 132
                 }
134 133
 
135 134
                 return popped;
@@ -148,7 +147,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
148 147
                 StyleHelper.updateStyles(mToolbar, currentScreen);
149 148
 
150 149
                 if (shouldToggleTabs(currentScreen)) {
151
-                    toggleTabs(currentScreen.bottomTabsHidden, false);
150
+                    mBottomNavigation.toggleTabs(currentScreen.bottomTabsHidden, false);
152 151
                 }
153 152
 
154 153
                 return popped;
@@ -236,24 +235,17 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
236 235
     public void toggleTabs(ReadableMap params) {
237 236
         boolean hide = params.getBoolean(KEY_HIDDEN);
238 237
         boolean animated = params.getBoolean(KEY_ANIMATED);
239
-        toggleTabs(hide, animated);
240
-    }
241
-
242
-    // TODO: support animated = false -guyca
243
-    private void toggleTabs(boolean hide, boolean animated) {
244
-        if (hide) {
245
-//            mBottomNavigation.hideBottomNavigation(animated);
246
-            mBottomNavigation.setVisibility(View.GONE);
247
-        } else {
248
-            mBottomNavigation.setVisibility(View.VISIBLE);
249
-//            mBottomNavigation.restoreBottomNavigation(animated);
250
-        }
238
+        mBottomNavigation.toggleTabs(hide, animated);
251 239
     }
252 240
 
253 241
     private boolean shouldToggleTabs(Screen newScreen) {
254 242
         return mBottomNavigation.isShown() == newScreen.bottomTabsHidden;
255 243
     }
256 244
 
245
+    public void notifyScroll(int direction) {
246
+        mBottomNavigation.onScroll(direction);
247
+    }
248
+
257 249
     private static class SetupTabsTask extends AsyncTask<Void, Void, Map<Screen, Drawable>> {
258 250
         private BottomTabActivity mActivity;
259 251
         private RnnToolBar mToolBar;
@@ -308,7 +300,6 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
308 300
         this.onTabSelected(0, false);
309 301
     }
310 302
 
311
-
312 303
     @Override
313 304
     protected void removeAllReactViews() {
314 305
         for (ScreenStack screenStack : mScreenStacks) {

+ 26
- 4
android/app/src/main/java/com/reactnativenavigation/views/BottomNavigation.java Näytä tiedosto

@@ -2,6 +2,7 @@ package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.util.AttributeSet;
5
+import android.view.View;
5 6
 
6 7
 import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
7 8
 
@@ -10,6 +11,9 @@ import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;
10 11
  */
11 12
 public class BottomNavigation extends AHBottomNavigation {
12 13
 
14
+    public static final int SCROLL_DIRECTION_UP = 0;
15
+    public static final int SCROLL_DIRECTION_DOWN = 1;
16
+
13 17
     public BottomNavigation(Context context) {
14 18
         super(context);
15 19
     }
@@ -22,12 +26,30 @@ public class BottomNavigation extends AHBottomNavigation {
22 26
         super(context, attrs, defStyleAttr);
23 27
     }
24 28
 
25
-    /**
26
-     * Synchronize the BottomNavigation with a {@link android.widget.ScrollView}. When
27
-     */
28
-    public void setupWithScrollView() {
29
+    // TODO: support animated = false -guyca
30
+    public void toggleTabs(boolean hide, boolean animated) {
31
+        if (hide) {
32
+            hide();
33
+        } else {
34
+            show();
35
+        }
36
+    }
29 37
 
38
+    private void hide() {
39
+        // mBottomNavigation.hideBottomNavigation(animated);
40
+        setVisibility(View.GONE);
30 41
     }
31 42
 
43
+    private void show() {
44
+        setVisibility(View.VISIBLE);
45
+        // mBottomNavigation.restoreBottomNavigation(animated);
46
+    }
32 47
 
48
+    public void onScroll(int direction) {
49
+        if (direction == SCROLL_DIRECTION_DOWN) {
50
+            hideBottomNavigation(true);
51
+        } else if (direction == SCROLL_DIRECTION_UP) {
52
+            restoreBottomNavigation(true);
53
+        }
54
+    }
33 55
 }

+ 14
- 1
android/app/src/main/java/com/reactnativenavigation/views/RctView.java Näytä tiedosto

@@ -11,6 +11,7 @@ import android.widget.ScrollView;
11 11
 import com.facebook.react.ReactInstanceManager;
12 12
 import com.facebook.react.ReactRootView;
13 13
 import com.reactnativenavigation.activities.BaseReactActivity;
14
+import com.reactnativenavigation.activities.BottomTabActivity;
14 15
 import com.reactnativenavigation.core.objects.Screen;
15 16
 import com.reactnativenavigation.utils.BridgeUtils;
16 17
 import com.reactnativenavigation.utils.ReflectionUtils;
@@ -20,13 +21,24 @@ import com.reactnativenavigation.utils.ReflectionUtils;
20 21
  */
21 22
 public class RctView extends FrameLayout {
22 23
     private static final String TAG = "RctView";
24
+
25
+    private BottomTabActivity mContext;
23 26
     private ReactRootView mReactRootView;
24 27
     private ScrollView mScrollView;
28
+    private int mLastScrollY = -1;
25 29
     private final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
26 30
         @Override
27 31
         public void onScrollChanged() {
28 32
             if (mScrollView.getViewTreeObserver().isAlive()) {
29
-                Log.i(TAG, "onScrollChanged: " + mScrollView.getScrollY());
33
+                if (mScrollView.getScrollY() != mLastScrollY) {
34
+                    int currentScrollY = mScrollView.getScrollY();
35
+                    mContext.notifyScroll(currentScrollY > mLastScrollY ?
36
+                            BottomNavigation.SCROLL_DIRECTION_DOWN :
37
+                            BottomNavigation.SCROLL_DIRECTION_UP);
38
+
39
+                    mLastScrollY = currentScrollY;
40
+                }
41
+                Log.i(TAG, "onScrollChanged: " + mLastScrollY);
30 42
             }
31 43
         }
32 44
     };
@@ -119,6 +131,7 @@ public class RctView extends FrameLayout {
119 131
     private void setupScrollViewWithBottomTabs() {
120 132
         mScrollView = getScrollView((ViewGroup) getParent());
121 133
         if (mScrollView != null) {
134
+            mContext = (BottomTabActivity) getContext();
122 135
             attachStateChangeListener(mScrollView);
123 136
             addScrollListener();
124 137
         }