diff --git a/ui/page/page-common.ts b/ui/page/page-common.ts index a95fb15f2..8dc9124d3 100644 --- a/ui/page/page-common.ts +++ b/ui/page/page-common.ts @@ -9,14 +9,32 @@ import bindable = require("ui/core/bindable"); import dependencyObservable = require("ui/core/dependency-observable"); import enums = require("ui/enums"); import frameCommon = require("ui/frame/frame-common"); +import proxy = require("ui/core/proxy"); var OPTIONS_MENU = "optionsMenu"; +var navigationBarHiddenProperty = new dependencyObservable.Property( + "navigationBarHidden", + "Page", + new proxy.PropertyMetadata(false, dependencyObservable.PropertyMetadataSettings.AffectsLayout) + ); + +function onNavigationBarHiddenPropertyChanged(data: dependencyObservable.PropertyChangeData) { + console.log("onNavigationBarHiddenPropertyChanged("+data.newValue+")"); + var page = data.object; + if (page.isLoaded) { + page._updateNavigationBar(data.newValue); + } +} + +(navigationBarHiddenProperty.metadata).onSetNativeValue = onNavigationBarHiddenPropertyChanged; + export module knownCollections { export var optionsMenu = "optionsMenu"; } export class Page extends contentView.ContentView implements dts.Page, view.AddArrayFromBuilder { + public static navigationBarHiddenProperty = navigationBarHiddenProperty; public static navigatingToEvent = "navigatingTo"; public static navigatedToEvent = "navigatedTo"; public static navigatingFromEvent = "navigatingFrom"; @@ -36,9 +54,24 @@ export class Page extends contentView.ContentView implements dts.Page, view.AddA public onLoaded() { this._applyCss(); + this._updateNavigationBar(this.navigationBarHidden); super.onLoaded(); } + get navigationBarHidden(): boolean { + console.log("page-common get navigationBarHidden: " + this._getValue(Page.navigationBarHiddenProperty)); + return this._getValue(Page.navigationBarHiddenProperty); + } + + set navigationBarHidden(value: boolean) { + console.log("page-common set navigationBarHidden: " + value); + this._setValue(Page.navigationBarHiddenProperty, value); + } + + public _updateNavigationBar(hidden: boolean) { + console.log("page-common._updateNavigationBar("+hidden+")"); + } + get navigationContext(): any { return this._navigationContext; } @@ -204,6 +237,7 @@ export class Page extends contentView.ContentView implements dts.Page, view.AddA this.optionsMenu.setItems(value); } } + } export class OptionsMenu implements dts.OptionsMenu { diff --git a/ui/page/page.android.ts b/ui/page/page.android.ts index f7ee71f77..e1387e7ef 100644 --- a/ui/page/page.android.ts +++ b/ui/page/page.android.ts @@ -89,4 +89,27 @@ export class Page extends pageCommon.Page { this._isAddedToNativeVisualTree = false; this._onDetached(true); } + + public _updateNavigationBar(hidden: boolean) { + if (!this.frame || !this.frame.android) { + return; + } + + var actionBar = this.frame.android.actionBar; + + if (!actionBar) { + return; + } + + if (hidden) { + if (actionBar.isShowing()) { + actionBar.hide(); + } + } + else { + if (!actionBar.isShowing()) { + actionBar.show(); + } + } + } } \ No newline at end of file diff --git a/ui/page/page.d.ts b/ui/page/page.d.ts index f1b36b8c7..496c2b79a 100644 --- a/ui/page/page.d.ts +++ b/ui/page/page.d.ts @@ -46,6 +46,11 @@ declare module "ui/page" { * Represents a logical unit for navigation (inside Frame). */ export class Page extends contentView.ContentView implements view.AddArrayFromBuilder { + /** + * Dependency property used to hide the Navigation Bar in iOS and the Action Bar in Android. + */ + public static navigationBarHiddenProperty: dependencyObservable.Property; + /** * String value used when hooking to shownModally event. */ @@ -73,6 +78,11 @@ declare module "ui/page" { constructor(options?: Options) + /** + * Used to hide the Navigation Bar in iOS and the Action Bar in Android. + */ + navigationBarHidden: boolean; + /** * A valid css string which will be applied for all nested UI components (based on css rules). */ diff --git a/ui/page/page.ios.ts b/ui/page/page.ios.ts index 41e3fb2e6..997492a9f 100644 --- a/ui/page/page.ios.ts +++ b/ui/page/page.ios.ts @@ -175,6 +175,13 @@ export class Page extends pageCommon.Page { (this)._isModal = false; (this)._UIModalPresentationFormSheet = false; } + + public _updateNavigationBar(hidden: boolean) { + if (this.ios.navigationController.navigationBarHidden !== hidden) { + this.ios.navigationController.navigationBarHidden = hidden; + this.requestLayout(); + } + } } class TapBarItemHandlerImpl extends NSObject { diff --git a/ui/tab-view/tab-view.android.ts b/ui/tab-view/tab-view.android.ts index a99a3f369..291b7d6f1 100644 --- a/ui/tab-view/tab-view.android.ts +++ b/ui/tab-view/tab-view.android.ts @@ -6,6 +6,7 @@ import trace = require("trace"); import imageSource = require("image-source"); import types = require("utils/types"); import app = require("application"); +import page = require("ui/page"); var VIEWS_STATES = "_viewStates"; var RESOURCE_PREFIX = "res://"; @@ -345,6 +346,11 @@ export class TabView extends common.TabView { } public _addTabs(newItems: Array) { + var parentPage = view.getAncestor(this, "Page"); + if (parentPage && parentPage.navigationBarHidden) { + return; + } + trace.write("TabView._addTabs(" + newItems + ");", common.traceCategory); super._addTabs(newItems); @@ -364,6 +370,7 @@ export class TabView extends common.TabView { actionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS); this._originalActionBarIsShowing = actionBar.isShowing(); + actionBar.show(); // TODO: Where will be the support for more ActionBar settings like Title, Navigation buttons, etc.? @@ -416,6 +423,11 @@ export class TabView extends common.TabView { } public _removeTabs(oldItems: Array) { + var parentPage = view.getAncestor(this, "Page"); + if (parentPage && parentPage.navigationBarHidden) { + return; + } + trace.write("TabView._removeTabs(" + oldItems + ");", common.traceCategory); super._removeTabs(oldItems); @@ -469,12 +481,9 @@ export class TabView extends common.TabView { // Select the respective tab in the ActionBar. var actionBar = this._getActionBar(); - if (actionBar) { - var actionBarSelectedIndex = actionBar.getSelectedNavigationIndex(); - if (actionBarSelectedIndex !== index) { - trace.write("TabView actionBar.setSelectedNavigationItem("+index+")", common.traceCategory); - actionBar.setSelectedNavigationItem(index); - } + if (actionBar && index < actionBar.getNavigationItemCount() && index !== actionBar.getSelectedNavigationIndex()) { + trace.write("TabView actionBar.setSelectedNavigationItem("+index+")", common.traceCategory); + actionBar.setSelectedNavigationItem(index); } // Select the respective page in the ViewPager