Skip to content

Commit b8d5e2d

Browse files
committed
Fix recycled ScrollView keyboard inset state
Fixes #57755 Reset keyboard-managed state and cancel active animations when a Fabric ScrollView is recycled so later views cannot inherit keyboard insets.
1 parent 8e995e8 commit b8d5e2d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
360360
MAP_SCROLL_VIEW_PROP(showsHorizontalScrollIndicator);
361361
MAP_SCROLL_VIEW_PROP(showsVerticalScrollIndicator);
362362

363-
if (oldScrollViewProps.automaticallyAdjustKeyboardInsets != newScrollViewProps.automaticallyAdjustKeyboardInsets) {
364-
_automaticallyAdjustKeyboardInsets = newScrollViewProps.automaticallyAdjustKeyboardInsets;
365-
}
363+
_automaticallyAdjustKeyboardInsets = newScrollViewProps.automaticallyAdjustKeyboardInsets;
366364

367365
if (oldScrollViewProps.scrollIndicatorInsets != newScrollViewProps.scrollIndicatorInsets) {
368366
_scrollView.scrollIndicatorInsets = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.scrollIndicatorInsets);
@@ -690,18 +688,22 @@ - (void)prepareForRecycle
690688
_state.reset();
691689

692690
const auto &props = static_cast<const ScrollViewProps &>(*_props);
691+
// Cancel keyboard animations before resetting the state they manage.
692+
[_scrollView.layer removeAllAnimations];
693693
_scrollView.contentOffset = RCTCGPointFromPoint(props.contentOffset);
694694
// Reset zoom scale to default
695695
_scrollView.zoomScale = 1.0;
696696
// Invalidate cached content size so that updateState: recalculates the
697697
// container frame after zoomScale reset (which may have mutated it in RTL).
698698
_contentSize = CGSizeZero;
699699
_scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(props.contentInset);
700+
_scrollView.verticalScrollIndicatorInsets = RCTUIEdgeInsetsFromEdgeInsets(props.scrollIndicatorInsets);
700701
// We set the default behavior to "never" so that iOS
701702
// doesn't do weird things to UIScrollView insets automatically
702703
// and keeps it as an opt-in behavior.
703704
_scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
704705
_shouldUpdateContentInsetAdjustmentBehavior = YES;
706+
_automaticallyAdjustKeyboardInsets = NO;
705707
_isUserTriggeredScrolling = NO;
706708
CGRect oldFrame = self.frame;
707709
self.frame = CGRectZero;

0 commit comments

Comments
 (0)