@@ -97,6 +97,7 @@ @implementation RCTScrollViewComponentView {
97
97
// This helps to only update state from `scrollViewDidScroll` in case
98
98
// some other part of the system scrolls scroll view.
99
99
BOOL _isUserTriggeredScrolling;
100
+ BOOL _shouldUpdateContentInsetAdjustmentBehavior;
100
101
101
102
CGPoint _contentOffsetWhenClipped;
102
103
}
@@ -120,6 +121,7 @@ - (instancetype)initWithFrame:(CGRect)frame
120
121
_scrollView.delaysContentTouches = NO ;
121
122
((RCTEnhancedScrollView *)_scrollView).overridingDelegate = self;
122
123
_isUserTriggeredScrolling = NO ;
124
+ _shouldUpdateContentInsetAdjustmentBehavior = YES ;
123
125
[self addSubview: _scrollView];
124
126
125
127
_containerView = [[UIView alloc ] initWithFrame: CGRectZero ];
@@ -266,7 +268,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
266
268
}
267
269
}
268
270
269
- if (oldScrollViewProps.contentInsetAdjustmentBehavior != newScrollViewProps.contentInsetAdjustmentBehavior ) {
271
+ if ((oldScrollViewProps.contentInsetAdjustmentBehavior != newScrollViewProps.contentInsetAdjustmentBehavior ) ||
272
+ _shouldUpdateContentInsetAdjustmentBehavior) {
270
273
auto const contentInsetAdjustmentBehavior = newScrollViewProps.contentInsetAdjustmentBehavior ;
271
274
if (contentInsetAdjustmentBehavior == ContentInsetAdjustmentBehavior::Never) {
272
275
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
@@ -277,6 +280,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
277
280
} else if (contentInsetAdjustmentBehavior == ContentInsetAdjustmentBehavior::Always) {
278
281
scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAlways;
279
282
}
283
+ _shouldUpdateContentInsetAdjustmentBehavior = NO ;
280
284
}
281
285
282
286
MAP_SCROLL_VIEW_PROP (disableIntervalMomentum);
@@ -390,6 +394,11 @@ - (void)prepareForRecycle
390
394
{
391
395
const auto &props = *std::static_pointer_cast<const ScrollViewProps>(_props);
392
396
_scrollView.contentOffset = RCTCGPointFromPoint (props.contentOffset );
397
+ // We set the default behavior to "never" so that iOS
398
+ // doesn't do weird things to UIScrollView insets automatically
399
+ // and keeps it as an opt-in behavior.
400
+ _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
401
+ _shouldUpdateContentInsetAdjustmentBehavior = YES ;
393
402
_state.reset ();
394
403
_isUserTriggeredScrolling = NO ;
395
404
[super prepareForRecycle ];
0 commit comments