Tutorial: Platform.reparentView

Platform.reparentView

Reparents a specified view in a new target window.

Example

let windowIdentity;
if (fin.me.isWindow) {
    windowIdentity = fin.me.identity;
} else if (fin.me.isView) {
    windowIdentity = (await fin.me.getCurrentWindow()).identity;
} else {
    throw new Error('Not running in a platform View or Window');
}

let platform = fin.Platform.getCurrentSync();
let viewOptions = {
    name: 'example_view',
    url: 'https://example.com'
};
// a new view will now show in the current window
await platform.createView(viewOptions, windowIdentity);

//reparent view when the new view is shown
const view = fin.View.wrapSync({ uuid: windowIdentity.uuid, name: 'yahoo_view' });

view.on('shown', () => {
    let viewIdentity = { uuid: windowIdentity.uuid, name: 'example_view'};
    let target = {uuid: windowIdentity.uuid, name: 'test_win'};
    platform.reparentView(viewIdentity, target);
});

// create a new window
await platform.createWindow({
    name: "test_win",
    layout: {
        content: [
            {
                type: 'stack',
                content: [
                    {
                        type: 'component',
                        componentName: 'view',
                        componentState: {
                            name: 'yahoo_view',
                            url: 'https://yahoo.com'
                        }
                    }
                ]
            }
        ]
    }
}).then(console.log);