shirakaba / react-nativescript

React renderer for NativeScript
https://react-nativescript.netlify.com
MIT License
280 stars 14 forks source link

Get ReactNativeScript.render() working #1

Closed shirakaba closed 5 years ago

shirakaba commented 5 years ago

ReactNativeScript.render() needs a root node (AKA container) to render into. Thus, I need to get a reference to the application's root view at startup time (which I'll use as the React root). However, I'm facing difficulties:

/* app.ts */
import { on, run, launchEvent, getRootView } from "tns-core-modules/application";

console.log(getRootView());
// application root view is undefined

on(launchEvent, (data) => {
    console.log(data.root);
    // application launch event's data.root is undefined
});
run();

Clearly I am misunderstanding the application lifecycle here. Wondering how I get a reference to the root view (frame) of the app at startup.

References:

shirakaba commented 5 years ago

Solved by: https://stackoverflow.com/questions/55340806/bootstrapping-a-react-renderer-how-do-i-get-a-reference-to-the-root-view-at-app/55341405