diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index edc8d0a8c..a9a572760 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -81,6 +81,11 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width return [[superDescription substringToIndex:superDescription.length - 1] stringByAppendingFormat:@"; text: %@>", [self attributedString].string]; } +- (BOOL)isCSSLeafNode +{ + return YES; +} + - (void)contentSizeMultiplierDidChange:(NSNotification *)note { [self dirtyLayout]; @@ -443,18 +448,6 @@ static css_dim_t RCTMeasure(void *context, float width, css_measure_mode_t width } } -- (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex -{ - [super insertReactSubview:subview atIndex:atIndex]; - self.cssNode->children_count = 0; -} - -- (void)removeReactSubview:(RCTShadowView *)subview -{ - [super removeReactSubview:subview]; - self.cssNode->children_count = 0; -} - - (void)setBackgroundColor:(UIColor *)backgroundColor { super.backgroundColor = backgroundColor; diff --git a/React/Views/RCTShadowView.h b/React/Views/RCTShadowView.h index 6c5bbf17c..f6f149d81 100644 --- a/React/Views/RCTShadowView.h +++ b/React/Views/RCTShadowView.h @@ -189,6 +189,13 @@ typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry - (void)dirtyLayout NS_REQUIRES_SUPER; - (BOOL)isLayoutDirty; +/** + * Return whether or not this node acts as a leaf node in the eyes of CSSLayout. For example + * RCTShadowText has children which it does not want CSSLayout to lay out so in the eyes of + * CSSLayout it is a leaf node. + */ +- (BOOL)isCSSLeafNode; + - (void)dirtyPropagation NS_REQUIRES_SUPER; - (BOOL)isPropagationDirty; diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index a8cd30ae5..6fcb72128 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -320,6 +320,11 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st return _layoutLifecycle != RCTUpdateLifecycleComputed; } +- (BOOL)isCSSLeafNode +{ + return NO; +} + - (void)dirtyPropagation { if (_propagationLifecycle != RCTUpdateLifecycleDirtied) { @@ -354,7 +359,7 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st - (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex { [_reactSubviews insertObject:subview atIndex:atIndex]; - _cssNode->children_count = (int)_reactSubviews.count; + _cssNode->children_count = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count; subview->_superview = self; _didUpdateSubviews = YES; [self dirtyText]; @@ -370,7 +375,7 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st _didUpdateSubviews = YES; subview->_superview = nil; [_reactSubviews removeObject:subview]; - _cssNode->children_count = (int)_reactSubviews.count; + _cssNode->children_count = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count; } - (NSArray *)reactSubviews