Skip to content

Commit 6ecd9a4

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Fix touch events not being dispatched to ScrollView's children when they overflow content container (facebook#49855)
Summary: Pull Request resolved: facebook#49855 Changelog: [IOS][FIXED] - Fixed touch events not being dispatched to ScrollView's children when they overflow the content container Closes facebook#47740. Changes the ScrollView's container view to be `RCTViewComponentView` instead of `UIView` and sets custom layout metrics to it in a way that it will propagate touch events to all children, even if they overflow its bounds. Reviewed By: sammy-SC Differential Revision: D70619894 fbshipit-source-id: 348a1a369489d5208d6037c8d76b223c4ab2d5f7
1 parent 0ade23d commit 6ecd9a4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

+7-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ @interface RCTScrollViewComponentView () <
8989

9090
@implementation RCTScrollViewComponentView {
9191
ScrollViewShadowNode::ConcreteState::Shared _state;
92+
LayoutMetrics _lastContentContainerLayoutMetrics;
9293
CGSize _contentSize;
9394
NSTimeInterval _lastScrollEventDispatchTime;
9495
NSTimeInterval _scrollEventThrottle;
@@ -132,7 +133,7 @@ - (instancetype)initWithFrame:(CGRect)frame
132133
_automaticallyAdjustKeyboardInsets = NO;
133134
[self addSubview:_scrollView];
134135

135-
_containerView = [[UIView alloc] initWithFrame:CGRectZero];
136+
_containerView = [[RCTViewComponentView alloc] initWithFrame:CGRectZero];
136137
[_scrollView addSubview:_containerView];
137138

138139
[self.scrollViewDelegateSplitter addDelegate:self];
@@ -468,7 +469,11 @@ - (void)updateState:(const State::Shared &)state oldState:(const State::Shared &
468469
}
469470

470471
_contentSize = contentSize;
471-
_containerView.frame = CGRect{RCTCGPointFromPoint(data.contentBoundingRect.origin), contentSize};
472+
LayoutMetrics newContentContainerLayoutMetrics = LayoutMetrics{
473+
.frame = {.origin = data.contentBoundingRect.origin, .size = data.getContentSize()}, .overflowInset = {.top = 1}};
474+
[_containerView updateLayoutMetrics:newContentContainerLayoutMetrics
475+
oldLayoutMetrics:_lastContentContainerLayoutMetrics];
476+
_lastContentContainerLayoutMetrics = newContentContainerLayoutMetrics;
472477

473478
[self _preserveContentOffsetIfNeededWithBlock:^{
474479
self->_scrollView.contentSize = contentSize;

0 commit comments

Comments
 (0)