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 cell style for inverted Animated.FlatList #3765

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

levibuzolic
Copy link
Contributor

@levibuzolic levibuzolic commented Nov 11, 2022

Description

Animated.FlatList currently presents each item flipped when using the inverted prop, this due to how the inverted props works internally (it literally flips the ScrollView). In the React Native codebase they then apply a style to each cell item to flip it back to the correct orientation. However this fix isn't applied to Reanimated's FlatList implementation because it overrides the CellRendererComponent prop.

Fixes #2769

Changes

I've used the same fix from React Native to correct the implementation in Reanimated and included an example in the Example app so it's easy to verify if this gets regressed in the future.

Before After
Simulator Screen Recording - iPhone 8 - 2022-11-11 at 14 19 48 Simulator Screen Recording - iPhone 8 - 2022-11-11 at 14 18 16

Test code and steps to reproduce

Check the Inverted FlatList Example in the Example app.

Checklist

  • Included code example that can be used to test this change
  • Updated TS types
  • Added TS types tests
  • Added unit / integration tests
  • Updated documentation
  • Ensured that CI passes

Previously Animated.FlatList would show each item flipped when using the 'inverted' prop, this due to how 'inverted' works internally - it literally flips the ScrollView. In React Native they then apply a style to each cell item to restore the transform back to the correct way. This fix here works the same way.
@levibuzolic levibuzolic changed the title Fix mirrored cell style for inverted Animated.FlatLists Fix inverted cell style for inverted Animated.FlatList Nov 13, 2022
@piaskowyk
Copy link
Member

Hey 👋 Thanks for your PR!

@piaskowyk piaskowyk merged commit c33e25b into software-mansion:main Dec 19, 2022
@levibuzolic levibuzolic deleted the fix-inverted-flatlist branch December 19, 2022 20:19
fluiddot pushed a commit to wordpress-mobile/react-native-reanimated that referenced this pull request Jun 5, 2023
…ion#3765)

## Description

`Animated.FlatList` currently presents each item flipped when using the `inverted` prop, this due to how the `inverted` props works internally (it literally flips the ScrollView). [In the React  Native codebase](https://github.com/facebook/react-native/blob/29caed22cc1c9a426e524e498cf44cf18df0577e/Libraries/Lists/VirtualizedList.js#L1845-L1850) they then apply a style to each cell item to flip it back to the correct orientation. However this fix isn't applied to Reanimated's `FlatList` implementation because it overrides the `CellRendererComponent` prop.

Fixes software-mansion#2769

## Changes

I've used the same fix from React Native to correct the implementation in Reanimated and included an example in the Example app so it's easy to verify if this gets regressed in the future.

Before | After
---|---
![Simulator Screen Recording - iPhone 8 - 2022-11-11 at 14 19 48](https://user-images.githubusercontent.com/721323/201256418-0edf01dc-c4df-4a87-8afd-364f0680631b.gif) | ![Simulator Screen Recording - iPhone 8 - 2022-11-11 at 14 18 16](https://user-images.githubusercontent.com/721323/201256429-2c0a216d-a61c-41a0-8528-654a73982b06.gif)

## Test code and steps to reproduce

Check the `Inverted FlatList Example` in the Example app.

## Checklist

- [x] Included code example that can be used to test this change
- [x] ~Updated TS types~
- [x] ~Added TS types tests~
- [ ] Added unit / integration tests
- [x] ~Updated documentation~
- [x] Ensured that CI passes
@seba1342
Copy link

@piaskowyk sorry to resurrect this. Looks like in v3 (I am on 3.3.0) this needs to be reverted as it appears to be fixed elsewhere? Could we get a revert on this PR?

@bartlomiejbloniarz
Copy link
Contributor

@seba1342 hi, could you point me to the where it was fixed in react-native?

github-merge-queue bot pushed a commit that referenced this pull request Oct 30, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR changes how reanimated treats inverted `FlatLists`. In #3765 our
implementation was changed to mimic the react-native behavior by
assigning a special style that reverts the cell inversion (inverted
FlatList flips the entire view and then flips back every cell). In
react-native@0.72.4 the inversion style was
[changed](facebook/react-native#38073) on
android due to some performance issues. That change combined with our
implementation was causing the cell to remain inverted on android (since
both styles were being applied). This PR changes our implementation to
instead allow the `CellRendererComponent` to receive a style prop,
making react solely responsible for the cell inversion.


## Test plan
Check whether the Inverted FlatList Example behaves properly on android.
I tested the example on all rn versions from rn@0.69
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.

FlatList inverted, itemLayoutAnimation and Typescript not working
4 participants