Skip to content

View loaded event being called too soon? #250

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

Closed
vjoao opened this issue May 22, 2016 · 1 comment
Closed

View loaded event being called too soon? #250

vjoao opened this issue May 22, 2016 · 1 comment

Comments

@vjoao
Copy link

vjoao commented May 22, 2016

There is a plugin with this structure:

class Plugin extends AbsoluteLayout { }

and the constructView method does:

this.on(AbsoluteLayout.loadedEvent, (data: any) => {
    this.eachLayoutChild((view: View) => {

    .... some code with the children views   

    });

Because it's meant to be instantiated like that:

<PluginContainer>
    <SubView>
...
    </SubView>

    <SubView>
...
    </SubView>

    <SubView>
...
    </SubView>
</PluginContainer>

The problem is the eachLayoutChild is being called with no children whatsoever (looks like the onLoad event is being called before any child is constructed.

Is this the expected behavior? How to get the children list in this case?

@hdeshev
Copy link
Contributor

hdeshev commented May 25, 2016

Yes, at this moment the renderer creates parent views, attaches them to the visual tree (which fires their loaded events), and then proceeds with child views.

Since you are inheriting from a layout, perhaps it would be easiest if you override _registerLayoutChild and set up your children there:

https://github.com/NativeScript/NativeScript/blob/57d5bd143a0a60bc5867470966e66290bf7bb021/ui/layouts/layout-base.ts#L45-L51

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

No branches or pull requests

2 participants