mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 17:34:07 +08:00
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:
committed by
Facebook Github Bot
parent
7e9d6ea51d
commit
2c0af4b317
@@ -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];
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user