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

Add workaround for android API 33 ANR when inverting ScrollView #37913

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
hannojg marked this conversation as resolved.
Show resolved Hide resolved
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/u/1/issues/287304310
if (inverted) {
view.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
} else {
view.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_DEFAULT);
}
Comment on lines +394 to +398
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work correctly for horizontal lists?

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 😊

}
}
5 changes: 4 additions & 1 deletion packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1969,7 +1970,9 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {

const styles = StyleSheet.create({
verticallyInverted: {
transform: [{scaleY: -1}],
transform:
// It's important to invert the Y AND X axis to prevent a react native issue that can lead to ANRs on android 13
hannojg marked this conversation as resolved.
Show resolved Hide resolved
Platform.OS === 'android' ? [{scaleX: -1}, {scaleY: -1}] : [{scaleY: -1}],
hannojg marked this conversation as resolved.
Show resolved Hide resolved
},
horizontallyInverted: {
transform: [{scaleX: -1}],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the same workaround needed for horizontal lists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Expand Down