@@ -204,7 +204,9 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
204204 CGPoint absoluteViewOrigin = [self convertPoint: self .bounds.origin toView: nil ];
205205 CGFloat scrollViewLowerY = isInverted ? absoluteViewOrigin.y : absoluteViewOrigin.y + self.bounds .size .height ;
206206
207- UIEdgeInsets newEdgeInsets = _scrollView.contentInset ;
207+ auto *enhancedScrollView = (RCTEnhancedScrollView *)_scrollView;
208+ UIEdgeInsets newEdgeInsets =
209+ enhancedScrollView.padsContentForSafeArea ? enhancedScrollView.baseContentInset : enhancedScrollView.contentInset ;
208210 CGFloat inset = MAX (scrollViewLowerY - keyboardEndFrame.origin .y , 0 );
209211 const auto &props = static_cast <const ScrollViewProps &>(*_props);
210212 if (isInverted) {
@@ -257,7 +259,7 @@ - (void)_keyboardWillChangeFrame:(NSNotification *)notification
257259 delay: 0.0
258260 options: animationOptionsWithCurve (curve)
259261 animations: ^{
260- self->_scrollView . contentInset = newEdgeInsets;
262+ ((RCTEnhancedScrollView *) self->_scrollView ). baseContentInset = newEdgeInsets;
261263 self->_scrollView .verticalScrollIndicatorInsets = newEdgeInsets;
262264 [self scrollTo: newContentOffset.x y: newContentOffset.y animated: NO ];
263265 }
@@ -345,6 +347,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
345347 MAP_SCROLL_VIEW_PROP (bouncesZoom);
346348 MAP_SCROLL_VIEW_PROP (canCancelContentTouches);
347349 MAP_SCROLL_VIEW_PROP (centerContent);
350+ MAP_SCROLL_VIEW_PROP (horizontal);
348351 // MAP_SCROLL_VIEW_PROP(automaticallyAdjustContentInsets);
349352 MAP_SCROLL_VIEW_PROP (decelerationRate);
350353 MAP_SCROLL_VIEW_PROP (directionalLockEnabled);
@@ -396,13 +399,15 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
396399 // When disabling centerContent, reset inset to prop value
397400 // (enabling is handled automatically by the setCenterContent: setter)
398401 if (oldScrollViewProps.centerContent && !newScrollViewProps.centerContent ) {
399- _scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets (newScrollViewProps.contentInset );
402+ ((RCTEnhancedScrollView *)_scrollView).baseContentInset =
403+ RCTUIEdgeInsetsFromEdgeInsets (newScrollViewProps.contentInset );
400404 }
401405
402406 // Only apply contentInset from props if centerContent is disabled
403407 // When centerContent is enabled, the inset is calculated by centerContentIfNeeded
404408 if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset && !newScrollViewProps.centerContent ) {
405- _scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets (newScrollViewProps.contentInset );
409+ ((RCTEnhancedScrollView *)_scrollView).baseContentInset =
410+ RCTUIEdgeInsetsFromEdgeInsets (newScrollViewProps.contentInset );
406411 }
407412 if (oldScrollViewProps.contentOffset != newScrollViewProps.contentOffset ) {
408413 _scrollView.contentOffset = RCTCGPointFromPoint (newScrollViewProps.contentOffset );
@@ -446,6 +451,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
446451 }
447452 _shouldUpdateContentInsetAdjustmentBehavior = NO ;
448453 }
454+ scrollView.padsContentForSafeArea = newScrollViewProps.padsContentForSafeArea ;
449455
450456 MAP_SCROLL_VIEW_PROP (disableIntervalMomentum);
451457 MAP_SCROLL_VIEW_PROP (snapToInterval);
@@ -596,7 +602,9 @@ - (BOOL)_shouldDisableScrollInteraction
596602 auto metrics = ScrollViewEventEmitter::Metrics{};
597603 metrics.contentSize = RCTSizeFromCGSize (_scrollView.contentSize );
598604 metrics.contentOffset = RCTPointFromCGPoint (_scrollView.contentOffset );
599- metrics.contentInset = RCTEdgeInsetsFromUIEdgeInsets (_scrollView.contentInset );
605+ auto *scrollView = (RCTEnhancedScrollView *)_scrollView;
606+ metrics.contentInset = RCTEdgeInsetsFromUIEdgeInsets (
607+ scrollView.padsContentForSafeArea ? scrollView.baseContentInset : scrollView.contentInset );
600608 metrics.containerSize = RCTSizeFromCGSize (_scrollView.bounds .size );
601609 metrics.zoomScale = _scrollView.zoomScale ;
602610 metrics.timestamp = CACurrentMediaTime ();
@@ -700,11 +708,12 @@ - (void)prepareForRecycle
700708 // Invalidate cached content size so that updateState: recalculates the
701709 // container frame after zoomScale reset (which may have mutated it in RTL).
702710 _contentSize = CGSizeZero;
703- _scrollView. contentInset = RCTUIEdgeInsetsFromEdgeInsets (props.contentInset );
711+ ((RCTEnhancedScrollView *) _scrollView). baseContentInset = RCTUIEdgeInsetsFromEdgeInsets (props.contentInset );
704712 // We set the default behavior to "never" so that iOS
705713 // doesn't do weird things to UIScrollView insets automatically
706714 // and keeps it as an opt-in behavior.
707715 _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
716+ ((RCTEnhancedScrollView *)_scrollView).padsContentForSafeArea = NO ;
708717 _shouldUpdateContentInsetAdjustmentBehavior = YES ;
709718 _automaticallyAdjustKeyboardInsets = NO ;
710719 _isUserTriggeredScrolling = NO ;
0 commit comments