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; let started = false;
// NOTE: for backwards compatibility. Remove for 4.0.0. // NOTE: for backwards compatibility. Remove for 4.0.0.
const createRootFrame = { value: true }; 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) { if (started) {
throw new Error("Application is already 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 { export function shouldCreateRootFrame(): boolean {
return createRootFrame.value; return createRootFrame.value;
} }
export function run(entry?: NavigationEntry | string) { export function run(entry?: NavigationEntry | string) {
createRootFrame.value = false; createRootFrame.value = false;
start(entry); _start(entry);
} }
const CALLBACKS = "_callbacks"; const CALLBACKS = "_callbacks";

View File

@ -275,16 +275,15 @@ function createRootView(v?: View) {
let rootView = v; let rootView = v;
if (!rootView) { if (!rootView) {
// try to navigate to the mainEntry (if specified) // 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) { if (createRootFrame.value) {
const frame = rootView = new Frame(); const frame = rootView = new Frame();
frame.navigate(mainEntry); frame.navigate(mainEntry);
} else { } else {
rootView = createViewFromEntry(mainEntry); 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. // NOTE: for backwards compatibility. Remove for 4.0.0.
const createRootFrame = { value: true }; const createRootFrame = { value: true };
let started: boolean = false; let started: boolean = false;
export function start(entry?: string | NavigationEntry) { function _start(entry?: string | NavigationEntry) {
console.log("application.start() is deprecated; use application.run() instead");
mainEntry = typeof entry === "string" ? { moduleName: entry } : entry; mainEntry = typeof entry === "string" ? { moduleName: entry } : entry;
started = true; 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) { export function run(entry?: string | NavigationEntry) {
createRootFrame.value = false; createRootFrame.value = false;
start(entry); _start(entry);
} }
export function _resetRootView(entry?: NavigationEntry | string) { export function _resetRootView(entry?: NavigationEntry | string) {

View File

@ -1174,39 +1174,47 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
const intent = activity.getIntent(); const intent = activity.getIntent();
if (fireLaunchEvent) { if (fireLaunchEvent) {
// entry point for Angular and Vue frameworks
rootView = notifyLaunch(intent, savedInstanceState); rootView = notifyLaunch(intent, savedInstanceState);
} }
if (shouldCreateRootFrame) { if (!rootView) {
const extras = intent.getExtras(); // entry point for NS Core
let frameId = -1; if (!mainEntry) {
// Also handles scenarios with Angular and Vue where the notifyLaunch didn't return a root view.
// We have extras when we call - new Frame().navigate(); throw new Error("Main entry is missing. App cannot be started. Verify app bootstrap.");
// savedInstanceState is used when activity is recreated.
// NOTE: On API 23+ we get extras on first run.
// Check changed - first try to get frameId from Extras if not from saveInstanceState.
if (extras) {
frameId = extras.getInt(INTENT_EXTRA, -1);
} }
if (savedInstanceState && frameId < 0) { if (shouldCreateRootFrame) {
frameId = savedInstanceState.getInt(INTENT_EXTRA, -1); const extras = intent.getExtras();
} let frameId = -1;
if (!rootView) { // We have extras when we call - new Frame().navigate();
// If we have frameId from extras - we are starting a new activity from navigation (e.g. new Frame().navigate())) // savedInstanceState is used when activity is recreated.
// Then we check if we have frameId from savedInstanceState - this happens when Activity is destroyed but app was not (e.g. suspend) // NOTE: On API 23+ we get extras on first run.
rootView = getFrameByNumberId(frameId) || new Frame(); // Check changed - first try to get frameId from Extras if not from saveInstanceState.
} if (extras) {
frameId = extras.getInt(INTENT_EXTRA, -1);
}
if (rootView instanceof Frame) { if (savedInstanceState && frameId < 0) {
rootView.navigate(mainEntry); frameId = savedInstanceState.getInt(INTENT_EXTRA, -1);
}
if (!rootView) {
// If we have frameId from extras - we are starting a new activity from navigation (e.g. new Frame().navigate()))
// Then we check if we have frameId from savedInstanceState - this happens when Activity is destroyed but app was not (e.g. suspend)
rootView = getFrameByNumberId(frameId) || new Frame();
}
if (rootView instanceof Frame) {
rootView.navigate(mainEntry);
} else {
throw new Error("A Frame must be used to navigate to a Page.");
}
} else { } else {
throw new Error("A Frame must be used to navigate to a Page."); rootView = createViewFromEntry(mainEntry);
} }
} else {
// Create the root view if the notifyLaunch didn't return it
rootView = rootView || createViewFromEntry(mainEntry);
} }
this._rootView = rootView; this._rootView = rootView;