Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] inverted VirtualizedList supports wheel events #2223

Closed
wants to merge 1 commit into from

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

@necolas necolas added this to the 0.17.x milestone Feb 16, 2022
@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
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.

None yet

2 participants