mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Added an option to change the rootView.
Fixed crash where activity was incorrectly using existing initialized frame. Fixed TabView to use _nativeView instead of Frame.
This commit is contained in:
@@ -191,41 +191,7 @@ export class AndroidApplication extends observable.Observable implements definit
|
||||
private _eventsToken: any;
|
||||
|
||||
public getActivity(intent: android.content.Intent): Object {
|
||||
if (intent && intent.getAction() === android.content.Intent.ACTION_MAIN) {
|
||||
// application's main activity
|
||||
if (typedExports.onLaunch) {
|
||||
typedExports.onLaunch(intent);
|
||||
}
|
||||
|
||||
typedExports.notify({ eventName: typedExports.launchEvent, object: this, android: intent });
|
||||
|
||||
setupOrientationListener(this);
|
||||
|
||||
/* In the onLaunch event we expect the following setup, which ensures a root frame:
|
||||
* var frame = require("ui/frame");
|
||||
* var rootFrame = new frame.Frame();
|
||||
* rootFrame.navigate({ pageModuleName: "mainPage" });
|
||||
*/
|
||||
}
|
||||
|
||||
var topFrame = frame.topmost();
|
||||
if (!topFrame) {
|
||||
// try to navigate to the mainEntry/Module (if specified)
|
||||
var navParam = typedExports.mainEntry;
|
||||
if (!navParam) {
|
||||
navParam = typedExports.mainModule;
|
||||
}
|
||||
|
||||
if (navParam) {
|
||||
topFrame = new frame.Frame();
|
||||
topFrame.navigate(navParam);
|
||||
} else {
|
||||
// TODO: Throw an exception?
|
||||
throw new Error("A Frame must be used to navigate to a Page.");
|
||||
}
|
||||
}
|
||||
|
||||
return topFrame.android.onActivityRequested(intent);
|
||||
return frame.getActivity();
|
||||
}
|
||||
|
||||
public init(nativeApp: any) {
|
||||
@@ -320,7 +286,7 @@ function loadCss() {
|
||||
}
|
||||
|
||||
var started = false;
|
||||
export function start (entry?: frame.NavigationEntry) {
|
||||
export function start(entry?: frame.NavigationEntry) {
|
||||
if (started) {
|
||||
throw new Error("Application is already started.");
|
||||
}
|
||||
@@ -340,6 +306,7 @@ export function start (entry?: frame.NavigationEntry) {
|
||||
|
||||
onCreate: function () {
|
||||
androidApp.init(this);
|
||||
setupOrientationListener(androidApp);
|
||||
}
|
||||
});
|
||||
loadCss();
|
||||
@@ -352,8 +319,9 @@ typedExports.android = androidApp;
|
||||
var currentOrientation: number;
|
||||
function setupOrientationListener(androidApp: AndroidApplication) {
|
||||
androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_CONFIGURATION_CHANGED, onConfigurationChanged);
|
||||
currentOrientation = androidApp.context.getResources().getConfiguration().orientation
|
||||
currentOrientation = androidApp.context.getResources().getConfiguration().orientation;
|
||||
}
|
||||
|
||||
function onConfigurationChanged(context: android.content.Context, intent: android.content.Intent) {
|
||||
var orientation = context.getResources().getConfiguration().orientation;
|
||||
|
||||
|
||||
19
application/application.d.ts
vendored
19
application/application.d.ts
vendored
@@ -5,7 +5,7 @@ declare module "application" {
|
||||
import cssSelector = require("ui/styling/css-selector");
|
||||
import observable = require("data/observable");
|
||||
import frame = require("ui/frame");
|
||||
|
||||
import {View} from "ui/core/view";
|
||||
/**
|
||||
* An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code.
|
||||
*/
|
||||
@@ -76,6 +76,17 @@ declare module "application" {
|
||||
object: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event data containing information for launch event.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
root?: View;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event data containing information for orientation changed event.
|
||||
*/
|
||||
@@ -130,7 +141,7 @@ declare module "application" {
|
||||
/**
|
||||
* The main entry point event. This method is expected to use the root frame to navigate to the main application page.
|
||||
*/
|
||||
export function onLaunch(context: any): void;
|
||||
export function onLaunch(context?: any): void;
|
||||
|
||||
/**
|
||||
* A callback to be used when an uncaught error occurs while the application is running.
|
||||
@@ -174,7 +185,7 @@ declare module "application" {
|
||||
* @param callback - Callback function which will be removed.
|
||||
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
||||
*/
|
||||
export function off(eventNames: string, callback ?: any, thisArg ?: any);
|
||||
export function off(eventNames: string, callback?: any, thisArg?: any);
|
||||
|
||||
/**
|
||||
* Notifies all the registered listeners for the event provided in the data.eventName.
|
||||
@@ -191,7 +202,7 @@ declare module "application" {
|
||||
/**
|
||||
* This event is raised on application launchEvent.
|
||||
*/
|
||||
export function on(event: "launch", callback: (args: ApplicationEventData) => void, thisArg?: any);
|
||||
export function on(event: "launch", callback: (args: LaunchEventData) => void, thisArg?: any);
|
||||
|
||||
/**
|
||||
* This event is raised when the Application is suspended.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import common = require("./application-common");
|
||||
import frame = require("ui/frame");
|
||||
import {Frame, NavigationEntry, reloadPage} from "ui/frame";
|
||||
import definition = require("application");
|
||||
import * as uiUtils from "ui/utils";
|
||||
import * as typesModule from "utils/types";
|
||||
@@ -114,32 +114,51 @@ class IOSApplication implements definition.iOSApplication {
|
||||
typedExports.onLaunch(undefined);
|
||||
}
|
||||
|
||||
typedExports.notify({
|
||||
let args: definition.LaunchEventData = {
|
||||
eventName: typedExports.launchEvent,
|
||||
object: this,
|
||||
ios: notification.userInfo && notification.userInfo.objectForKey("UIApplicationLaunchOptionsLocalNotificationKey") || null
|
||||
});
|
||||
};
|
||||
|
||||
var topFrame = frame.topmost();
|
||||
if (!topFrame) {
|
||||
typedExports.notify(args);
|
||||
|
||||
let rootView = args.root;
|
||||
let frame: Frame;
|
||||
let navParam: Object;
|
||||
if (!rootView) {
|
||||
// try to navigate to the mainEntry/Module (if specified)
|
||||
var navParam = typedExports.mainEntry;
|
||||
navParam = typedExports.mainEntry;
|
||||
if (!navParam) {
|
||||
navParam = typedExports.mainModule;
|
||||
}
|
||||
|
||||
if (navParam) {
|
||||
topFrame = new frame.Frame();
|
||||
topFrame.navigate(navParam);
|
||||
frame = new Frame();
|
||||
frame.navigate(navParam);
|
||||
} else {
|
||||
// TODO: Throw an exception?
|
||||
throw new Error("A Frame must be used to navigate to a Page.");
|
||||
}
|
||||
|
||||
rootView = frame;
|
||||
}
|
||||
|
||||
this._window.content = rootView;
|
||||
|
||||
this._window.content = topFrame;
|
||||
|
||||
this.rootController = this._window.rootViewController = topFrame.ios.controller;
|
||||
if (rootView instanceof Frame) {
|
||||
this.rootController = this._window.rootViewController = rootView.ios.controller;
|
||||
}
|
||||
else if (rootView.ios instanceof UIViewController) {
|
||||
this.rootController = this._window.rootViewController = rootView.ios;
|
||||
}
|
||||
else if (rootView.ios instanceof UIView) {
|
||||
let newController = new UIViewController();
|
||||
newController.view.addSubview(rootView.ios);
|
||||
this.rootController = newController;
|
||||
}
|
||||
else {
|
||||
throw new Error("Root should be either UIViewController or UIView");
|
||||
}
|
||||
|
||||
this._window.makeKeyAndVisible();
|
||||
}
|
||||
@@ -229,7 +248,7 @@ function loadCss() {
|
||||
}
|
||||
|
||||
var started: boolean = false;
|
||||
typedExports.start = function (entry?: frame.NavigationEntry) {
|
||||
typedExports.start = function (entry?: NavigationEntry) {
|
||||
if (!started) {
|
||||
if (entry) {
|
||||
exports.mainEntry = entry;
|
||||
@@ -256,5 +275,5 @@ global.__onLiveSync = function () {
|
||||
loadCss();
|
||||
|
||||
// Reload current page.
|
||||
frame.reloadPage();
|
||||
reloadPage();
|
||||
}
|
||||
Reference in New Issue
Block a user