Skip to content
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] Refine the handling of measurement functions when Yoga is used. #408

Merged
merged 1 commit into from
Jul 2, 2017

Conversation

appleguy
Copy link
Member

@appleguy appleguy commented Jul 2, 2017

This ensures that measure funcs are not set for container / empty spacer
nodes, because Yoga has more internal capabilities than layoutThatFits:
knows about.

Avoid need for the main layout pass to directly call setup for measure
funcs, by making it an implicit part of .yogaLayoutInProgress =.

Tear down the measure func after the layout pass to avoid retain cycle.

@appleguy appleguy added the Layout label Jul 2, 2017
@appleguy appleguy self-assigned this Jul 2, 2017
@appleguy appleguy requested review from maicki and nguyenhuy July 2, 2017 06:23
@@ -36,11 +36,15 @@ @interface ASDisplayNode (YogaInternal)
- (ASSizeRange)_locked_constrainedSizeForLayoutPass;
@end

@interface ASLayout (YogaInternal)
@property (nonatomic, getter=isFlattened) BOOL flattened;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenhuy could you explain why the diff to this file in this other PR is correct?
https://github.com/TextureGroup/Texture/pull/395/files#diff-599cfec3d0b870d11b2965c36e2b6a72

I haven't been able to study the change in detail, but I wanted to be certain that flattening will still be performed correctly for Yoga nodes with this removed.

@implementation ASDisplayNode (Yoga)

- (void)setYogaChildren:(NSArray *)yogaChildren
{
for (ASDisplayNode *child in _yogaChildren) {
for (ASDisplayNode *child in [_yogaChildren copy]) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important - if this method was called previously with a non-nil _yogaChildren (not too common), then it would always crash due to mutate-while-iterating.

BOOL definesCustomLayout = [self implementsLayoutMethod];

// We set the measure func only during layout. Otherwise, a cycle is created:
// The YGNodeRef Context will retain the ASDisplayNode, which retains the style, which owns the YGNodeRef.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully I had fixed this a while ago and it was introduced only shortly before that, but just now getting around to upstreaming this.

This ensures that measure funcs are not set for container / empty spacer
nodes, because Yoga has more internal capabilities than layoutThatFits:
knows about.

Avoid need for the main layout pass to directly call setup for measure
funcs, by making it an implicit part of .yogaLayoutInProgress =.

Tear down the measure func after the layout pass to avoid retain cycle.
@ghost
Copy link

ghost commented Jul 2, 2017

1 Warning
⚠️ Any source code changes should have an entry in CHANGELOG.md or have #trivial in their title.

Generated by 🚫 Danger

@appleguy
Copy link
Member Author

appleguy commented Jul 2, 2017

@nguyenhuy could you explain briefly why the Flattened management is no longer needed? E.g. was removed in: https://github.com/TextureGroup/Texture/pull/395/files#diff-599cfec3d0b870d11b2965c36e2b6a72

I haven't been able to study the change in detail, but I wanted to be certain that flattening will still be performed correctly for Yoga nodes with this removed.

Copy link
Contributor

@maicki maicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

@@ -143,7 +143,7 @@ - (NSString *)asciiArtName
{
NSString *string = NSStringFromClass([self class]);
if (_debugName) {
string = [string stringByAppendingString:[NSString stringWithFormat:@"\"%@\"", _debugName]];
string = [string stringByAppendingString:[NSString stringWithFormat:@"\"%@\"",_debugName]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol strange change. This will cause a spurious merge conflict with #399 (which improves the perf) so better to revert it.

@appleguy
Copy link
Member Author

appleguy commented Jul 2, 2017 via email

@Adlai-Holler
Copy link
Member

Eh don't worry about it let's fry other fish. Besides we'll all be dead and gone before the tracing diff gets reviewed #salty

@appleguy appleguy merged commit 1d1a378 into master Jul 2, 2017
@appleguy appleguy deleted the YogaMeasureFuncRefinement branch July 2, 2017 20:01
@appleguy
Copy link
Member Author

appleguy commented Jul 2, 2017

@Adlai-Holler :-D it turns out that I am running into a really shitty issue with layout right now (where image loading indeed causes massive layout churn by ascending to the root, which then also triggers main thread relayout when the collection requests a cell's size -- basically, horribly defeating the point of everything). I logged on to go check out the tracing diff to see if I can utilize it. Sorry it's taken a few days, I still have a lot of other reviews waiting on me both internal and external!

@Adlai-Holler
Copy link
Member

Lol no worries, just whining. Hope the tracing diff helps!

bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
TextureGroup#408)

This ensures that measure funcs are not set for container / empty spacer
nodes, because Yoga has more internal capabilities than layoutThatFits:
knows about.

Avoid need for the main layout pass to directly call setup for measure
funcs, by making it an implicit part of .yogaLayoutInProgress =.

Tear down the measure func after the layout pass to avoid retain cycle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants