From 7e899348c74238a4a042380f86a8fe0d7e05511b Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 8 Sep 2020 16:41:28 -0700 Subject: [PATCH] Fabric: Better error reporting in UIView+ComponentViewProtocol 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 --- .../Mounting/UIView+ComponentViewProtocol.mm | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm index 82bfa1a5515..c0de92d8c21 100644 --- a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm @@ -30,16 +30,29 @@ using namespace facebook::react; - (void)mountChildComponentView:(UIView *)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 *)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]; }