NathanaelA / nativescript-dom

NativeScript DOM emulation methods
MIT License
42 stars 23 forks source link

Used in TS class constructor doesn't work #4

Open bradmartin opened 7 years ago

bradmartin commented 7 years ago
constructor(page: Page) {
        super();

        // Get any view components we need from the interface
/// ALL OF THIS WORK off the PAGE
        this.emailContainer = <GridLayout>page.getViewById('emailContainer');
        this.passwordContainer = <GridLayout>page.getViewById('passwordContainer');
        this.emailTextField = <TextField>page.getViewById('emailTextField');
        this.passwordTextField = <TextField>page.getViewById('passwordTextField');

        console.log(getElementById);

        let y = getElementById('passwordTextField'); // UNDEFINED
        console.log('y: ' + y); 

        setTimeout(function () {
            let x = getElementById('passwordTextField'); /// THIS WORKS
            console.log('x: ' + x);
        }, 0);

}
JS: function (id) {
JS:         return getElementById(getCurrentActiveModel(), id);
JS:     }
JS: y: undefined
JS: x: TextField<passwordTextField>@file:///app/views/login/login.xml:17:25;

So the timeout works with the function, although you can see it is available according to the first log of the function from the plugin.

NathanaelA commented 7 years ago

Yeah, I'm well aware of this issue; it is because the NS core framework does NOT setup the currentPage until way WAY late in the cycle; this causes the currentPage to either be null or point to the prior page.

Fix will be available after: https://github.com/NativeScript/NativeScript/issues/2966