Existing iOS integration app support added

This commit is contained in:
Vladimir Enchev
2016-10-11 10:10:35 +03:00
parent 4cf8a1574c
commit eab903e9e0
3 changed files with 55 additions and 24 deletions

View File

@ -559,6 +559,12 @@ declare module "application" {
*/
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).
*/

View File

@ -81,6 +81,10 @@ class IOSApplication implements definition.iOSApplication {
return utils.ios.getter(UIApplication, UIApplication.sharedApplication);
}
get window(): Window {
return this._window;
}
get delegate(): typeof UIApplicationDelegate {
return this._delegate;
}
@ -121,27 +125,7 @@ class IOSApplication implements definition.iOSApplication {
typedExports.notify(args);
let rootView = 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;
}
let rootView = createRootView(args.root);
this._window.content = rootView;
if (rootView instanceof Frame) {
@ -225,7 +209,6 @@ class IOSApplication implements definition.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;
typedExports.start = function (entry?: NavigationEntry) {
if (!started) {
@ -267,7 +275,20 @@ typedExports.start = function (entry?: NavigationEntry) {
}
started = true;
loadCss();
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 {
throw new Error("iOS Application already started!");
}

View File

@ -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 trace = require("trace");
import uiUtils = require("ui/utils");
@ -130,6 +131,9 @@ class UIViewControllerImpl extends UIViewController {
}
}
else {
if(!application.ios.window) {
uiUtils.ios._layoutRootView(owner, utils.ios.getter(UIScreen, UIScreen.mainScreen).bounds);
}
owner._updateLayout();
}
}