mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Existing iOS integration app support added
This commit is contained in:
@ -559,6 +559,12 @@ declare module "application" {
|
|||||||
*/
|
*/
|
||||||
rootController: any /* UIViewController */;
|
rootController: any /* UIViewController */;
|
||||||
|
|
||||||
|
/* tslint:enable */
|
||||||
|
/**
|
||||||
|
* The key window.
|
||||||
|
*/
|
||||||
|
window: any /* UIWindow */;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html).
|
* The [UIApplication](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/index.html).
|
||||||
*/
|
*/
|
||||||
|
@ -81,6 +81,10 @@ class IOSApplication implements definition.iOSApplication {
|
|||||||
return utils.ios.getter(UIApplication, UIApplication.sharedApplication);
|
return utils.ios.getter(UIApplication, UIApplication.sharedApplication);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get window(): Window {
|
||||||
|
return this._window;
|
||||||
|
}
|
||||||
|
|
||||||
get delegate(): typeof UIApplicationDelegate {
|
get delegate(): typeof UIApplicationDelegate {
|
||||||
return this._delegate;
|
return this._delegate;
|
||||||
}
|
}
|
||||||
@ -121,27 +125,7 @@ class IOSApplication implements definition.iOSApplication {
|
|||||||
|
|
||||||
typedExports.notify(args);
|
typedExports.notify(args);
|
||||||
|
|
||||||
let rootView = args.root;
|
let rootView = createRootView(args.root);
|
||||||
let frame: Frame;
|
|
||||||
let navParam: Object;
|
|
||||||
if (!rootView) {
|
|
||||||
// try to navigate to the mainEntry/Module (if specified)
|
|
||||||
navParam = typedExports.mainEntry;
|
|
||||||
if (!navParam) {
|
|
||||||
navParam = typedExports.mainModule;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (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 = rootView;
|
||||||
|
|
||||||
if (rootView instanceof Frame) {
|
if (rootView instanceof Frame) {
|
||||||
@ -225,7 +209,6 @@ class IOSApplication implements definition.iOSApplication {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var iosApp = new IOSApplication();
|
var iosApp = new IOSApplication();
|
||||||
@ -259,6 +242,31 @@ export function addCss(cssText: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createRootView(v?) {
|
||||||
|
let rootView = v;
|
||||||
|
let frame: Frame;
|
||||||
|
let navParam: Object;
|
||||||
|
if (!rootView) {
|
||||||
|
// try to navigate to the mainEntry/Module (if specified)
|
||||||
|
navParam = typedExports.mainEntry;
|
||||||
|
if (!navParam) {
|
||||||
|
navParam = typedExports.mainModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rootView;
|
||||||
|
}
|
||||||
|
|
||||||
var started: boolean = false;
|
var started: boolean = false;
|
||||||
typedExports.start = function (entry?: NavigationEntry) {
|
typedExports.start = function (entry?: NavigationEntry) {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
@ -267,7 +275,20 @@ typedExports.start = function (entry?: NavigationEntry) {
|
|||||||
}
|
}
|
||||||
started = true;
|
started = true;
|
||||||
loadCss();
|
loadCss();
|
||||||
UIApplicationMain(0, null, null, typedExports.ios && typedExports.ios.delegate ? NSStringFromClass(typedExports.ios.delegate) : NSStringFromClass(Responder));
|
|
||||||
|
if(!iosApp.nativeApp) {
|
||||||
|
// Normal NativeScript app will need UIApplicationMain.
|
||||||
|
UIApplicationMain(0, null, null, typedExports.ios && typedExports.ios.delegate ? NSStringFromClass(typedExports.ios.delegate) : NSStringFromClass(Responder));
|
||||||
|
} else {
|
||||||
|
let rootView = createRootView();
|
||||||
|
if(rootView) {
|
||||||
|
// Attach to the existing iOS app
|
||||||
|
let rootController = iosApp.nativeApp.keyWindow.rootViewController;
|
||||||
|
rootController.presentViewControllerAnimatedCompletion(rootView.ios.controller, utils.ios.MajorVersion >= 7, null);
|
||||||
|
uiUtils.ios._layoutRootView(rootView, utils.ios.getter(UIScreen, UIScreen.mainScreen).bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error("iOS Application already started!");
|
throw new Error("iOS Application already started!");
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import pageCommon = require("./page-common");
|
import application = require("application");
|
||||||
|
import pageCommon = require("./page-common");
|
||||||
import { View } from "ui/core/view";
|
import { View } from "ui/core/view";
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
import uiUtils = require("ui/utils");
|
import uiUtils = require("ui/utils");
|
||||||
@ -130,6 +131,9 @@ class UIViewControllerImpl extends UIViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if(!application.ios.window) {
|
||||||
|
uiUtils.ios._layoutRootView(owner, utils.ios.getter(UIScreen, UIScreen.mainScreen).bounds);
|
||||||
|
}
|
||||||
owner._updateLayout();
|
owner._updateLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user