Skip to content

Commit

Permalink
Fix crash when navigating away from screens (#46559)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46559

There is an edge case when we navigate away from a screen that contains a scroll view where one of the UISCrollViewDelegates does not implement the scrollViewDidEndDecelerating method.

This happens because the Macro used assumes that the event that we are forwarding is the actual method from where the macro is called. Which is not true when it comes to `didMoveToWindow`.

This change fixes that by explicitly expanding the macro in this scenario and passing the right selector.

## Changelog:
[iOS][Fixed] - Fixed a crash when navigating away from a screen that contains a scrollView

## Facebook
This should fix T201780472

Reviewed By: philIip

Differential Revision: D62935876

fbshipit-source-id: e29aadf201c8066b5d3b7b0ada21fa8d763e9af0
  • Loading branch information
cipolleschi authored and blakef committed Sep 23, 2024
1 parent a22e29c commit e8fdd3c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/react-native/React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,14 @@ - (void)didMoveToWindow
if (_scrollView.isDecelerating || !_scrollView.isTracking) {
// Trigger the onMomentumScrollEnd event manually
RCT_SEND_SCROLL_EVENT(onMomentumScrollEnd, nil);
RCT_FORWARD_SCROLL_EVENT(scrollViewDidEndDecelerating : _scrollView);
// We can't use the RCT_FORWARD_SCROLL_EVENT here beacuse the `_cmd` parameter passed
// to `respondsToSelector` is the current method - so it will be `didMoveToWindow` - and not
// `scrollViewDidEndDecelerating` that is passed.
for (NSObject<UIScrollViewDelegate> *scrollViewListener in _scrollListeners) {
if ([scrollViewListener respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
[scrollViewListener scrollViewDidEndDecelerating:_scrollView];
}
}
}
}
}
Expand Down

0 comments on commit e8fdd3c

Please sign in to comment.