Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ - (void)setContentOffset:(CGPoint)contentOffset
RCTSanitizeNaNValue(contentOffset.y, @"scrollView.contentOffset.y"));
}

- (void)setCenterContent:(BOOL)centerContent
{
if (_centerContent != centerContent) {
_centerContent = centerContent;
[self centerContentIfNeeded];
}
}

- (void)setContentSize:(CGSize)contentSize
{
[super setContentSize:contentSize];
[self centerContentIfNeeded];
}

- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,19 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &

MAP_SCROLL_VIEW_PROP(zoomScale);

if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset) {
_scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset);
RCTEnhancedScrollView *scrollView = (RCTEnhancedScrollView *)_scrollView;

// When disabling centerContent, reset inset to prop value
// (enabling is handled automatically by the setCenterContent: setter)
if (oldScrollViewProps.centerContent && !newScrollViewProps.centerContent) {
scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset);
}

RCTEnhancedScrollView *scrollView = (RCTEnhancedScrollView *)_scrollView;
// Only apply contentInset from props if centerContent is disabled
// When centerContent is enabled, the inset is calculated by centerContentIfNeeded
if (oldScrollViewProps.contentInset != newScrollViewProps.contentInset && !newScrollViewProps.centerContent) {
_scrollView.contentInset = RCTUIEdgeInsetsFromEdgeInsets(newScrollViewProps.contentInset);
}
if (oldScrollViewProps.contentOffset != newScrollViewProps.contentOffset) {
_scrollView.contentOffset = RCTCGPointFromPoint(newScrollViewProps.contentOffset);
}
Expand Down
Loading