feat: Add CellRendererComponentStyle to Animated.FlatList #6573
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.
Summary
This PR adds a new prop to
Animated.FlatList
,CellRendererComponentStyle
. It has a very similar description asreact-native
'sPressable
style prop, where it can either be a regular animated style, or a function that receives the index and the corresponding item. The naming convention followsreact-native
'sFlatList
naming convention (e.g.ListHeaderComponent
andListHeaderComponentStyle
).The idea sprung when trying to implement a draggable
FlatList
withreanimated
'sAnimated.FlatList
and being unable to change thezIndex
of the item being dragged, resulting in it always being rendered behind items of a higher index.After the
CellRendererComponent
prop was removed fromAnimated.Flatlist
, it became impossible to control styles that need to be altered in the top-level element - specificallyzIndex
.While it would be possible to use
Animated.createAnimatedComponent
and mimic the logic ofAnimated.FlatList
for anything but the style of theCellRendererComponent
, this API seems to have at least some attraction within the community and therefore is being suggested.Test plan
Simply adding this code snippet as a property on an
Animated.FlatList
should show that it functions as intended. See video below where this snippet was added to theInvertedFlatListExample.tsx
example.Simulator.Screen.Recording.-.iPhone.16.Pro.Max.-.2024-10-04.at.15.47.20.mp4