From 511188dd7540c837b435b2f448a18bffb44bcb9c Mon Sep 17 00:00:00 2001 From: Adam Comella Date: Tue, 22 Nov 2016 18:29:24 -0800 Subject: [PATCH] When calculating maxScrollY, take padding into account Also, refactored this logic into a helper. --- .../react/views/scroll/ReactScrollView.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java index 1208440bac31ed..b14d6cb98f80fc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java @@ -304,6 +304,12 @@ private boolean isScrollPerfLoggingEnabled() { return mFpsListener != null && mScrollPerfTag != null && !mScrollPerfTag.isEmpty(); } + private int getMaxScrollY() { + int contentHeight = mContentView.getHeight(); + int viewportHeight = getHeight() - getPaddingBottom() - getPaddingTop(); + return Math.max(0, contentHeight - viewportHeight); + } + @Override public void draw(Canvas canvas) { if (mEndFillColor != Color.TRANSPARENT) { @@ -332,10 +338,8 @@ protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolea // more information. if (!mScroller.isFinished() && mScroller.getCurrY() != mScroller.getFinalY()) { - int scrollRange = Math.max( - 0, - getChildAt(0).getHeight() - (getHeight() - getPaddingBottom() - getPaddingTop())); - if (scrollY >= scrollRange) { + int scrollRange = getMaxScrollY(); + if (scrollY >= getMaxScrollY()) { mScroller.abortAnimation(); scrollY = scrollRange; } @@ -371,12 +375,8 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int return; } - int contentHeight = mContentView.getMeasuredHeight(); int currentScrollY = getScrollY(); - int thisHeight = getMeasuredHeight(); - - int maxScrollY = Math.max(0, contentHeight - thisHeight); - + int maxScrollY = getMaxScrollY(); if (currentScrollY > maxScrollY) { scrollTo(getScrollX(), maxScrollY); }