ソースを参照

Stop notifying scrollChanged events when scroll view over scrolls

Guy Carmeli 8 年 前
コミット
80c3c93005

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/activities/BottomTabActivity.java ファイルの表示

@@ -242,7 +242,7 @@ public class BottomTabActivity extends BaseReactActivity implements AHBottomNavi
242 242
         return mBottomNavigation.isShown() == newScreen.bottomTabsHidden;
243 243
     }
244 244
 
245
-    public void notifyScroll(int direction) {
245
+    public void onScrollChanged(int direction) {
246 246
         mBottomNavigation.onScroll(direction);
247 247
     }
248 248
 

+ 13
- 10
android/app/src/main/java/com/reactnativenavigation/views/RctView.java ファイルの表示

@@ -29,16 +29,19 @@ public class RctView extends FrameLayout {
29 29
     private final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener = new ViewTreeObserver.OnScrollChangedListener() {
30 30
         @Override
31 31
         public void onScrollChanged() {
32
-            if (mScrollView.getViewTreeObserver().isAlive()) {
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);
32
+            if (!mScrollView.getViewTreeObserver().isAlive()) {
33
+                return;
34
+            }
35
+
36
+            final int scrollY = mScrollView.getScrollY();
37
+            if (scrollY != mLastScrollY && // Scroll position changed
38
+                scrollY > 0 && // Ignore top overscroll
39
+                scrollY < (mScrollView.getChildAt(0).getHeight() - mScrollView.getHeight())) { // Ignore bottom overscroll
40
+                int direction = scrollY > mLastScrollY ?
41
+                        BottomNavigation.SCROLL_DIRECTION_DOWN :
42
+                        BottomNavigation.SCROLL_DIRECTION_UP;
43
+                mLastScrollY = scrollY;
44
+                mContext.onScrollChanged(direction);
42 45
             }
43 46
         }
44 47
     };