Skip to content

Commit

Permalink
Fixed incorrect assert in RCTScrollViewComponentView
Browse files Browse the repository at this point in the history
Summary:
This diff removes an incorrect assert and replaces it with a debug-only verification phase that compares "what we want" with "what we get".

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: PeteTheHeat

Differential Revision: D23983123

fbshipit-source-id: 03a628b4f8baa1f5fe4b55354b7c943e38b5e537
  • Loading branch information
shergin authored and facebook-github-bot committed Oct 1, 2020
1 parent 18f7aba commit c421838
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,16 +498,15 @@ - (void)_remountChildren
visibleFrame.size.width *= scale;
visibleFrame.size.height *= scale;

#ifndef NDEBUG
NSMutableArray<UIView<RCTComponentViewProtocol> *> *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;
Expand All @@ -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
Expand Down

0 comments on commit c421838

Please sign in to comment.