[fix] inverted VirtualizedList supports wheel events #2223
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Mostly issue #995 but also in other repos:
Problem
The
scale(-1)
hack in FlatList whenprops.inverted
is true is pretty dirty, and causes some side effects of "flipping things upside down", such as the arithmetics in thewheel
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 apatch-package
: https://github.com/staltz/manyverse/blob/52d5bbfb334e238f7d993ac7c0d764c32aeddb05/patches/react-native-web%2B0.17.5.patchTests
yarn test