Skip to content

Commit

Permalink
Override canScrollHorizontally() to expose when scrolling is disabled
Browse files Browse the repository at this point in the history
Summary:
**Context**
We have a bug where a ReactHorizontalScrollView is set to scrollEnabled = false. However, it still has a "scrollable width." When other components evaluate how to handle touches, they assume this view wants it...but `onInterceptTouch()` will return NO. To fix this in the most generic way and without making the other code aware of this class, I'm overriding `View.canScrollHorizontally()`.

**Notes**
- I also considered making the other code invoke onInterceptTouch(), but I don't want to have non-OS code invoking that and messing up state. The order of the input events matters.
- The [docs explicitly state](https://developer.android.com/reference/android/view/View#canScrollHorizontally(int)) "this is without regard to whether the view is enabled or not, or if it will scroll in response to user input or not"
  - I'm not so sure this is useful.
  - Other Android OS classes disregard it. :)
    - https://cs.android.com/android/platform/superproject/+/master:packages/apps/Messaging/src/com/android/messaging/ui/PagingAwareViewPager.java;l=91?q=%20canScrollHorizontally%5C(&start=21
    - https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/packages/SystemUI/src/com/android/systemui/qs/NonInterceptingScrollView.java;l=107?q=canScrollHorizontal

Reviewed By: NickGerleman

Differential Revision: D48343681

fbshipit-source-id: 4e133bc5509f68efdf510115f26aa56cfa115d94
  • Loading branch information
kolinkrewinkel authored and facebook-github-bot committed Aug 16, 2023
1 parent c8a479c commit 02408e1
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public boolean getScrollEnabled() {
return mScrollEnabled;
}

@Override
public boolean canScrollHorizontally(int direction) {
return mScrollEnabled && super.canScrollHorizontally(direction);
}

@Nullable
private OverScroller getOverScrollerFromParent() {
OverScroller scroller;
Expand Down

0 comments on commit 02408e1

Please sign in to comment.