Add react_recursiveDescription to UIView and debugging to RCTScrollView

Summary:
@public
RCTScrollView sometimes asserts with another contentView set. While this doesn't crash, it'd be good to know what's causing the assert. This will add a recursive description of the contentView.

Changelog: [iOS] [Changed] RCTScrollView: added debugging to help fix assert

Reviewed By: PeteTheHeat

Differential Revision: D15049869

fbshipit-source-id: 5431de7764881922327c6c0a3bdd392668396b58
This commit is contained in:
Mehdi Mulani
2019-04-23 14:55:09 -07:00
committed by Facebook Github Bot
parent 7e9d6ea51d
commit 2c0af4b317
3 changed files with 31 additions and 1 deletions

View File

@@ -476,7 +476,7 @@ static inline void RCTApplyTransformationAccordingLayoutDirection(UIView *view,
} else
#endif
{
RCTAssert(_contentView == nil, @"RCTScrollView may only contain a single subview");
RCTAssert(_contentView == nil, @"RCTScrollView may only contain a single subview, the already set subview looks like: %@", [_contentView react_recursiveDescription]);
_contentView = view;
RCTApplyTransformationAccordingLayoutDirection(_contentView, self.reactLayoutDirection);
[_scrollView addSubview:view];

View File

@@ -113,4 +113,10 @@
*/
@property (nonatomic, readonly) UIView *reactAccessibilityElement;
/**
* Used in debugging to get a description of the view hierarchy rooted at
* the current view.
*/
- (NSString *)react_recursiveDescription;
@end

View File

@@ -297,4 +297,28 @@
return self;
}
#pragma mark - Debug
- (void)react_addRecursiveDescriptionToString:(NSMutableString *)string atLevel:(NSUInteger)level
{
for (NSUInteger i = 0; i < level; i++) {
[string appendString:@" | "];
}
[string appendString:self.description];
[string appendString:@"\n"];
for (UIView *subview in self.subviews) {
[subview react_addRecursiveDescriptionToString:string atLevel:level + 1];
}
}
- (NSString *)react_recursiveDescription
{
NSMutableString *description = [NSMutableString string];
[self react_addRecursiveDescriptionToString:description atLevel:0];
return description;
}
@end