Skip to content

Commit

Permalink
Add debug message to RCTShadowView when we insert a subview incorrectly
Browse files Browse the repository at this point in the history
Summary:
@public
This will provide a more useful error message and hopefully allow us to debug the issue further.

Reviewed By: JoshuaGross

Differential Revision: D17793693

fbshipit-source-id: 848ae658200ea5e3892d8a88888599c1c248c994
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed Oct 7, 2019
1 parent c71bbb0 commit 72c0390
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions React/Views/RCTShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ - (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
{
RCTAssert(self.canHaveSubviews, @"Attempt to insert subview inside leaf view.");

// TODO(T55181688): Delete after getting crashes with a view hierarchy.
if (atIndex > [_reactSubviews count]) {
RCTShadowView *ancestor = self;
for (NSInteger i = 0; i < 5 && [ancestor superview]; i++) {
ancestor = [ancestor superview];
}
RCTAssert(NO, @"Tried to insert subview on view %@ with ancestor description %@", self, ancestor);
}

[_reactSubviews insertObject:subview atIndex:atIndex];
if (![self isYogaLeafNode]) {
YGNodeInsertChild(_yogaNode, subview.yogaNode, (uint32_t)atIndex);
Expand Down

0 comments on commit 72c0390

Please sign in to comment.