Skip to content

Commit e8fdd3c

Browse files
cipolleschiblakef
authored andcommitted
Fix crash when navigating away from screens (#46559)
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
1 parent a22e29c commit e8fdd3c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/react-native/React/Views/ScrollView/RCTScrollView.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,14 @@ - (void)didMoveToWindow
856856
if (_scrollView.isDecelerating || !_scrollView.isTracking) {
857857
// Trigger the onMomentumScrollEnd event manually
858858
RCT_SEND_SCROLL_EVENT(onMomentumScrollEnd, nil);
859-
RCT_FORWARD_SCROLL_EVENT(scrollViewDidEndDecelerating : _scrollView);
859+
// We can't use the RCT_FORWARD_SCROLL_EVENT here beacuse the `_cmd` parameter passed
860+
// to `respondsToSelector` is the current method - so it will be `didMoveToWindow` - and not
861+
// `scrollViewDidEndDecelerating` that is passed.
862+
for (NSObject<UIScrollViewDelegate> *scrollViewListener in _scrollListeners) {
863+
if ([scrollViewListener respondsToSelector:@selector(scrollViewDidEndDecelerating:)]) {
864+
[scrollViewListener scrollViewDidEndDecelerating:_scrollView];
865+
}
866+
}
860867
}
861868
}
862869
}

0 commit comments

Comments
 (0)