Asyncdisplaykit: [ASViewController] Add a way to participate with ASLayoutSpec, analogous to -viewWillLayoutSubviews.

Created on 22 Dec 2015  Â·  13Comments  Â·  Source: facebookarchive/AsyncDisplayKit

Hi,

I am very impressed how easy I build layout with ASLayout. And I want use it not only in cells, but in ViewController.

I found ASViewController, but as I understand, I need to create ASDisplayNode separately and init ASViewController with it.

I wonder, if you have any plans to tune ASViewController API to be able to specify layout in it. For instance:

class LoginViewController: ASViewController {
    private let _loginNode = ...
    private let _passwordNode = ...
    private let _loginButtonNode = ...

    override func viewDidLoad() {
        super.viewDidLoad()
        node.addSubnode(_loginNode)
        node.addSubdode(_passwordNode)
        node.addSubnode(_loginButtonNode)
    }

    // I think this method is missing...
    override func layoutSpecThatFits(constrainedSize: ASSizeRange) -> ASLayoutSpec! {
        return ...
    }
}
API improvement Enhancement

Most helpful comment

All 13 comments

@yury Where did you find the documentation for LayoutSpec? I don't understand it.

@yury Thanks, how did you find that link?!?!

I'm also really confused about what constrained size actually is. I'm also really unclear about which of -layout, -layoutSpecThatFits:. How is this related to -calculateSizeThatFits:?

@nguyenhuy any ideas

I'd love to see something like this too, @yury. @appleguy, I know you've mentioned this in the past. Let's start the discussion on making this API a reality.

@fatuhoku @yury This presentation of mine is not very good, but it does include essential information about the layout patterns. @fatuhoku I think it would be particularly useful to you as it does compare those patterns (skip to 11 minutes). This video is also linked at the very bottom (tiny font) on asyncdisplaykit.org:

https://www.youtube.com/watch?v=RY_X7l1g79Q

@yury there is not currently a layoutSpec method on ASViewController - this will be added soon, but in the meantime you must subclass the node that you provide to ASVC. This is the same as how UIViewController started out, where for 4 or 5 years the iOS API did not provide -viewDidLayoutSubviews and it wasn't possible to implement layout in a view controller without doing it in an usual place like -viewWillAppear:.

@appleguy thank you!

@yury @fatuhoku: check out the (work-in-progress) website documentation on ASLayout - http://asyncdisplaykit.org/docs/automatic-layout-basics.html

@yury @fatuhoku - You can now do self.node.layoutSpecBlock which is handy for various use cases. We are actively working on designing an API that is more directly integrated with ASViewController so that it is discoverable and allows extended layout on top of existing layoutSpecThatFits: implementations that the node may also specify.

For example, a node subclass may have a layoutSpecThatFits:, the node may have a layoutSpecBlock and the viewConteroller has a layoutSpecThatFits:, we have well defined ways to apply these layouts, but the work to be able to run multiple layout specs for a single is ongoing.

@appleguy thanks

We now have .layoutSpecBlock(), a block you can provide on any ASDisplayNode that can take the place of -layoutSpecThatFits.

This work perfectly for ASViewController if you want to do something like initWithNode:[[ASDisplayNode alloc] init]. You can add subnodes (or better yet, do self.node.usesImplicitHierarchyManagement = YES), then provide the layout spec block (typically best to define this in -init).

The only trick is that this cannot be used with any class that defines -layoutSpecThatFits as a method. This does limit the usefulness quite a bit, so we have an important task on the team roadmap already to address this by allowing any two layout spec definitions to both apply themselves.

On May 6, 2016, at 7:24 AM, Yury Korolev [email protected] wrote:

@appleguy https://github.com/appleguy thanks

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub https://github.com/facebook/AsyncDisplayKit/issues/969#issuecomment-217453677

@maicki: should this go into 2.1 or 2.2 or 3.0?

This issue was moved to TextureGroup/Texture#118

Was this page helpful?
0 / 5 - 0 ratings