Skip to content

[fix] inverted VirtualizedList supports wheel events#2223

Closed
staltz wants to merge 1 commit intonecolas:masterfrom
staltz:inverted-list-wheel-ev
Closed

[fix] inverted VirtualizedList supports wheel events#2223
staltz wants to merge 1 commit intonecolas:masterfrom
staltz:inverted-list-wheel-ev

Conversation

@staltz
Copy link
Contributor

@staltz staltz commented Feb 16, 2022

Context

Mostly issue #995 but also in other repos:

Problem

The scale(-1) hack in FlatList when props.inverted is true is pretty dirty, and causes some side effects of "flipping things upside down", such as the arithmetics in the wheel event. (Note, scrolling with the trackpad was working well before this PR and is unaffected by this PR)

I have spent some days trying alternative such as recyclerlistview, but they seem to work well only if all items are of the same layout dimensions. When you need items of variable height and the inverted prop, FlatList (VirtualizedList) was more reliable, it has more consistent behavior. (recyclerlistview was giving sudden yanks during scrolling)

Solution

Flip the math when handling the wheel event, in VirtualizedList, as an event listener setup in componentDidMount/componentWillUnmount. The code I'm submitting here has been thoroughly tested in my app Manyverse in the form of a patch-package: https://github.com/staltz/manyverse/blob/52d5bbfb334e238f7d993ac7c0d764c32aeddb05/patches/react-native-web%2B0.17.5.patch

Tests

  • ✔️ Passes yarn test
  • ✔️ Works in Chrome (well, in Electron 15, thus Chrome 94)
  • ❓ Works in Firefox
  • ❓ Works in Safari

@staltz staltz force-pushed the inverted-list-wheel-ev branch from 58b7c2f to 6b13017 Compare February 16, 2022 11:06
@necolas necolas added this to the 0.17.x milestone Feb 16, 2022
@staltz staltz force-pushed the inverted-list-wheel-ev branch from 6b13017 to 98128d4 Compare February 17, 2022 13:23
@staltz
Copy link
Contributor Author

staltz commented Feb 17, 2022

Updated the commit so that it passes yarn test.

@necolas
Copy link
Owner

necolas commented Feb 17, 2022

Thanks! I think deltaX needs to be used if the scroll direction is horizontal. See the similar PR #1241

@staltz staltz force-pushed the inverted-list-wheel-ev branch from 98128d4 to c0431f0 Compare February 18, 2022 09:09
@staltz
Copy link
Contributor Author

staltz commented Feb 18, 2022

Done (force pushed an update to the commit). I also removed Platform.OS checks because there should only be 'web' in this case.

@necolas necolas closed this in 7ec2489 Feb 18, 2022
@necolas
Copy link
Owner

necolas commented Feb 18, 2022

Thanks. Included in 0.17.6

@staltz staltz deleted the inverted-list-wheel-ev branch February 18, 2022 18:34
rnike pushed a commit to VeryBuy/react-native-web that referenced this pull request Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants