-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Add workaround for android API 33 ANR when inverting ScrollView #37913
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
Changes from all commits
58d4ebc
e94e87f
5279546
c44cb4d
296226a
0f09703
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -379,4 +379,22 @@ public void setPointerEvents(ReactScrollView view, @Nullable String pointerEvent | |
| public void setScrollEventThrottle(ReactScrollView view, int scrollEventThrottle) { | ||
| view.setScrollEventThrottle(scrollEventThrottle); | ||
| } | ||
|
|
||
| @ReactProp(name = "inverted") | ||
| public void setInverted(ReactScrollView view, boolean inverted) { | ||
| // Usually when inverting the scroll view we are using scaleY: -1 on the list | ||
| // and on the parent container. HOWEVER, starting from android API 33 there is | ||
| // a bug that can cause an ANR due to that. Thus we are using different transform | ||
| // commands to circumvent the ANR. This however causes the vertical scrollbar to | ||
| // be on the wrong side. Thus we are moving it to the other side, when the list | ||
| // is inverted. | ||
| // See also: | ||
| // - https://github.com/facebook/react-native/issues/35350 | ||
| // - https://issuetracker.google.com/issues/287304310 | ||
| if (inverted) { | ||
| view.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT); | ||
| } else { | ||
| view.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_DEFAULT); | ||
| } | ||
|
Comment on lines
+394
to
+398
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work correctly for horizontal lists?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, does it position the scrollbar correctly on RTL interfaces? I don't know offhand if they're usually on the opposite sides for RTL vs LTR on Android but I suspect they might be, they are for the web: https://www.w3.org/People/kennyluck/Test/bidi-scrollbar
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about RTL as well, but it seems that RTL isn't handled right now and the scrollbar handle is always on the right side. So I didn't add support for it here either. HorizontalLists are handled by ReactHorizontalScrollViewManager, so yes, it still works 😊 |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import type { | |
| LayoutEvent, | ||
| ScrollEvent, | ||
| } from 'react-native/Libraries/Types/CoreEventTypes'; | ||
| import Platform from 'react-native/Libraries/Utilities/Platform'; | ||
| import type {ViewToken} from './ViewabilityHelper'; | ||
| import type { | ||
| Item, | ||
|
|
@@ -1969,7 +1970,15 @@ class VirtualizedList extends StateSafePureComponent<Props, State> { | |
|
|
||
| const styles = StyleSheet.create({ | ||
| verticallyInverted: { | ||
| transform: [{scaleY: -1}], | ||
| transform: | ||
| // Android 13 Bug Workaround: | ||
| // On Android, we need to invert both axes to mitigate a native bug | ||
| // that could lead to ANRs. | ||
| // Simply using scaleY: -1 leads to the application of scaleY and | ||
| // rotationX natively, resulting in the ANR. | ||
| // For more information, refer to the following Android tracking issue: | ||
| // https://issuetracker.google.com/issues/287304310 | ||
| Platform.OS === 'android' ? [{scale: -1}] : [{scaleY: -1}], | ||
| }, | ||
| horizontallyInverted: { | ||
| transform: [{scaleX: -1}], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the same workaround needed for horizontal lists?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Horizontal lists don't need that workaround, there won't be any ANRs when inverted |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.