-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Yoga Beta] Improvements to the experimental support for Yoga layout. #59
Changes from all commits
605e369
de4f1f0
5cdf50d
8cac04c
26bd1b3
64adecb
75287ce
aee040b
e2a13a7
478f473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
- Add support for IGListKit post-removal-of-IGListSectionType, in preparation for IGListKit 3.0.0 release. (Adlai-Holler)[https://github.com/Adlai-Holler] (#49)[https://github.com/TextureGroup/Texture/pull/49] | ||
- Fix `__has_include` check in ASLog.h [Philipp Smorygo]([email protected]) | ||
- Fix potential deadlock in ASControlNode [Garrett Moon](https://github.com/garrettmoon) | ||
- [Yoga Beta] Improvements to the experimental support for Yoga layout [Scott Goodson](appleguy) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,10 +147,15 @@ float yogaDimensionToPercent(ASDimension dimension) | |
ASDimension dimensionForEdgeWithEdgeInsets(YGEdge edge, ASEdgeInsets insets) | ||
{ | ||
switch (edge) { | ||
case YGEdgeLeft: return insets.left; | ||
case YGEdgeTop: return insets.top; | ||
case YGEdgeRight: return insets.right; | ||
case YGEdgeBottom: return insets.bottom; | ||
case YGEdgeLeft: return insets.left; | ||
case YGEdgeTop: return insets.top; | ||
case YGEdgeRight: return insets.right; | ||
case YGEdgeBottom: return insets.bottom; | ||
case YGEdgeStart: return insets.start; | ||
case YGEdgeEnd: return insets.end; | ||
case YGEdgeHorizontal: return insets.horizontal; | ||
case YGEdgeVertical: return insets.vertical; | ||
case YGEdgeAll: return insets.all; | ||
default: ASDisplayNodeCAssert(NO, @"YGEdge other than ASEdgeInsets is not supported."); | ||
return ASDimensionAuto; | ||
} | ||
|
@@ -314,10 +319,9 @@ - (void)setupYogaCalculatedLayout | |
|
||
- (void)setYogaMeasureFuncIfNeeded | ||
{ | ||
// Manual size calculation via calculateSizeThatFits: | ||
// This will be used for ASTextNode, as well as any other leaf node that has no layout spec. | ||
if ((self.methodOverrides & ASDisplayNodeMethodOverrideLayoutSpecThatFits) == NO | ||
&& self.layoutSpecBlock == NULL && self.yogaChildren.count == 0) { | ||
// Size calculation via calculateSizeThatFits: or layoutSpecThatFits: | ||
// This will be used for ASTextNode, as well as any other node that has no Yoga children | ||
if (self.yogaChildren.count == 0) { | ||
YGNodeRef yogaNode = self.yogaNode; // Use property to assign Ref if needed. | ||
YGNodeSetContext(yogaNode, (__bridge void *)self); | ||
YGNodeSetMeasureFunc(yogaNode, &ASLayoutElementYogaMeasureFunc); | ||
|
@@ -333,8 +337,24 @@ - (void)invalidateCalculatedYogaLayout | |
} | ||
} | ||
|
||
- (void)semanticContentAttributeDidChange:(UISemanticContentAttribute)attribute | ||
{ | ||
if (AS_AT_LEAST_IOS9) { | ||
UIUserInterfaceLayoutDirection layoutDirection = | ||
[UIView userInterfaceLayoutDirectionForSemanticContentAttribute:attribute]; | ||
self.style.direction = (layoutDirection == UIUserInterfaceLayoutDirectionLeftToRight | ||
? YGDirectionLTR : YGDirectionRTL); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! That class method may not be safe off-main, but I expect you've considered that. Even if so, the risk here is teeny tiny. |
||
} | ||
|
||
- (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize | ||
{ | ||
if (self.yogaParent) { | ||
if (ASHierarchyStateIncludesYogaLayoutMeasuring(self.hierarchyState) == NO) { | ||
[self _setNeedsLayoutFromAbove]; | ||
} | ||
return; | ||
} | ||
if (ASHierarchyStateIncludesYogaLayoutMeasuring(self.hierarchyState)) { | ||
ASDisplayNodeAssert(NO, @"A Yoga layout is being performed by a parent; children must not perform their own until it is done! %@", [self displayNodeRecursiveDescription]); | ||
return; | ||
|
@@ -356,14 +376,14 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize | |
ASLayoutElementStyle *style = node.style; | ||
YGNodeRef yogaNode = node.yogaNode; | ||
|
||
YGNodeStyleSetDirection (yogaNode, YGDirectionInherit); | ||
YGNodeStyleSetDirection (yogaNode, style.direction); | ||
|
||
YGNodeStyleSetFlexWrap (yogaNode, style.flexWrap); | ||
YGNodeStyleSetFlexGrow (yogaNode, style.flexGrow); | ||
YGNodeStyleSetFlexShrink (yogaNode, style.flexShrink); | ||
YGNODE_STYLE_SET_DIMENSION (yogaNode, FlexBasis, style.flexBasis); | ||
|
||
YGNodeStyleSetFlexDirection (yogaNode, yogaFlexDirection(style.direction)); | ||
YGNodeStyleSetFlexDirection (yogaNode, yogaFlexDirection(style.flexDirection)); | ||
YGNodeStyleSetJustifyContent(yogaNode, yogaJustifyContent(style.justifyContent)); | ||
YGNodeStyleSetAlignSelf (yogaNode, yogaAlignSelf(style.alignSelf)); | ||
ASStackLayoutAlignItems alignItems = style.alignItems; | ||
|
@@ -378,12 +398,12 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize | |
ASEdgeInsets border = style.border; | ||
|
||
YGEdge edge = YGEdgeLeft; | ||
for (int i = 0; i < 4; i++) { | ||
for (int i = 0; i < YGEdgeAll + 1; ++i) { | ||
YGNODE_STYLE_SET_DIMENSION_WITH_EDGE(yogaNode, Position, dimensionForEdgeWithEdgeInsets(edge, position), edge); | ||
YGNODE_STYLE_SET_DIMENSION_WITH_EDGE(yogaNode, Margin, dimensionForEdgeWithEdgeInsets(edge, margin), edge); | ||
YGNODE_STYLE_SET_DIMENSION_WITH_EDGE(yogaNode, Padding, dimensionForEdgeWithEdgeInsets(edge, padding), edge); | ||
YGNODE_STYLE_SET_FLOAT_WITH_EDGE(yogaNode, Border, dimensionForEdgeWithEdgeInsets(edge, border), edge); | ||
edge = (edge == YGEdgeLeft ? YGEdgeTop : (edge == YGEdgeTop ? YGEdgeRight : YGEdgeBottom)); | ||
edge = (YGEdge)(edge + 1); | ||
} | ||
|
||
CGFloat aspectRatio = style.aspectRatio; | ||
|
@@ -406,7 +426,6 @@ - (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize | |
[node setYogaMeasureFuncIfNeeded]; | ||
|
||
/* TODO(appleguy): STYLE SETTER METHODS LEFT TO IMPLEMENT | ||
void YGNodeStyleSetFlexDirection(YGNodeRef node, YGFlexDirection flexDirection); | ||
void YGNodeStyleSetOverflow(YGNodeRef node, YGOverflow overflow); | ||
void YGNodeStyleSetFlex(YGNodeRef node, float flex); | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,8 @@ @implementation ASLayoutElementStyle { | |
std::atomic<CGPoint> _layoutPosition; | ||
|
||
#if YOGA | ||
std::atomic<ASStackLayoutDirection> _direction; | ||
std::atomic<ASStackLayoutDirection> _flexDirection; | ||
std::atomic<YGDirection> _direction; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (You knew it was coming!) Maybe these would be better-off as Objective-C atomic properties to improve performance and cut down on boilerplate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As all of them are currently c++ atomics let's go with it for now and do the whole change in a another diff if we want to. |
||
std::atomic<CGFloat> _spacing; | ||
std::atomic<ASStackLayoutJustifyContent> _justifyContent; | ||
std::atomic<ASStackLayoutAlignItems> _alignItems; | ||
|
@@ -600,7 +601,8 @@ - (NSString *)description | |
|
||
#if YOGA | ||
|
||
- (ASStackLayoutDirection)direction { return _direction.load(); } | ||
- (ASStackLayoutDirection)flexDirection { return _flexDirection.load(); } | ||
- (YGDirection)direction { return _direction.load(); } | ||
- (CGFloat)spacing { return _spacing.load(); } | ||
- (ASStackLayoutJustifyContent)justifyContent { return _justifyContent.load(); } | ||
- (ASStackLayoutAlignItems)alignItems { return _alignItems.load(); } | ||
|
@@ -612,7 +614,8 @@ - (ASEdgeInsets)border { return _border.load(); } | |
- (CGFloat)aspectRatio { return _aspectRatio.load(); } | ||
- (YGWrap)flexWrap { return _flexWrap.load(); } | ||
|
||
- (void)setDirection:(ASStackLayoutDirection)direction { _direction.store(direction); } | ||
- (void)setFlexDirection:(ASStackLayoutDirection)flexDirection { _flexDirection.store(flexDirection); } | ||
- (void)setDirection:(YGDirection)direction { _direction.store(direction); } | ||
- (void)setSpacing:(CGFloat)spacing { _spacing.store(spacing); } | ||
- (void)setJustifyContent:(ASStackLayoutJustifyContent)justify { _justifyContent.store(justify); } | ||
- (void)setAlignItems:(ASStackLayoutAlignItems)alignItems { _alignItems.store(alignItems); } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if these are implemented using C++ atomics, we ought to declare them as
atomic
.