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 Beta] Improvements to the experimental support for Yoga layout. #59

Merged
merged 10 commits into from
Apr 27, 2017

Conversation

appleguy
Copy link
Member

@appleguy appleguy commented Apr 23, 2017

Yoga remains an unsupported / speculative feature, but these improvements are important for
the functionality of clients that are experimenting with it.

Total list of changes:

  1. Add "YGDirection" field to control vertical and horizontal.
  2. Add .start, .end, etc to gated EdgeInsets struct to support RTL layout properly. I can rename this struct to be Yoga-specific if desired, but it does need to exist on ASLayoutElementStyle objects.
  3. Fix some of the logic in the Yoga-private layout extensions. ASDisplayNode+Yoga is compiled out of most builds, so it is not possible for these changes to affect mainline users.

For example, without these changes, ASButtonNode is not able to lay out correctly. These
changes allow certain subtrees that use layout specs to coexist properly in a Yoga heirarchy.

The most significant change here is moving ASEdgeInsets into the #if YOGA gating. Although
this is technically an API change, this type was added with no known use cases and is
really only useful for flexbox layout specification. So, before usages of it are created,
it makes sense to constrain the Texture API surface until that time.

Yoga remains an unsupported / speculative feature, but these improvements are important for
the functionality of clients that are experimenting with it.

For example, without these changes, ASButtonNode is not able to lay out correctly. These
changes allow certain subtrees that use layout specs to coexist properly in a Yoga heirarchy.

The most significant change here is moving ASEdgeInsets into the #if YOGA gating. Although
this is technically an API change, this type was added with no known use cases and is
really only useful for flexbox layout specification. So, before usages of it are created,
it makes sense to constrain the Texture API surface until that time.
@CLAassistant
Copy link

CLAassistant commented Apr 23, 2017

CLA assistant check
All committers have signed the CLA.

…ent RTL support.

Although apps could handle this before by setting the view's property in didLoad, it's
useful to bridge this property for setting during off-main initialization.

This change also makes RTL fully functional / automatic for Yoga layout users.
@appleguy appleguy force-pushed the YogaUpdates branch 2 times, most recently from e50b2e3 to 5cdf50d Compare April 23, 2017 21:20
@appleguy
Copy link
Member Author

This has now merged latest master and should be ready to land, including RTL support as provided by PR #60.

@ghost
Copy link

ghost commented Apr 26, 2017

🚫 CI failed with log

Copy link
Member

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

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

Very good stuff here! A lot more refined and complete implementation than before, and I agree with the decision to limit the surface area and gate ASEdgeInsets on yoga until it's needed elsewhere.

Comments are non-blocking.

@@ -150,7 +150,8 @@ @implementation ASLayoutElementStyle {
std::atomic<CGPoint> _layoutPosition;

#if YOGA
std::atomic<ASStackLayoutDirection> _direction;
std::atomic<ASStackLayoutDirection> _flexDirection;
std::atomic<YGDirection> _direction;
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

[UIView userInterfaceLayoutDirectionForSemanticContentAttribute:attribute];
self.style.direction = (layoutDirection == UIUserInterfaceLayoutDirectionLeftToRight
? YGDirectionLTR : YGDirectionRTL);
}
Copy link
Member

Choose a reason for hiding this comment

The 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.


@end

@interface ASLayoutElementStyle (Yoga)

@property (nonatomic, assign, readwrite) ASStackLayoutDirection direction;
@property (nonatomic, assign, readwrite) ASStackLayoutDirection flexDirection;
@property (nonatomic, assign, readwrite) YGDirection direction;
Copy link
Member

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.

@maicki
Copy link
Contributor

maicki commented Apr 27, 2017

As I'm currently working in this area and this PR can introduce some merge conflicts, I rather would prevent this and I will try to get this PR further and hopefully in sooner than later cc @appleguy @Adlai-Holler

@ghost
Copy link

ghost commented Apr 27, 2017

🚫 CI failed with log

@ghost
Copy link

ghost commented Apr 27, 2017

🚫 CI failed with log

@ghost
Copy link

ghost commented Apr 27, 2017

🚫 CI failed with log

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.

Let's get that in now.

@maicki maicki merged commit 6f82d0f into master Apr 27, 2017
@appleguy
Copy link
Member Author

@maicki @Adlai-Holler thanks for your comments here and for merging this - sorry for the slow response on my side. I could put up another change that includes atomic, too, but won't worry about it until the other changes @maicki mentioned are landed.

One more thing - @maicki it's totally OK if your refactor removes the Yoga hook from ASDisplayNode entirely. Just drop me a message if you do this and I will work on re-adding it in the least invasive way possible. I actually had some recent ideas about how to possibly use the ASLayoutSpec API to build the Yoga tree; it would be a bit unusual because it would have to connect with the Yoga tree across levels of the hierarchy, BUT the integration points would basically not touch ASDisplayNode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants