Files
NativeScript/ui/page/page.ios.ts
2015-03-03 10:34:40 +02:00

78 lines
2.5 KiB
TypeScript

import pageCommon = require("ui/page/page-common");
import definition = require("ui/page");
import viewModule = require("ui/core/view");
import trace = require("trace");
module.exports.knownEvents = pageCommon.knownEvents;
class UIViewControllerImpl extends UIViewController {
static new(): UIViewControllerImpl {
return <UIViewControllerImpl>super.new();
}
private _owner: Page;
public initWithOwner(owner: Page): UIViewControllerImpl {
this._owner = owner;
this.automaticallyAdjustsScrollViewInsets = false;
return this;
}
public viewDidLoad() {
this.view.autoresizesSubviews = false;
this.view.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;
}
public viewDidLayoutSubviews() {
trace.write(this._owner + " viewDidLayoutSubviews, isLoaded = " + this._owner.isLoaded, trace.categories.ViewHierarchy);
this._owner._updateLayout();
}
}
/* tslint:enable */
export class Page extends pageCommon.Page {
private _ios: UIViewController;
constructor(options?: definition.Options) {
super(options);
this._ios = UIViewControllerImpl.new().initWithOwner(this);
}
public _onContentChanged(oldView: viewModule.View, newView: viewModule.View) {
super._onContentChanged(oldView, newView);
this._removeNativeView(oldView);
this._addNativeView(newView);
}
private _addNativeView(view: viewModule.View) {
if (view) {
trace.write("Native: Adding " + view + " to " + this, trace.categories.ViewHierarchy);
if (view.ios instanceof UIView) {
this._ios.view.addSubview(view.ios);
} else if (view.ios instanceof UIViewController) {
this._ios.addChildViewController(view.ios);
this._ios.view.addSubview(view.ios.view);
}
}
}
private _removeNativeView(view: viewModule.View) {
if (view) {
trace.write("Native: Removing " + view + " from " + this, trace.categories.ViewHierarchy);
if (view.ios instanceof UIView) {
(<UIView>view.ios).removeFromSuperview();
} else if (view.ios instanceof UIViewController) {
(<UIViewController>view.ios).removeFromParentViewController();
(<UIViewController>view.ios).view.removeFromSuperview();
}
}
}
get ios(): UIViewController {
return this._ios;
}
get _nativeView(): any {
return this.ios.view;
}
}