mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Intermediate commit, using the NavBar items push/pop/set.
This commit is contained in:
@ -3,6 +3,7 @@ import definition = require("application");
|
|||||||
import fs = require("file-system");
|
import fs = require("file-system");
|
||||||
import styleScope = require("ui/styling/style-scope");
|
import styleScope = require("ui/styling/style-scope");
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
|
import frame = require("ui/frame");
|
||||||
|
|
||||||
var events = new observable.Observable();
|
var events = new observable.Observable();
|
||||||
global.moduleMerge(events, exports);
|
global.moduleMerge(events, exports);
|
||||||
@ -15,6 +16,9 @@ export var lowMemoryEvent = "lowMemory";
|
|||||||
export var uncaughtErrorEvent = "uncaughtError";
|
export var uncaughtErrorEvent = "uncaughtError";
|
||||||
export var orientationChangedEvent = "orientationChanged";
|
export var orientationChangedEvent = "orientationChanged";
|
||||||
|
|
||||||
|
export var mainModule: string;
|
||||||
|
export var mainEntry: frame.NavigationEntry;
|
||||||
|
|
||||||
export var cssFile: string = "app.css"
|
export var cssFile: string = "app.css"
|
||||||
|
|
||||||
export var resources: any = {};
|
export var resources: any = {};
|
||||||
|
@ -7,8 +7,6 @@ import enums = require("ui/enums");
|
|||||||
|
|
||||||
global.moduleMerge(appModule, exports);
|
global.moduleMerge(appModule, exports);
|
||||||
|
|
||||||
export var mainModule: string;
|
|
||||||
|
|
||||||
// We are using the exports object for the common events since we merge the appModule with this module's exports, which is what users will receive when require("application") is called;
|
// We are using the exports object for the common events since we merge the appModule with this module's exports, which is what users will receive when require("application") is called;
|
||||||
// TODO: This is kind of hacky and is "pure JS in TypeScript"
|
// TODO: This is kind of hacky and is "pure JS in TypeScript"
|
||||||
|
|
||||||
@ -218,10 +216,15 @@ export class AndroidApplication extends observable.Observable implements dts.And
|
|||||||
|
|
||||||
var topFrame = frame.topmost();
|
var topFrame = frame.topmost();
|
||||||
if (!topFrame) {
|
if (!topFrame) {
|
||||||
// try to navigate to the mainModule (if specified)
|
// try to navigate to the mainEntry/Module (if specified)
|
||||||
if (mainModule) {
|
var navParam = dts.mainEntry;
|
||||||
|
if (!navParam) {
|
||||||
|
navParam = dts.mainModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navParam) {
|
||||||
topFrame = new frame.Frame();
|
topFrame = new frame.Frame();
|
||||||
topFrame.navigate(mainModule);
|
topFrame.navigate(navParam);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Throw an exception?
|
// TODO: Throw an exception?
|
||||||
throw new Error("A Frame must be used to navigate to a Page.");
|
throw new Error("A Frame must be used to navigate to a Page.");
|
||||||
|
6
application/application.d.ts
vendored
6
application/application.d.ts
vendored
@ -4,6 +4,7 @@
|
|||||||
declare module "application" {
|
declare module "application" {
|
||||||
import cssSelector = require("ui/styling/css-selector");
|
import cssSelector = require("ui/styling/css-selector");
|
||||||
import observable = require("data/observable");
|
import observable = require("data/observable");
|
||||||
|
import frame = require("ui/frame");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code.
|
* An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code.
|
||||||
@ -94,6 +95,11 @@ declare module "application" {
|
|||||||
*/
|
*/
|
||||||
export var mainModule: string;
|
export var mainModule: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main navigation entry to be used when loading the main Page.
|
||||||
|
*/
|
||||||
|
export var mainEntry: frame.NavigationEntry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An application level static resources.
|
* An application level static resources.
|
||||||
*/
|
*/
|
||||||
|
@ -5,9 +5,8 @@ import types = require("utils/types");
|
|||||||
import view = require("ui/core/view");
|
import view = require("ui/core/view");
|
||||||
import definition = require("application");
|
import definition = require("application");
|
||||||
import enums = require("ui/enums");
|
import enums = require("ui/enums");
|
||||||
global.moduleMerge(appModule, exports);
|
|
||||||
|
|
||||||
export var mainModule: string;
|
global.moduleMerge(appModule, exports);
|
||||||
|
|
||||||
class Responder extends UIResponder {
|
class Responder extends UIResponder {
|
||||||
//
|
//
|
||||||
@ -120,13 +119,18 @@ class IOSApplication implements definition.iOSApplication {
|
|||||||
|
|
||||||
var topFrame = frame.topmost();
|
var topFrame = frame.topmost();
|
||||||
if (!topFrame) {
|
if (!topFrame) {
|
||||||
if (mainModule) {
|
// try to navigate to the mainEntry/Module (if specified)
|
||||||
|
var navParam = definition.mainEntry;
|
||||||
|
if (!navParam) {
|
||||||
|
navParam = definition.mainModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (navParam) {
|
||||||
topFrame = new frame.Frame();
|
topFrame = new frame.Frame();
|
||||||
topFrame.navigate(mainModule);
|
topFrame.navigate(navParam);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Throw an exception?
|
// TODO: Throw an exception?
|
||||||
// throw new Error("A Frame must be used to navigate to a Page.");
|
throw new Error("A Frame must be used to navigate to a Page.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import contentView = require("ui/content-view");
|
|||||||
import viewModule = require("ui/core/view");
|
import viewModule = require("ui/core/view");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
|
|
||||||
@Deprecated
|
//@Deprecated
|
||||||
export class Border extends contentView.ContentView implements definition.Border {
|
export class Border extends contentView.ContentView implements definition.Border {
|
||||||
get cornerRadius(): number {
|
get cornerRadius(): number {
|
||||||
return this.borderRadius;
|
return this.borderRadius;
|
||||||
|
@ -196,6 +196,21 @@ export class Frame extends view.CustomLayoutView implements definition.Frame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _isEntryBackstackVisible(entry: definition.BackstackEntry): boolean {
|
||||||
|
if (!entry) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var backstackVisibleValue = entry.entry.backstackVisible;
|
||||||
|
var backstackHidden = types.isDefined(backstackVisibleValue) && !backstackVisibleValue;
|
||||||
|
|
||||||
|
return !backstackHidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
public _updateActionBar(page?: pages.Page) {
|
||||||
|
trace.write("calling _updateActionBar on Frame", trace.categories.Navigation);
|
||||||
|
}
|
||||||
|
|
||||||
private _processNavigationContext(navigationContext: NavigationContext) {
|
private _processNavigationContext(navigationContext: NavigationContext) {
|
||||||
if (navigationContext.isBackNavigation) {
|
if (navigationContext.isBackNavigation) {
|
||||||
this.performGoBack(navigationContext);
|
this.performGoBack(navigationContext);
|
||||||
@ -209,7 +224,7 @@ export class Frame extends view.CustomLayoutView implements definition.Frame {
|
|||||||
var navContext = navigationContext.entry;
|
var navContext = navigationContext.entry;
|
||||||
this._onNavigatingTo(navContext);
|
this._onNavigatingTo(navContext);
|
||||||
|
|
||||||
if (this.currentPage) {
|
if (this._isEntryBackstackVisible(this._currentEntry)) {
|
||||||
this._backStack.push(this._currentEntry);
|
this._backStack.push(this._currentEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ var OWNER = "_owner";
|
|||||||
var HIDDEN = "_hidden";
|
var HIDDEN = "_hidden";
|
||||||
var INTENT_EXTRA = "com.tns.activity";
|
var INTENT_EXTRA = "com.tns.activity";
|
||||||
var ANDROID_FRAME = "android_frame";
|
var ANDROID_FRAME = "android_frame";
|
||||||
|
var BACKSTAK_TAG = "_backstackTag";
|
||||||
|
var NAV_DEPTH = "_navDepth";
|
||||||
|
|
||||||
var navDepth = 0;
|
var navDepth = 0;
|
||||||
|
|
||||||
@ -227,8 +229,10 @@ export class Frame extends frameCommon.Frame {
|
|||||||
var manager = activity.getFragmentManager();
|
var manager = activity.getFragmentManager();
|
||||||
var fragmentTransaction = manager.beginTransaction();
|
var fragmentTransaction = manager.beginTransaction();
|
||||||
|
|
||||||
var newFragmentTag = "fragment" + this.backStack.length;
|
var newFragmentTag = "fragment" + navDepth;
|
||||||
var newFragment = new PageFragmentBody(this, backstackEntry);
|
var newFragment = new PageFragmentBody(this, backstackEntry);
|
||||||
|
backstackEntry[BACKSTAK_TAG] = newFragmentTag;
|
||||||
|
backstackEntry[NAV_DEPTH] = navDepth;
|
||||||
|
|
||||||
// remember the fragment tag at page level so that we can retrieve the fragment associated with a Page instance
|
// remember the fragment tag at page level so that we can retrieve the fragment associated with a Page instance
|
||||||
backstackEntry.resolvedPage[TAG] = newFragmentTag;
|
backstackEntry.resolvedPage[TAG] = newFragmentTag;
|
||||||
@ -285,13 +289,15 @@ export class Frame extends frameCommon.Frame {
|
|||||||
trace.write("fragmentTransaction.commit();", trace.categories.NativeLifecycle);
|
trace.write("fragmentTransaction.commit();", trace.categories.NativeLifecycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _goBackCore(entry: definition.NavigationEntry) {
|
public _goBackCore(backstackEntry: definition.BackstackEntry) {
|
||||||
navDepth--;
|
navDepth = backstackEntry[NAV_DEPTH];
|
||||||
trace.write("Frame<" + this._domId + ">.fragmentTransaction POP depth = " + navDepth, trace.categories.Navigation);
|
trace.write("Frame<" + this._domId + ">.fragmentTransaction POP depth = " + navDepth, trace.categories.Navigation);
|
||||||
|
|
||||||
var manager = this._android.activity.getFragmentManager();
|
var manager = this._android.activity.getFragmentManager();
|
||||||
if (manager.getBackStackEntryCount() > 0) {
|
if (manager.getBackStackEntryCount() > 0) {
|
||||||
manager.popBackStack();
|
// pop all other fragments up until the named one
|
||||||
|
// this handles cases where user may navigate to an inner page without adding it on the backstack
|
||||||
|
manager.popBackStack(<string>backstackEntry[BACKSTAK_TAG], android.app.FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
ui/frame/frame.d.ts
vendored
7
ui/frame/frame.d.ts
vendored
@ -89,6 +89,7 @@ declare module "ui/frame" {
|
|||||||
|
|
||||||
//@private
|
//@private
|
||||||
_processNavigationQueue(page: pages.Page);
|
_processNavigationQueue(page: pages.Page);
|
||||||
|
_updateActionBar(page?: pages.Page);
|
||||||
//@endprivate
|
//@endprivate
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,6 +145,12 @@ declare module "ui/frame" {
|
|||||||
* True to navigate to the new Page using animated transitions, false otherwise.
|
* True to navigate to the new Page using animated transitions, false otherwise.
|
||||||
*/
|
*/
|
||||||
animated?: boolean;
|
animated?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True to record the navigation in the backstack, false otherwise.
|
||||||
|
* If the parameter is set to false then the Page will be displayed but once navigated from it will not be able to be navigated back to.
|
||||||
|
*/
|
||||||
|
backstackVisible?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,14 +10,16 @@ import types = require("utils/types");
|
|||||||
global.moduleMerge(frameCommon, exports);
|
global.moduleMerge(frameCommon, exports);
|
||||||
|
|
||||||
var ENTRY = "_entry";
|
var ENTRY = "_entry";
|
||||||
|
var PREV_ENTRY = "_prevEntry";
|
||||||
|
var NAV_DEPTH = "_navDepth";
|
||||||
|
|
||||||
var navDepth = 0;
|
var navDepth = -1;
|
||||||
|
|
||||||
export class Frame extends frameCommon.Frame {
|
export class Frame extends frameCommon.Frame {
|
||||||
private _ios: iOSFrame;
|
private _ios: iOSFrame;
|
||||||
private _paramToNavigate: any;
|
private _paramToNavigate: any;
|
||||||
public _shouldSkipNativePop: boolean = false;
|
|
||||||
public _navigateToEntry: definition.BackstackEntry;
|
public _navigateToEntry: definition.BackstackEntry;
|
||||||
|
public _goBackScheduled: boolean;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -48,31 +50,54 @@ export class Frame extends frameCommon.Frame {
|
|||||||
throw new Error("Required page does have an viewController created.");
|
throw new Error("Required page does have an viewController created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
navDepth++;
|
||||||
|
|
||||||
var animated = false;
|
var animated = false;
|
||||||
if (this.currentPage) {
|
if (this.currentPage) {
|
||||||
animated = this._getIsAnimatedNavigation(backstackEntry.entry);
|
animated = this._getIsAnimatedNavigation(backstackEntry.entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateNavigationBar();
|
backstackEntry[NAV_DEPTH] = navDepth;
|
||||||
|
|
||||||
viewController[ENTRY] = backstackEntry;
|
viewController[ENTRY] = backstackEntry;
|
||||||
|
this._navigateToEntry = backstackEntry;
|
||||||
navDepth++;
|
|
||||||
trace.write("Frame<" + this._domId + ">.pushViewControllerAnimated depth = " + navDepth, trace.categories.Navigation);
|
trace.write("Frame<" + this._domId + ">.pushViewControllerAnimated depth = " + navDepth, trace.categories.Navigation);
|
||||||
|
|
||||||
|
this._updateActionBar(backstackEntry.resolvedPage);
|
||||||
this._ios.controller.pushViewControllerAnimated(viewController, animated);
|
this._ios.controller.pushViewControllerAnimated(viewController, animated);
|
||||||
}
|
}
|
||||||
|
|
||||||
public _goBackCore(entry: definition.NavigationEntry) {
|
public _goBackCore(backstackEntry: definition.BackstackEntry) {
|
||||||
navDepth--;
|
navDepth = backstackEntry[NAV_DEPTH];
|
||||||
trace.write("Frame<" + this._domId + ">.popViewControllerAnimated depth = " + navDepth, trace.categories.Navigation);
|
trace.write("Frame<" + this._domId + ">.popViewControllerAnimated depth = " + navDepth, trace.categories.Navigation);
|
||||||
if (!this._shouldSkipNativePop) {
|
|
||||||
this._ios.controller.popViewControllerAnimated(this._getIsAnimatedNavigation(entry));
|
var controller = backstackEntry.resolvedPage.ios;
|
||||||
|
var animated = this._getIsAnimatedNavigation(backstackEntry.entry);
|
||||||
|
this._navigateToEntry = backstackEntry;
|
||||||
|
//this._updateActionBar(backstackEntry.resolvedPage);
|
||||||
|
this._ios.controller.popToViewControllerAnimated(controller, animated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public _updateActionBar(page?: pages.Page): void {
|
||||||
|
super._updateActionBar(page);
|
||||||
|
|
||||||
|
var previousValue = !!this._ios.showNavigationBar;
|
||||||
|
var page = page || this.currentPage;
|
||||||
|
var newValue = this._getNavBarVisible(page);
|
||||||
|
|
||||||
|
this._ios.showNavigationBar = newValue;
|
||||||
|
if (previousValue !== newValue) {
|
||||||
|
this.requestLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateNavigationBar(page?: pages.Page): void {
|
public _getNavBarVisible(page: pages.Page) {
|
||||||
var previousValue = !!this._ios.showNavigationBar;
|
if (!page) {
|
||||||
var newValue: boolean = false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newValue = false;
|
||||||
|
|
||||||
switch (this._ios.navBarVisibility) {
|
switch (this._ios.navBarVisibility) {
|
||||||
case enums.NavigationBarVisibility.always:
|
case enums.NavigationBarVisibility.always:
|
||||||
newValue = true;
|
newValue = true;
|
||||||
@ -83,21 +108,17 @@ export class Frame extends frameCommon.Frame {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case enums.NavigationBarVisibility.auto:
|
case enums.NavigationBarVisibility.auto:
|
||||||
var pageInstance: pages.Page = page || this.currentPage;
|
if (page && types.isDefined(page.actionBarHidden)) {
|
||||||
if (pageInstance && types.isDefined(pageInstance.actionBarHidden)) {
|
newValue = !page.actionBarHidden;
|
||||||
newValue = !pageInstance.actionBarHidden;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newValue = this.backStack.length > 0 || (pageInstance && !pageInstance.actionBar._isEmpty());
|
newValue = this.backStack.length > 0 || (page && !page.actionBar._isEmpty());
|
||||||
}
|
}
|
||||||
newValue = !!newValue; // Make sure it is boolean
|
newValue = !!newValue; // Make sure it is boolean
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._ios.showNavigationBar = newValue;
|
return !!newValue;
|
||||||
if (previousValue !== newValue) {
|
|
||||||
this.requestLayout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get ios(): definition.iOSFrame {
|
public get ios(): definition.iOSFrame {
|
||||||
@ -156,20 +177,132 @@ export class Frame extends frameCommon.Frame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UINavigationBarImpl extends UINavigationBar {
|
||||||
|
public static ObjCProtocols = [UINavigationBarDelegate];
|
||||||
|
|
||||||
|
static new(): UINavigationBarImpl {
|
||||||
|
return <UINavigationBarImpl>super.new();
|
||||||
|
}
|
||||||
|
|
||||||
|
private _originalDelegate: UINavigationBarDelegate;
|
||||||
|
|
||||||
|
get controller(): UINavigationControllerImpl {
|
||||||
|
return <UINavigationControllerImpl>this._originalDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
get ownerFrame(): Frame {
|
||||||
|
return this.controller.owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
get delegate() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
set delegate(value: UINavigationBarDelegate) {
|
||||||
|
this._originalDelegate = value;
|
||||||
|
(<any>this).super.delegate = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setItemsAnimated(items: NSArray, animated: boolean) {
|
||||||
|
if (items) {
|
||||||
|
trace.write("updating navigation bar items stack; original items count: " + items.count, trace.categories.Navigation);
|
||||||
|
|
||||||
|
items = this.controller._getNavBarItems();
|
||||||
|
|
||||||
|
trace.write("updated navigation bar items stack; new items count: " + items.count, trace.categories.Navigation);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.setItemsAnimated(items, animated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public navigationBarShouldPopItem(navBar: UINavigationBar, item: UINavigationItem): boolean {
|
||||||
|
// should pop will be called only when the NavigationBar is visible and in the following cases:
|
||||||
|
// 1. The user has pressed the back button - we need to manually call 'goBack' on the Frame
|
||||||
|
// 2. The user has programmatically called goBack on the Frame - in this case the '_popScheduled' flag is set to true
|
||||||
|
if (!this.controller._popScheduled) {
|
||||||
|
this.ownerFrame.goBack();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public navigationBarShouldPushItem(navBar: UINavigationBar, item: UINavigationItem): boolean {
|
||||||
|
var entry = this.ownerFrame._navigateToEntry || this.ownerFrame._currentEntry;
|
||||||
|
if (!entry) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var prevEntry: definition.BackstackEntry = entry[PREV_ENTRY];
|
||||||
|
if (!prevEntry) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.ownerFrame._isEntryBackstackVisible(prevEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
//private _callBaseDelegateMethod() {
|
||||||
|
// //var controller = UINavigationController.alloc().init();
|
||||||
|
// //var methodSignature = controller.methodSignatureForSelector("navigationBar:shouldPopItem:");
|
||||||
|
// //if (methodSignature != null) {
|
||||||
|
// // var invocation = NSInvocation.invocationWithMethodSignature(methodSignature);
|
||||||
|
// // invocation.target = controller;
|
||||||
|
// // invocation.selector = "navigationBar:shouldPopItem:";
|
||||||
|
|
||||||
|
// // invocation.setArgumentAtIndex(new interop.Reference(UINavigationBar, UINavigationBar.alloc().init()), 2);
|
||||||
|
// // invocation.setArgumentAtIndex(new interop.Reference(UINavigationItem, UINavigationItem.alloc().init()), 3);
|
||||||
|
|
||||||
|
// // invocation.invoke();
|
||||||
|
|
||||||
|
// // var result = new interop.Reference(interop.types.bool, false);
|
||||||
|
// // invocation.getReturnValue(result);
|
||||||
|
|
||||||
|
// // console.log(result.value);
|
||||||
|
// //}
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
class UINavigationControllerImpl extends UINavigationController implements UINavigationControllerDelegate {
|
class UINavigationControllerImpl extends UINavigationController implements UINavigationControllerDelegate {
|
||||||
public static ObjCProtocols = [UINavigationControllerDelegate];
|
public static ObjCProtocols = [UINavigationControllerDelegate];
|
||||||
|
|
||||||
static new(): UINavigationControllerImpl {
|
static new(): UINavigationControllerImpl {
|
||||||
return <UINavigationControllerImpl>super.new();
|
return new UINavigationControllerImpl(UINavigationBarImpl.class(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _owner: Frame;
|
private _owner: Frame;
|
||||||
|
public _popScheduled;
|
||||||
|
|
||||||
public initWithOwner(owner: Frame): UINavigationControllerImpl {
|
public initWithOwner(owner: Frame): UINavigationControllerImpl {
|
||||||
this._owner = owner;
|
this._owner = owner;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _getNavBarItems(): NSArray {
|
||||||
|
var frame = this._owner;
|
||||||
|
var backstack = frame.backStack;
|
||||||
|
var length = backstack.length;
|
||||||
|
var entry: definition.BackstackEntry;
|
||||||
|
|
||||||
|
var navItems = NSMutableArray.alloc().init();
|
||||||
|
for (let i = 0; i < length; i++) {
|
||||||
|
entry = backstack[i];
|
||||||
|
var controller: UIViewController = entry.resolvedPage.ios;
|
||||||
|
navItems.addObject(controller.navigationItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the top controller
|
||||||
|
entry = frame._navigateToEntry || frame._currentEntry;
|
||||||
|
if (entry) {
|
||||||
|
var topController = entry.resolvedPage.ios;
|
||||||
|
if (topController) {
|
||||||
|
navItems.addObject(topController.navigationItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return navItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
get owner(): Frame {
|
||||||
|
return this._owner;
|
||||||
|
}
|
||||||
|
|
||||||
public viewDidLoad(): void {
|
public viewDidLoad(): void {
|
||||||
this.view.autoresizesSubviews = false;
|
this.view.autoresizesSubviews = false;
|
||||||
this.view.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;
|
this.view.autoresizingMask = UIViewAutoresizing.UIViewAutoresizingNone;
|
||||||
@ -181,65 +314,91 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
|
|||||||
this._owner._updateLayout();
|
this._owner._updateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
public navigationControllerWillShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
public popToViewControllerAnimated(controller: UIViewController, animated: boolean): NSArray {
|
||||||
// In this method we need to layout the new page otherwise page will be shown empty and update after that which is bad UX.
|
// our _goBackCore routine uses popToViewController, hence it is granted this method is called through the navbar back button click
|
||||||
var frame = this._owner;
|
this._popScheduled = true;
|
||||||
|
return super.popToViewControllerAnimated(controller, animated);
|
||||||
|
}
|
||||||
|
|
||||||
|
navigationControllerWillShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
||||||
|
//// In this method we need to layout the new page otherwise page will be shown empty and update after that which is bad UX.
|
||||||
|
//var frame = this._owner;
|
||||||
|
//var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
||||||
|
//var newPage = newEntry.resolvedPage;
|
||||||
|
//if (!newPage.parent) {
|
||||||
|
// if (!frame._currentEntry) {
|
||||||
|
// // First navigation
|
||||||
|
// frame._currentEntry = newEntry;
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// frame._navigateToEntry = newEntry;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// frame._addView(newPage);
|
||||||
|
//}
|
||||||
|
//else if (newPage.parent !== frame) {
|
||||||
|
// throw new Error("Page is already shown on another frame.");
|
||||||
|
//}
|
||||||
|
|
||||||
|
//newPage.actionBar.update();
|
||||||
|
var currEntry = this._owner._currentEntry;
|
||||||
|
if (currEntry) {
|
||||||
|
this._owner._removeView(currEntry.resolvedPage);
|
||||||
|
//delete currEntry[PREV_ENTRY];
|
||||||
|
}
|
||||||
|
|
||||||
var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
||||||
var newPage = newEntry.resolvedPage;
|
var newPage = newEntry.resolvedPage;
|
||||||
if (!newPage.parent) {
|
|
||||||
if (!frame._currentEntry) {
|
|
||||||
// First navigation
|
|
||||||
frame._currentEntry = newEntry;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
frame._navigateToEntry = newEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
frame._addView(newPage);
|
newEntry[PREV_ENTRY] = currEntry;
|
||||||
}
|
this._owner._currentEntry = newEntry;
|
||||||
else if (newPage.parent !== frame) {
|
this._owner._navigateToEntry = undefined;
|
||||||
throw new Error("Page is already shown on another frame.");
|
this._owner._addView(newEntry.resolvedPage);
|
||||||
}
|
this._owner._updateActionBar(newEntry.resolvedPage);
|
||||||
|
|
||||||
|
newPage.onNavigatedTo();
|
||||||
newPage.actionBar.update();
|
newPage.actionBar.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
public navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
navigationControllerDidShowViewControllerAnimated(navigationController: UINavigationController, viewController: UIViewController, animated: boolean): void {
|
||||||
|
this._popScheduled = false;
|
||||||
|
var entry: definition.BackstackEntry = viewController[ENTRY];
|
||||||
|
this._owner._processNavigationQueue(entry.resolvedPage);
|
||||||
|
|
||||||
var frame: Frame = this._owner;
|
//var frame: Frame = this._owner;
|
||||||
var backStack = frame.backStack;
|
//var backStack = frame.backStack;
|
||||||
var currentEntry = backStack.length > 0 ? backStack[backStack.length - 1] : null;
|
//var currentEntry = backStack.length > 0 ? backStack[backStack.length - 1] : null;
|
||||||
var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
//var newEntry: definition.BackstackEntry = viewController[ENTRY];
|
||||||
|
|
||||||
// This code check if navigation happened through UI (e.g. back button or swipe gesture).
|
//// This code check if navigation happened through UI (e.g. back button or swipe gesture).
|
||||||
// When calling goBack on frame isBack will be false.
|
//// When calling goBack on frame isBack will be false.
|
||||||
var isBack: boolean = currentEntry && newEntry === currentEntry;
|
//var isBack: boolean = currentEntry && newEntry === currentEntry;
|
||||||
if (isBack) {
|
//if (isBack) {
|
||||||
try {
|
// try {
|
||||||
frame._shouldSkipNativePop = true;
|
// frame._shouldSkipNativePop = true;
|
||||||
frame.goBack();
|
// frame.goBack();
|
||||||
}
|
// }
|
||||||
finally {
|
// finally {
|
||||||
frame._shouldSkipNativePop = false;
|
// frame._shouldSkipNativePop = false;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
var page = frame.currentPage;
|
//var page = frame.currentPage;
|
||||||
if (page && !navigationController.viewControllers.containsObject(page.ios)) {
|
//if (page && !navigationController.viewControllers.containsObject(page.ios)) {
|
||||||
frame._removeView(page);
|
// frame._removeView(page);
|
||||||
}
|
//}
|
||||||
|
|
||||||
frame._navigateToEntry = null;
|
//frame._navigateToEntry = null;
|
||||||
frame._currentEntry = newEntry;
|
//frame._currentEntry = newEntry;
|
||||||
frame.updateNavigationBar();
|
//frame.updateNavigationBar();
|
||||||
|
|
||||||
frame.ios.controller.navigationBar.backIndicatorImage
|
//frame.ios.controller.navigationBar.backIndicatorImage
|
||||||
|
|
||||||
var newPage = newEntry.resolvedPage;
|
//var newPage = newEntry.resolvedPage;
|
||||||
|
|
||||||
// notify the page
|
//// notify the page
|
||||||
newPage.onNavigatedTo();
|
//newPage.onNavigatedTo();
|
||||||
frame._processNavigationQueue(newPage);
|
//frame._processNavigationQueue(newPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public supportedInterfaceOrientation(): number {
|
public supportedInterfaceOrientation(): number {
|
||||||
@ -258,7 +417,7 @@ class iOSFrame implements definition.iOSFrame {
|
|||||||
this._controller = UINavigationControllerImpl.new().initWithOwner(owner);
|
this._controller = UINavigationControllerImpl.new().initWithOwner(owner);
|
||||||
this._controller.delegate = this._controller;
|
this._controller.delegate = this._controller;
|
||||||
this._controller.automaticallyAdjustsScrollViewInsets = false;
|
this._controller.automaticallyAdjustsScrollViewInsets = false;
|
||||||
this.showNavigationBar = false;
|
//this.showNavigationBar = false;
|
||||||
this._navBarVisibility = enums.NavigationBarVisibility.auto;
|
this._navBarVisibility = enums.NavigationBarVisibility.auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import definition = require("ui/page");
|
|||||||
import viewModule = require("ui/core/view");
|
import viewModule = require("ui/core/view");
|
||||||
import trace = require("trace");
|
import trace = require("trace");
|
||||||
import utils = require("utils/utils");
|
import utils = require("utils/utils");
|
||||||
import types = require("utils/types");
|
|
||||||
|
|
||||||
global.moduleMerge(pageCommon, exports);
|
global.moduleMerge(pageCommon, exports);
|
||||||
|
|
||||||
@ -149,9 +148,9 @@ export class Page extends pageCommon.Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public _updateActionBar(hidden: boolean) {
|
public _updateActionBar(hidden: boolean) {
|
||||||
if (types.isDefined(hidden) && this.ios.navigationController.navigationBarHidden !== hidden) {
|
var frame = this.frame;
|
||||||
this.ios.navigationController.navigationBarHidden = hidden;
|
if (frame) {
|
||||||
this.requestLayout();
|
frame._updateActionBar(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user