Resolved issue #263

This commit is contained in:
Rossen Hristov
2015-07-01 14:15:38 +03:00
parent ccfd625ea0
commit 4d30170bbe
5 changed files with 89 additions and 6 deletions

View File

@ -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 = <Page>data.object;
if (page.isLoaded) {
page._updateNavigationBar(data.newValue);
}
}
(<proxy.PropertyMetadata>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 {

View File

@ -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();
}
}
}
}

10
ui/page/page.d.ts vendored
View File

@ -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).
*/

View File

@ -175,6 +175,13 @@ export class Page extends pageCommon.Page {
(<any>this)._isModal = false;
(<any>this)._UIModalPresentationFormSheet = false;
}
public _updateNavigationBar(hidden: boolean) {
if (this.ios.navigationController.navigationBarHidden !== hidden) {
this.ios.navigationController.navigationBarHidden = hidden;
this.requestLayout();
}
}
}
class TapBarItemHandlerImpl extends NSObject {

View File

@ -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<definition.TabViewItem>) {
var parentPage = <page.Page>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<definition.TabViewItem>) {
var parentPage = <page.Page>view.getAncestor(this, "Page");
if (parentPage && parentPage.navigationBarHidden) {
return;
}
trace.write("TabView._removeTabs(" + oldItems + ");", common.traceCategory);
super._removeTabs(oldItems);
@ -469,13 +481,10 @@ 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) {
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
var viewPagerSelectedIndex = this._android.getCurrentItem();