Skip to content

Commit

Permalink
Fabric: Better error reporting in UIView+ComponentViewProtocol
Browse files Browse the repository at this point in the history
Summary:
We need this to make crash logs more actionable. For now we know that those asserts fire so we should make them actionable.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D23580103

fbshipit-source-id: 8532e33b016e738a4f128c9b547c33d204610bcc
  • Loading branch information
shergin authored and facebook-github-bot committed Sep 8, 2020
1 parent b7b0e23 commit 7e89934
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions React/Fabric/Mounting/UIView+ComponentViewProtocol.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,29 @@ + (ComponentDescriptorProvider)componentDescriptorProvider

- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
RCTAssert(childComponentView.superview == nil, @"Attempt to mount already mounted component view.");
RCTAssert(
childComponentView.superview == nil,
@"Attempt to mount already mounted component view. (parent: %@, child: %@, index: %@)",
self,
childComponentView,
@(index));
[self insertSubview:childComponentView atIndex:index];
}

- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
RCTAssert(childComponentView.superview == self, @"Attempt to unmount improperly mounted component view.");
RCTAssert(
[self.subviews objectAtIndex:index] == childComponentView,
@"Attempt to unmount improperly mounted component view.");
childComponentView.superview == self,
@"Attempt to unmount a view which is mounted inside different view. (parent: %@, child: %@, index: %@)",
self,
childComponentView,
@(index));
RCTAssert(
(self.subviews.count > index) && [self.subviews objectAtIndex:index] == childComponentView,
@"Attempt to unmount a view which has a different index. (parent: %@, child: %@, index: %@)",
self,
childComponentView,
@(index));

[childComponentView removeFromSuperview];
}
Expand Down

0 comments on commit 7e89934

Please sign in to comment.