Merge pull request #7075 from NativeScript/myankov/merge

chore: merge release to master
This commit is contained in:
Manol Donev
2019-03-26 19:50:12 +02:00
committed by GitHub
3 changed files with 51 additions and 37 deletions

View File

@ -131,9 +131,8 @@ let mainEntry: NavigationEntry;
let started = false;
// NOTE: for backwards compatibility. Remove for 4.0.0.
const createRootFrame = { value: true };
export function start(entry?: NavigationEntry | string) {
console.log("application.start() is deprecated; use application.run() instead");
function _start(entry?: NavigationEntry | string) {
if (started) {
throw new Error("Application is already started.");
}
@ -146,13 +145,18 @@ export function start(entry?: NavigationEntry | string) {
}
}
export function start(entry?: NavigationEntry | string) {
console.log("application.start() is deprecated; use application.run() instead");
_start(entry);
}
export function shouldCreateRootFrame(): boolean {
return createRootFrame.value;
}
export function run(entry?: NavigationEntry | string) {
createRootFrame.value = false;
start(entry);
_start(entry);
}
const CALLBACKS = "_callbacks";

View File

@ -275,16 +275,15 @@ function createRootView(v?: View) {
let rootView = v;
if (!rootView) {
// try to navigate to the mainEntry (if specified)
if (mainEntry) {
if (!mainEntry) {
throw new Error("Main entry is missing. App cannot be started. Verify app bootstrap.");
} else {
if (createRootFrame.value) {
const frame = rootView = new Frame();
frame.navigate(mainEntry);
} else {
rootView = createViewFromEntry(mainEntry);
}
} else {
// TODO: Throw an exception?
throw new Error("A Frame must be used to navigate to a Page.");
}
}
@ -302,9 +301,7 @@ export function getRootView() {
// NOTE: for backwards compatibility. Remove for 4.0.0.
const createRootFrame = { value: true };
let started: boolean = false;
export function start(entry?: string | NavigationEntry) {
console.log("application.start() is deprecated; use application.run() instead");
function _start(entry?: string | NavigationEntry) {
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
started = true;
@ -336,9 +333,14 @@ export function start(entry?: string | NavigationEntry) {
}
}
export function start(entry?: string | NavigationEntry) {
console.log("application.start() is deprecated; use application.run() instead");
_start(entry);
}
export function run(entry?: string | NavigationEntry) {
createRootFrame.value = false;
start(entry);
_start(entry);
}
export function _resetRootView(entry?: NavigationEntry | string) {

View File

@ -1174,9 +1174,17 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
const intent = activity.getIntent();
if (fireLaunchEvent) {
// entry point for Angular and Vue frameworks
rootView = notifyLaunch(intent, savedInstanceState);
}
if (!rootView) {
// entry point for NS Core
if (!mainEntry) {
// Also handles scenarios with Angular and Vue where the notifyLaunch didn't return a root view.
throw new Error("Main entry is missing. App cannot be started. Verify app bootstrap.");
}
if (shouldCreateRootFrame) {
const extras = intent.getExtras();
let frameId = -1;
@ -1205,8 +1213,8 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
throw new Error("A Frame must be used to navigate to a Page.");
}
} else {
// Create the root view if the notifyLaunch didn't return it
rootView = rootView || createViewFromEntry(mainEntry);
rootView = createViewFromEntry(mainEntry);
}
}
this._rootView = rootView;