RCTShadowViews's cssNode property was renamed to yogaNode

Reviewed By: javache

Differential Revision: D4590104

fbshipit-source-id: 7767aaa62bcbdce2746c3a26543052dd46be63e0
This commit is contained in:
Valentin Shergin 2017-02-21 08:43:34 -08:00 committed by Facebook Github Bot
parent a7d3940de6
commit e361ce8673
5 changed files with 92 additions and 66 deletions

View File

@ -29,9 +29,9 @@
[super setUp];
self.parentView = [RCTRootShadowView new];
YGNodeStyleSetFlexDirection(self.parentView.cssNode, YGFlexDirectionColumn);
YGNodeStyleSetWidth(self.parentView.cssNode, 440);
YGNodeStyleSetHeight(self.parentView.cssNode, 440);
YGNodeStyleSetFlexDirection(self.parentView.yogaNode, YGFlexDirectionColumn);
YGNodeStyleSetWidth(self.parentView.yogaNode, 440);
YGNodeStyleSetHeight(self.parentView.yogaNode, 440);
self.parentView.reactTag = @1; // must be valid rootView tag
}
@ -82,10 +82,10 @@
YGNodeStyleSetFlex(node, 1);
}];
YGNodeStyleSetPadding(self.parentView.cssNode, YGEdgeLeft, 10);
YGNodeStyleSetPadding(self.parentView.cssNode, YGEdgeTop, 10);
YGNodeStyleSetPadding(self.parentView.cssNode, YGEdgeRight, 10);
YGNodeStyleSetPadding(self.parentView.cssNode, YGEdgeBottom, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeLeft, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeTop, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeRight, 10);
YGNodeStyleSetPadding(self.parentView.yogaNode, YGEdgeBottom, 10);
[self.parentView insertReactSubview:headerView atIndex:0];
[self.parentView insertReactSubview:mainView atIndex:1];
@ -167,8 +167,8 @@
- (void)testDoesNotAssignSuggestedDimensionsWhenStyledWithFlexAttribute
{
float parentWidth = YGNodeStyleGetWidth(self.parentView.cssNode).value;
float parentHeight = YGNodeStyleGetHeight(self.parentView.cssNode).value;
float parentWidth = YGNodeStyleGetWidth(self.parentView.yogaNode).value;
float parentHeight = YGNodeStyleGetHeight(self.parentView.yogaNode).value;
[self _withShadowViewWithStyle:^(YGNodeRef node) {
YGNodeStyleSetFlex(node, 1);
}
@ -194,7 +194,7 @@
- (RCTShadowView *)_shadowViewWithConfig:(void(^)(YGNodeRef node))configBlock
{
RCTShadowView *shadowView = [RCTShadowView new];
configBlock(shadowView.cssNode);
configBlock(shadowView.yogaNode);
return shadowView;
}

View File

@ -73,7 +73,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
_writingDirection = NSWritingDirectionNatural;
_cachedEffectiveLayoutDirection = UIUserInterfaceLayoutDirectionLeftToRight;
YGNodeSetMeasureFunc(self.cssNode, RCTMeasure);
YGNodeSetMeasureFunc(self.yogaNode, RCTMeasure);
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contentSizeMultiplierDidChange:)
@ -94,14 +94,14 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
return [[superDescription substringToIndex:superDescription.length - 1] stringByAppendingFormat:@"; text: %@>", [self attributedString].string];
}
- (BOOL)isCSSLeafNode
- (BOOL)isYogaLeafNode
{
return YES;
}
- (void)contentSizeMultiplierDidChange:(NSNotification *)note
{
YGNodeMarkDirty(self.cssNode);
YGNodeMarkDirty(self.yogaNode);
[self dirtyText];
}
@ -166,7 +166,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
NSRange characterRange = [layoutManager characterRangeForGlyphRange:glyphRange actualGlyphRange:NULL];
[layoutManager.textStorage enumerateAttribute:RCTShadowViewAttributeName inRange:characterRange options:0 usingBlock:^(RCTShadowView *child, NSRange range, BOOL *_) {
if (child) {
YGNodeRef childNode = child.cssNode;
YGNodeRef childNode = child.yogaNode;
float width = YGNodeStyleGetWidth(childNode).value;
float height = YGNodeStyleGetHeight(childNode).value;
if (YGFloatIsUndefined(width) || YGFloatIsUndefined(height)) {
@ -324,8 +324,8 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
[attributedString appendAttributedString:[[NSAttributedString alloc] initWithString:shadowRawText.text ?: @""]];
[child setTextComputed];
} else {
float width = YGNodeStyleGetWidth(child.cssNode).value;
float height = YGNodeStyleGetHeight(child.cssNode).value;
float width = YGNodeStyleGetWidth(child.yogaNode).value;
float height = YGNodeStyleGetHeight(child.yogaNode).value;
if (YGFloatIsUndefined(width) || YGFloatIsUndefined(height)) {
RCTLogError(@"Views nested within a <Text> must have a width and height");
}
@ -365,7 +365,7 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
// create a non-mutable attributedString for use by the Text system which avoids copies down the line
_cachedAttributedString = [[NSAttributedString alloc] initWithAttributedString:attributedString];
YGNodeMarkDirty(self.cssNode);
YGNodeMarkDirty(self.yogaNode);
return _cachedAttributedString;
}

View File

@ -33,10 +33,10 @@
float availableWidth = _availableSize.width == INFINITY ? YGUndefined : _availableSize.width;
float availableHeight = _availableSize.height == INFINITY ? YGUndefined : _availableSize.height;
YGNodeCalculateLayout(self.cssNode, availableWidth, availableHeight, _baseDirection);
YGNodeCalculateLayout(self.yogaNode, availableWidth, availableHeight, _baseDirection);
NSMutableSet<RCTShadowView *> *viewsWithNewFrame = [NSMutableSet set];
[self applyLayoutNode:self.cssNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:CGPointZero];
[self applyLayoutNode:self.yogaNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:CGPointZero];
return viewsWithNewFrame;
}

View File

@ -44,7 +44,7 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
- (void)removeReactSubview:(RCTShadowView *)subview NS_REQUIRES_SUPER;
@property (nonatomic, weak, readonly) RCTShadowView *superview;
@property (nonatomic, assign, readonly) YGNodeRef cssNode;
@property (nonatomic, assign, readonly) YGNodeRef yogaNode;
@property (nonatomic, copy) NSString *viewName;
@property (nonatomic, strong) UIColor *backgroundColor; // Used to propagate to children
@property (nonatomic, copy) RCTDirectEventBlock onLayout;
@ -211,11 +211,11 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
absolutePosition:(CGPoint)absolutePosition;
/**
* Return whether or not this node acts as a leaf node in the eyes of Yoga. For example
* RCTShadowText has children which it does not want Yoga to lay out so in the eyes of
* Yoga it is a leaf node.
* Return whether or not this node acts as a leaf node in the eyes of Yoga.
* For example `RCTShadowText` has children which it does not want Yoga
* to lay out so in the eyes of Yoga it is a leaf node.
*/
- (BOOL)isCSSLeafNode;
- (BOOL)isYogaLeafNode;
- (void)dirtyPropagation NS_REQUIRES_SUPER;
- (BOOL)isPropagationDirty;
@ -246,3 +246,13 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
- (BOOL)viewIsDescendantOf:(RCTShadowView *)ancestor;
@end
@interface RCTShadowView (Deprecated)
@property (nonatomic, assign, readonly) YGNodeRef cssNode
__deprecated_msg("Use `yogaNode` instead.");
- (BOOL)isCSSLeafNode
__deprecated_msg("Use `isYogaLeafNode` instead.");
@end

View File

@ -48,7 +48,7 @@ typedef NS_ENUM(unsigned int, meta_prop_t) {
@synthesize reactTag = _reactTag;
// cssNode api
// YogaNode API
static void RCTPrint(YGNodeRef node)
{
@ -133,7 +133,7 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
YGNodeSetHasNewLayout(node, false);
#if RCT_DEBUG
// This works around a breaking change in css-layout where setting flexBasis needs to be set explicitly, instead of relying on flex to propagate.
// This works around a breaking change in Yoga layout where setting flexBasis needs to be set explicitly, instead of relying on flex to propagate.
// We check for it by seeing if a width/height is provided along with a flexBasis of 0 and the width/height is laid out as 0.
if (YGNodeStyleGetFlexBasis(node).unit == YGUnitPoint && YGNodeStyleGetFlexBasis(node).value == 0 &&
((YGNodeStyleGetWidth(node).unit == YGUnitPoint && YGNodeStyleGetWidth(node).value > 0 && YGNodeLayoutGetWidth(node) == 0) ||
@ -251,15 +251,15 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
}
if (!CGRectEqualToRect(frame, _frame)) {
YGNodeStyleSetPositionType(_cssNode, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(_cssNode, frame.size.width);
YGNodeStyleSetHeight(_cssNode, frame.size.height);
YGNodeStyleSetPosition(_cssNode, YGEdgeLeft, frame.origin.x);
YGNodeStyleSetPosition(_cssNode, YGEdgeTop, frame.origin.y);
YGNodeStyleSetPositionType(_yogaNode, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(_yogaNode, frame.size.width);
YGNodeStyleSetHeight(_yogaNode, frame.size.height);
YGNodeStyleSetPosition(_yogaNode, YGEdgeLeft, frame.origin.x);
YGNodeStyleSetPosition(_yogaNode, YGEdgeTop, frame.origin.y);
}
YGNodeCalculateLayout(_cssNode, frame.size.width, frame.size.height, YGDirectionInherit);
[self applyLayoutNode:_cssNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:absolutePosition];
YGNodeCalculateLayout(_yogaNode, frame.size.width, frame.size.height, YGDirectionInherit);
[self applyLayoutNode:_yogaNode viewsWithNewFrame:viewsWithNewFrame absolutePosition:absolutePosition];
}
- (CGRect)measureLayoutRelativeToAncestor:(RCTShadowView *)ancestor
@ -310,9 +310,9 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
_reactSubviews = [NSMutableArray array];
_cssNode = YGNodeNew();
YGNodeSetContext(_cssNode, (__bridge void *)self);
YGNodeSetPrintFunc(_cssNode, RCTPrint);
_yogaNode = YGNodeNew();
YGNodeSetContext(_yogaNode, (__bridge void *)self);
YGNodeSetPrintFunc(_yogaNode, RCTPrint);
}
return self;
}
@ -324,10 +324,10 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
- (void)dealloc
{
YGNodeFree(_cssNode);
YGNodeFree(_yogaNode);
}
- (BOOL)isCSSLeafNode
- (BOOL)isYogaLeafNode
{
return NO;
}
@ -366,8 +366,8 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
- (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
{
[_reactSubviews insertObject:subview atIndex:atIndex];
if (![self isCSSLeafNode]) {
YGNodeInsertChild(_cssNode, subview.cssNode, (uint32_t)atIndex);
if (![self isYogaLeafNode]) {
YGNodeInsertChild(_yogaNode, subview.yogaNode, (uint32_t)atIndex);
}
subview->_superview = self;
_didUpdateSubviews = YES;
@ -382,8 +382,8 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
_didUpdateSubviews = YES;
subview->_superview = nil;
[_reactSubviews removeObject:subview];
if (![self isCSSLeafNode]) {
YGNodeRemoveChild(_cssNode, subview.cssNode);
if (![self isYogaLeafNode]) {
YGNodeRemoveChild(_yogaNode, subview.yogaNode);
}
}
@ -444,7 +444,7 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
- (UIUserInterfaceLayoutDirection)effectiveLayoutDirection {
// Even if `YGNodeLayoutGetDirection` can return `YGDirectionInherit` here, it actually means
// that Yoga will use LTR layout for the view (even if layout process is not finished yet).
return YGNodeLayoutGetDirection(self.cssNode) == YGDirectionRTL ? UIUserInterfaceLayoutDirectionRightToLeft : UIUserInterfaceLayoutDirectionLeftToRight;
return YGNodeLayoutGetDirection(_yogaNode) == YGDirectionRTL ? UIUserInterfaceLayoutDirectionRightToLeft : UIUserInterfaceLayoutDirectionLeftToRight;
}
// Margin
@ -492,10 +492,10 @@ RCT_PADDING_PROPERTY(Right, RIGHT)
- (UIEdgeInsets)paddingAsInsets
{
return (UIEdgeInsets){
YGNodeLayoutGetPadding(_cssNode, YGEdgeTop),
YGNodeLayoutGetPadding(_cssNode, YGEdgeLeft),
YGNodeLayoutGetPadding(_cssNode, YGEdgeBottom),
YGNodeLayoutGetPadding(_cssNode, YGEdgeRight)
YGNodeLayoutGetPadding(_yogaNode, YGEdgeTop),
YGNodeLayoutGetPadding(_yogaNode, YGEdgeLeft),
YGNodeLayoutGetPadding(_yogaNode, YGEdgeBottom),
YGNodeLayoutGetPadding(_yogaNode, YGEdgeRight)
};
}
@ -523,12 +523,12 @@ RCT_BORDER_PROPERTY(Right, RIGHT)
#define RCT_DIMENSION_PROPERTY(setProp, getProp, cssProp) \
- (void)set##setProp:(YGValue)value \
{ \
RCT_SET_YGVALUE(value, YGNodeStyleSet##cssProp, _cssNode); \
RCT_SET_YGVALUE(value, YGNodeStyleSet##cssProp, _yogaNode); \
[self dirtyText]; \
} \
- (YGValue)getProp \
{ \
return YGNodeStyleGet##cssProp(_cssNode); \
return YGNodeStyleGet##cssProp(_yogaNode); \
}
RCT_DIMENSION_PROPERTY(Width, width, Width)
@ -543,12 +543,12 @@ RCT_DIMENSION_PROPERTY(MaxHeight, maxHeight, MaxHeight)
#define RCT_POSITION_PROPERTY(setProp, getProp, edge) \
- (void)set##setProp:(YGValue)value \
{ \
RCT_SET_YGVALUE(value, YGNodeStyleSetPosition, _cssNode, edge); \
RCT_SET_YGVALUE(value, YGNodeStyleSetPosition, _yogaNode, edge); \
[self dirtyText]; \
} \
- (YGValue)getProp \
{ \
return YGNodeStyleGetPosition(_cssNode, edge); \
return YGNodeStyleGetPosition(_yogaNode, edge); \
}
RCT_POSITION_PROPERTY(Top, top, YGEdgeTop)
@ -560,8 +560,8 @@ RCT_POSITION_PROPERTY(Left, left, YGEdgeStart)
- (CGSize)size
{
YGValue width = YGNodeStyleGetWidth(_cssNode);
YGValue height = YGNodeStyleGetHeight(_cssNode);
YGValue width = YGNodeStyleGetWidth(_yogaNode);
YGValue height = YGNodeStyleGetHeight(_yogaNode);
return CGSizeMake(
width.unit == YGUnitPoint ? width.value : NAN,
@ -571,8 +571,8 @@ RCT_POSITION_PROPERTY(Left, left, YGEdgeStart)
- (void)setSize:(CGSize)size
{
YGNodeStyleSetWidth(_cssNode, size.width);
YGNodeStyleSetHeight(_cssNode, size.height);
YGNodeStyleSetWidth(_yogaNode, size.width);
YGNodeStyleSetHeight(_yogaNode, size.height);
}
// IntrinsicContentSize
@ -624,39 +624,39 @@ static inline YGSize RCTShadowViewMeasure(YGNodeRef node, float width, YGMeasure
_intrinsicContentSize = intrinsicContentSize;
if (CGSizeEqualToSize(_intrinsicContentSize, CGSizeMake(UIViewNoIntrinsicMetric, UIViewNoIntrinsicMetric))) {
YGNodeSetMeasureFunc(_cssNode, NULL);
YGNodeSetMeasureFunc(_yogaNode, NULL);
} else {
YGNodeSetMeasureFunc(_cssNode, RCTShadowViewMeasure);
YGNodeSetMeasureFunc(_yogaNode, RCTShadowViewMeasure);
}
YGNodeMarkDirty(_cssNode);
YGNodeMarkDirty(_yogaNode);
}
// Flex
- (void)setFlex:(float)value
{
YGNodeStyleSetFlex(_cssNode, value);
YGNodeStyleSetFlex(_yogaNode, value);
}
- (void)setFlexBasis:(YGValue)value
{
RCT_SET_YGVALUE(value, YGNodeStyleSetFlexBasis, _cssNode);
RCT_SET_YGVALUE(value, YGNodeStyleSetFlexBasis, _yogaNode);
}
- (YGValue)flexBasis
{
return YGNodeStyleGetFlexBasis(_cssNode);
return YGNodeStyleGetFlexBasis(_yogaNode);
}
#define RCT_STYLE_PROPERTY(setProp, getProp, cssProp, type) \
- (void)set##setProp:(type)value \
{ \
YGNodeStyleSet##cssProp(_cssNode, value); \
YGNodeStyleSet##cssProp(_yogaNode, value); \
} \
- (type)getProp \
{ \
return YGNodeStyleGet##cssProp(_cssNode); \
return YGNodeStyleGet##cssProp(_yogaNode); \
}
RCT_STYLE_PROPERTY(FlexGrow, flexGrow, FlexGrow, float)
@ -695,13 +695,13 @@ RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float)
- (void)didSetProps:(__unused NSArray<NSString *> *)changedProps
{
if (_recomputePadding) {
RCTProcessMetaPropsPadding(_paddingMetaProps, _cssNode);
RCTProcessMetaPropsPadding(_paddingMetaProps, _yogaNode);
}
if (_recomputeMargin) {
RCTProcessMetaPropsMargin(_marginMetaProps, _cssNode);
RCTProcessMetaPropsMargin(_marginMetaProps, _yogaNode);
}
if (_recomputeBorder) {
RCTProcessMetaPropsBorder(_borderMetaProps, _cssNode);
RCTProcessMetaPropsBorder(_borderMetaProps, _yogaNode);
}
_recomputeMargin = NO;
_recomputePadding = NO;
@ -709,3 +709,19 @@ RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float)
}
@end
@implementation RCTShadowView (Deprecated)
- (YGNodeRef)cssNode
{
RCTLogWarn(@"Calling deprecated `[-RCTShadowView cssNode]`.");
return _yogaNode;
}
- (BOOL)isCSSLeafNode
{
RCTLogWarn(@"Calling deprecated `[-RCTShadowView isCSSLeafNode]`.");
return self.isYogaLeafNode;
}
@end