mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(core): allow app to start without a root view (#9056)
This commit is contained in:
@@ -20,7 +20,7 @@ export interface ApplicationEventData extends EventData {
|
||||
}
|
||||
|
||||
export interface LaunchEventData extends ApplicationEventData {
|
||||
root?: View;
|
||||
root?: View | null;
|
||||
savedInstanceState?: any /* android.os.Bundle */;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ export function addCss(cssText: string, attributeScoped?: boolean): void {
|
||||
const CALLBACKS = '_callbacks';
|
||||
|
||||
export function _resetRootView(entry?: NavigationEntry | string): void {
|
||||
const activity = androidApp.foregroundActivity;
|
||||
const activity = androidApp.foregroundActivity || androidApp.startActivity;
|
||||
if (!activity) {
|
||||
throw new Error('Cannot find android activity.');
|
||||
}
|
||||
|
||||
3
packages/core/application/index.d.ts
vendored
3
packages/core/application/index.d.ts
vendored
@@ -103,8 +103,9 @@ export interface LaunchEventData extends ApplicationEventData {
|
||||
/**
|
||||
* The root view for this Window on iOS or Activity for Android.
|
||||
* If not set a new Frame will be created as a root view in order to maintain backwards compatibility.
|
||||
* If explicitly set to null, there will be no root view.
|
||||
*/
|
||||
root?: View;
|
||||
root?: View | null;
|
||||
|
||||
savedInstanceState?: any /* android.os.Bundle */;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,9 @@ export class iOSApplication implements iOSApplicationDefinition {
|
||||
|
||||
// this._window will be undefined when NS app is embedded in a native one
|
||||
if (this._window) {
|
||||
this.setWindowContent(args.root);
|
||||
if (args.root !== null) {
|
||||
this.setWindowContent(args.root);
|
||||
}
|
||||
} else {
|
||||
this._window = UIApplication.sharedApplication.delegate.window;
|
||||
}
|
||||
|
||||
@@ -1301,13 +1301,19 @@ class ActivityCallbacksImplementation implements AndroidActivityCallbacks {
|
||||
if (!rootView) {
|
||||
const mainEntry = application.getMainEntry();
|
||||
const intent = activity.getIntent();
|
||||
// useful for integrations that would like to set rootView asynchronously after app launch
|
||||
let shouldRootViewBeEmpty = false;
|
||||
|
||||
if (fireLaunchEvent) {
|
||||
// entry point for Angular and Vue frameworks
|
||||
rootView = notifyLaunch(intent, <any>savedInstanceState, null);
|
||||
shouldRootViewBeEmpty = rootView === null;
|
||||
}
|
||||
|
||||
if (!rootView) {
|
||||
if (shouldRootViewBeEmpty) {
|
||||
return;
|
||||
}
|
||||
// entry point for NS Core
|
||||
if (!mainEntry) {
|
||||
// Also handles scenarios with Angular and Vue where the notifyLaunch didn't return a root view.
|
||||
|
||||
Reference in New Issue
Block a user