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 all 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/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 😊

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@ ScrollViewProps::ScrollViewProps(
rawProps,
"scrollToOverflowEnabled",
sourceProps.scrollToOverflowEnabled,
{})),
inverted(
CoreFeatures::enablePropIteratorSetter
? sourceProps.inverted
: convertRawProp(
context,
rawProps,
"inverted",
sourceProps.inverted,
{})) {}

void ScrollViewProps::setProp(
Expand Down Expand Up @@ -368,6 +377,7 @@ void ScrollViewProps::setProp(
RAW_SET_PROP_SWITCH_CASE_BASIC(snapToEnd);
RAW_SET_PROP_SWITCH_CASE_BASIC(contentInsetAdjustmentBehavior);
RAW_SET_PROP_SWITCH_CASE_BASIC(scrollToOverflowEnabled);
RAW_SET_PROP_SWITCH_CASE_BASIC(inverted);
}
}

Expand Down Expand Up @@ -492,7 +502,9 @@ SharedDebugStringConvertibleList ScrollViewProps::getDebugProps() const {
debugStringConvertibleItem(
"snapToStart", snapToStart, defaultScrollViewProps.snapToStart),
debugStringConvertibleItem(
"snapToEnd", snapToEnd, defaultScrollViewProps.snapToEnd)};
"snapToEnd", snapToEnd, defaultScrollViewProps.snapToEnd),
debugStringConvertibleItem(
"inverted", inverted, defaultScrollViewProps.inverted)};
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ScrollViewProps final : public ViewProps {
ContentInsetAdjustmentBehavior contentInsetAdjustmentBehavior{
ContentInsetAdjustmentBehavior::Never};
bool scrollToOverflowEnabled{false};
bool inverted{false};
hannojg marked this conversation as resolved.
Show resolved Hide resolved

#pragma mark - DebugStringConvertible

Expand Down
11 changes: 10 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,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}],
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