Add workaround fix for #35350 (#38073)

Summary:
This PR is a result of this PR, which got merged but then reverted:

- https://github.com/facebook/react-native/pull/37913

We are trying to implement a workaround for https://github.com/facebook/react-native/issues/35350, so react-native users on android API 33+ can use `<FlatList inverted={true} />` without running into ANRs.

As explained in the issue, starting from android API 33 there are severe performance issues when using scaleY: -1 on a view, and its child view, which is what we are doing when inverting the ScrollView component (e.g. in FlatList).

This PR adds a workaround. The workaround is to also scale on the X-Axis which causes a different transform matrix to be created, that doesn't cause the ANR (see the issue for details).
However, when doing that the vertical scroll bar will be on the wrong side, thus we switch the position in the native code once we detect that the list is inverted, using the newly added `isInvertedVirtualizedList` prop.

This is a follow up PR to:

- https://github.com/facebook/react-native/pull/38071

⚠️ **Note:** [38071](https://github.com/facebook/react-native/pull/38071) needs to be merged and shipped first! Only then we can merge this PR.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[ANDROID] [FIXED] - ANR when having an inverted FlatList on android API 33+

Pull Request resolved: https://github.com/facebook/react-native/pull/38073

Test Plan:
- Check the RN tester app and see that scrollview is still working as expected
- Add the `internalAndroidApplyInvertedFix` prop as test to a scrollview and see how the scrollbar will change position.

Reviewed By: cortinico

Differential Revision: D47848063

Pulled By: NickGerleman

fbshipit-source-id: 4a6948a8b89f0b39f01b7a2d44dba740c53fabb3
This commit is contained in:
Hanno J. Gödecke
2023-08-07 10:43:26 -07:00
committed by Luna Wei
parent 22c9739042
commit e4429fa1c8
3 changed files with 7 additions and 3 deletions
@@ -1125,6 +1125,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
style: inversionStyle
? [inversionStyle, this.props.style]
: this.props.style,
isInvertedVirtualizedList: this.props.inverted,
maintainVisibleContentPosition:
this.props.maintainVisibleContentPosition != null
? {
@@ -2056,9 +2057,10 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}
const styles = StyleSheet.create({
verticallyInverted: {
transform: [{scaleY: -1}],
},
verticallyInverted:
Platform.OS === 'android'
? {transform: [{scale: -1}]}
: {transform: [{scaleY: -1}]},
horizontallyInverted: {
transform: [{scaleX: -1}],
},
@@ -1014,6 +1014,7 @@ exports[`VirtualizedList renders all the bells and whistles 1`] = `
getItemLayout={[Function]}
invertStickyHeaders={true}
inverted={true}
isInvertedVirtualizedList={true}
keyExtractor={[Function]}
onContentSizeChange={[Function]}
onLayout={[Function]}
@@ -796,6 +796,7 @@ exports[`VirtualizedSectionList renders all the bells and whistles 1`] = `
getItemLayout={[Function]}
invertStickyHeaders={true}
inverted={true}
isInvertedVirtualizedList={true}
keyExtractor={[Function]}
onContentSizeChange={[Function]}
onLayout={[Function]}