Skip to content

Commit

Permalink
Add [RCTShadowView isCSSLeaf] for skipping css tree of children
Browse files Browse the repository at this point in the history
Summary: RCTShadowText currently overrides a couple methods from RCTShadowView to reset the count of the cssNode children to 0. This diff instead moves that logic into RCTShadowView behind a configurable flag making it easier to reason about.

Reviewed By: javache

Differential Revision: D3586434

fbshipit-source-id: 4389a8119dc49e3fc4357174c87c0c69287ae385
  • Loading branch information
Emil Sjolander authored and Facebook Github Bot 7 committed Jul 20, 2016
1 parent 1025775 commit 0587c85
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
17 changes: 5 additions & 12 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ - (NSString *)description
return [[superDescription substringToIndex:superDescription.length - 1] stringByAppendingFormat:@"; text: %@>", [self attributedString].string];
}

- (BOOL)isCSSLeafNode
{
return YES;
}

- (void)contentSizeMultiplierDidChange:(NSNotification *)note
{
[self dirtyLayout];
Expand Down Expand Up @@ -443,18 +448,6 @@ - (void)_setParagraphStyleOnAttributedString:(NSMutableAttributedString *)attrib
}
}

- (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;
Expand Down
7 changes: 7 additions & 0 deletions React/Views/RCTShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *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;

Expand Down
9 changes: 7 additions & 2 deletions React/Views/RCTShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ - (BOOL)isLayoutDirty
return _layoutLifecycle != RCTUpdateLifecycleComputed;
}

- (BOOL)isCSSLeafNode
{
return NO;
}

- (void)dirtyPropagation
{
if (_propagationLifecycle != RCTUpdateLifecycleDirtied) {
Expand Down Expand Up @@ -354,7 +359,7 @@ - (void)setTextComputed
- (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];
Expand All @@ -370,7 +375,7 @@ - (void)removeReactSubview:(RCTShadowView *)subview
_didUpdateSubviews = YES;
subview->_superview = nil;
[_reactSubviews removeObject:subview];
_cssNode->children_count = (int)_reactSubviews.count;
_cssNode->children_count = [self isCSSLeafNode] ? 0 : (int)_reactSubviews.count;
}

- (NSArray<RCTShadowView *> *)reactSubviews
Expand Down

0 comments on commit 0587c85

Please sign in to comment.