Skip to content

Commit

Permalink
prevent scroll event in nested scroll when scrollEnabled={false} (#42219
Browse files Browse the repository at this point in the history
)

Summary:
When a FlatList is in side a scroll view (think Netflix style navigation), the DPAD up/down fires on the scroll view, despite scrollEnabled={false} being set. This additiontially conflicts with any custom scroll event that has been created.

## Changelog:

[Android] [Fixed] - fix: prevent scroll event in nested scroll when scrollEnabled={false}

Pull Request resolved: #42219

Test Plan:
I tested this by making a ScrollView with FlatList of opposite scrolling direction inside with basic card layouts.

Both had scrollEnabled={false}

I scrolled the ScrollView myself as it has multiple rows using:

```
  const scrollToItem = React.useCallback(
    (itemIndex: number): void => {
      const targetScrollY = itemIndex * height
      scrollViewRef.current?.scrollTo({ y: targetScrollY, animated: true })
    },
    [height]
  )

  React.useEffect(() => {
    // Row 0, is global nav, but it's also the first row of cards
    // when we scroll to "1" what we mean is global nav is hidden
    // we should still be showing the first row of items.
    scrollToItem(rowIndex <= 1 ? 0 : rowIndex - 1)
  }, [rowIndex, scrollToItem])
```

Reviewed By: NickGerleman

Differential Revision: D52642168

Pulled By: mdvacca

fbshipit-source-id: 9305bc56ba6b03b04b9f69a14d433593cab2025e
  • Loading branch information
Icehunter authored and facebook-github-bot committed Jan 10, 2024
1 parent ab192ce commit c7873b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
*/
@Override
public void requestChildFocus(View child, View focused) {
/**
* This issue arises in a ScrollView containing a FlatList. The method now checks
* `mScrollEnabled` before handling focus requests to prevent unintended scroll behavior,
* ensuring proper functioning of nested scrolling components. when scrollEnabled={false}
*/
if (!mScrollEnabled) {

return;
}

if (focused != null && !mPagingEnabled) {
scrollToChild(focused);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ protected void onDetachedFromWindow() {
*/
@Override
public void requestChildFocus(View child, View focused) {
/**
* This issue arises in a ScrollView containing a FlatList. The method now checks
* `mScrollEnabled` before handling focus requests to prevent unintended scroll behavior,
* ensuring proper functioning of nested scrolling components. when scrollEnabled={false}
*/
if (!mScrollEnabled) {

return;
}

if (focused != null) {
scrollToChild(focused);
}
Expand Down

0 comments on commit c7873b7

Please sign in to comment.