diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 859b4582980e8a..848e26d2678584 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -498,16 +498,15 @@ - (void)_remountChildren visibleFrame.size.width *= scale; visibleFrame.size.height *= scale; +#ifndef NDEBUG + NSMutableArray *> *expectedSubviews = [NSMutableArray new]; +#endif + NSInteger mountedIndex = 0; for (UIView *componentView in _childComponentViews) { BOOL shouldBeMounted = YES; BOOL isMounted = componentView.superview != nil; - // If a view is mounted, it must be mounted exactly at `mountedIndex` position. - RCTAssert( - !isMounted || [_containerView.subviews objectAtIndex:mountedIndex] == componentView, - @"Attempt to unmount improperly mounted component view."); - // It's simpler and faster to not mess with views that are not `RCTViewComponentView` subclasses. if ([componentView isKindOfClass:[RCTViewComponentView class]]) { RCTViewComponentView *viewComponentView = (RCTViewComponentView *)componentView; @@ -529,7 +528,24 @@ - (void)_remountChildren if (shouldBeMounted) { mountedIndex++; } + +#ifndef NDEBUG + if (shouldBeMounted) { + [expectedSubviews addObject:componentView]; + } +#endif + } + +#ifndef NDEBUG + RCTAssert( + _containerView.subviews.count == expectedSubviews.count, + @"-[RCTScrollViewComponentView _remountChildren]: Inconsistency detected."); + for (NSInteger i = 0; i < expectedSubviews.count; i++) { + RCTAssert( + [_containerView.subviews objectAtIndex:i] == [expectedSubviews objectAtIndex:i], + @"-[RCTScrollViewComponentView _remountChildren]: Inconsistency detected."); } +#endif } #pragma mark - RCTScrollableProtocol