Skip to content

Commit

Permalink
[Yoga] Ensure that calculated layout is nil'd in invalidate*Layout (#87)
Browse files Browse the repository at this point in the history
This is a simple additional fix to the last YOGA patch.
  • Loading branch information
appleguy committed Apr 29, 2017
1 parent 4745089 commit 411817b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Source/ASDisplayNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ extern void ASDisplayNodePerformBlockOnEveryYogaChild(ASDisplayNode * _Nullable

@interface ASDisplayNode (Yoga)

@property (nonatomic, strong) NSArray *yogaChildren;
@property (nonatomic, strong) ASLayout *yogaCalculatedLayout;
@property (nonatomic, strong, nullable) NSArray *yogaChildren;
@property (nonatomic, strong, nullable) ASLayout *yogaCalculatedLayout;

- (void)addYogaChild:(ASDisplayNode *)child;
- (void)removeYogaChild:(ASDisplayNode *)child;
Expand Down
3 changes: 2 additions & 1 deletion Source/ASDisplayNode+Yoga.mm
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ - (void)invalidateCalculatedYogaLayout
if (YGNodeGetMeasureFunc(yogaNode)) {
YGNodeMarkDirty(yogaNode);
}
self.yogaCalculatedLayout = nil;
}

- (void)semanticContentAttributeDidChange:(UISemanticContentAttribute)attribute
Expand All @@ -350,7 +351,7 @@ - (void)semanticContentAttributeDidChange:(UISemanticContentAttribute)attribute
- (void)calculateLayoutFromYogaRoot:(ASSizeRange)rootConstrainedSize
{
if (self.yogaParent) {
if (ASHierarchyStateIncludesYogaLayoutMeasuring(self.hierarchyState) == NO) {
if (self.yogaCalculatedLayout == nil) {
[self _setNeedsLayoutFromAbove];
}
return;
Expand Down
18 changes: 10 additions & 8 deletions Source/ASDisplayNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1166,17 +1166,19 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize
ASDN::MutexLocker l(__instanceLock__);

#if YOGA /* YOGA */
if (ASHierarchyStateIncludesYogaLayoutEnabled(_hierarchyState) == YES &&
ASHierarchyStateIncludesYogaLayoutMeasuring(_hierarchyState) == NO) {
ASDN::MutexUnlocker ul(__instanceLock__);
[self calculateLayoutFromYogaRoot:constrainedSize];
}
if (ASHierarchyStateIncludesYogaLayoutEnabled(_hierarchyState) == YES) {
if (ASHierarchyStateIncludesYogaLayoutMeasuring(_hierarchyState) == NO && self.yogaCalculatedLayout == nil) {
ASDN::MutexUnlocker ul(__instanceLock__);
[self calculateLayoutFromYogaRoot:constrainedSize];
}

if (ASHierarchyStateIncludesYogaLayoutEnabled(_hierarchyState) == YES && self.yogaCalculatedLayout) {
return self.yogaCalculatedLayout;
// The call above may set yogaCalculatedLayout, even if it tested as nil to enter it.
if (self.yogaCalculatedLayout && self.yogaChildren.count > 0) {
return self.yogaCalculatedLayout;
}
}
#endif /* YOGA */

// Manual size calculation via calculateSizeThatFits:
if (((_methodOverrides & ASDisplayNodeMethodOverrideLayoutSpecThatFits) ||
(_layoutSpecBlock != NULL)) == NO) {
Expand Down

0 comments on commit 411817b

Please sign in to comment.