mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Add visibility property to ActionItem
Adding the resource to the project file. Fix.
This commit is contained in:
@@ -21,7 +21,7 @@ function onTitlePropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
|
||||
export class ActionBar extends view.View implements dts.ActionBar {
|
||||
public static titleProperty = new dependencyObservable.Property("title", "ActionBar", new proxy.PropertyMetadata(undefined, dependencyObservable.PropertyMetadataSettings.None, onTitlePropertyChanged));
|
||||
|
||||
|
||||
private _actionItems: ActionItems;
|
||||
private _navigationButton: dts.NavigationButton;
|
||||
private _page: pages.Page;
|
||||
@@ -200,6 +200,17 @@ export class ActionItems implements dts.ActionItems {
|
||||
return this._items.slice();
|
||||
}
|
||||
|
||||
public getVisibleItems(): Array<dts.ActionItem> {
|
||||
var visibleItems = [];
|
||||
this._items.forEach((item) => {
|
||||
if (isVisible(item)) {
|
||||
visibleItems.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return visibleItems;
|
||||
}
|
||||
|
||||
public getItemAt(index: number): dts.ActionItem {
|
||||
if (index < 0 || index >= this._items.length) {
|
||||
return undefined;
|
||||
@@ -238,16 +249,15 @@ export class ActionItem extends bindable.Bindable implements dts.ActionItem {
|
||||
public static iconProperty = new dependencyObservable.Property(
|
||||
"icon", "ActionItem", new dependencyObservable.PropertyMetadata(null, null, ActionItem.onItemChanged));
|
||||
|
||||
private static onItemChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var menuItem = <ActionItem>data.object;
|
||||
if (menuItem.actionBar) {
|
||||
menuItem.actionBar.update();
|
||||
}
|
||||
}
|
||||
public static visibilityProperty = new dependencyObservable.Property(
|
||||
"visibility", "ActionItemBase", new dependencyObservable.PropertyMetadata(enums.Visibility.visible, null, ActionItem.onItemChanged));
|
||||
|
||||
private _actionBar: ActionBar;
|
||||
|
||||
get text(): string {
|
||||
return this._getValue(ActionItem.textProperty);
|
||||
}
|
||||
|
||||
set text(value: string) {
|
||||
this._setValue(ActionItem.textProperty, value);
|
||||
}
|
||||
@@ -255,14 +265,23 @@ export class ActionItem extends bindable.Bindable implements dts.ActionItem {
|
||||
get icon(): string {
|
||||
return this._getValue(ActionItem.iconProperty);
|
||||
}
|
||||
|
||||
set icon(value: string) {
|
||||
this._setValue(ActionItem.iconProperty, value);
|
||||
}
|
||||
|
||||
private _actionBar: ActionBar;
|
||||
get visibility(): string {
|
||||
return this._getValue(ActionItem.visibilityProperty);
|
||||
}
|
||||
|
||||
set visibility(value: string) {
|
||||
this._setValue(ActionItem.visibilityProperty, value);
|
||||
}
|
||||
|
||||
get actionBar(): ActionBar {
|
||||
return this._actionBar;
|
||||
}
|
||||
|
||||
set actionBar(value: ActionBar) {
|
||||
if (value !== this._actionBar) {
|
||||
this._actionBar = value;
|
||||
@@ -279,4 +298,14 @@ export class ActionItem extends bindable.Bindable implements dts.ActionItem {
|
||||
public ios: dts.IOSActionItemSettings;
|
||||
|
||||
public android: dts.AndroidActionItemSettings;
|
||||
}
|
||||
private static onItemChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var menuItem = <ActionItem>data.object;
|
||||
if (menuItem.actionBar) {
|
||||
menuItem.actionBar.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function isVisible(item: dts.ActionItem) {
|
||||
return item.visibility === enums.Visibility.visible;
|
||||
}
|
||||
|
||||
@@ -142,8 +142,7 @@ export class ActionBar extends common.ActionBar {
|
||||
|
||||
public _updateNavigationButton() {
|
||||
var navButton = this.navigationButton;
|
||||
if (navButton) {
|
||||
|
||||
if (navButton && common.isVisible(navButton)) {
|
||||
if (navButton.android.systemIcon) {
|
||||
// Try to look in the system resources.
|
||||
let systemResourceId = getSystemResourceId(navButton.android.systemIcon);
|
||||
@@ -208,7 +207,7 @@ export class ActionBar extends common.ActionBar {
|
||||
|
||||
public _addActionItems() {
|
||||
var menu = this._toolbar.getMenu();
|
||||
var items = this.actionItems.getItems();
|
||||
var items = this.actionItems.getVisibleItems();
|
||||
|
||||
menu.clear();
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
|
||||
10
ui/action-bar/action-bar.d.ts
vendored
10
ui/action-bar/action-bar.d.ts
vendored
@@ -103,6 +103,11 @@ declare module "ui/action-bar" {
|
||||
*/
|
||||
public static iconProperty: dependencyObservable.Property;
|
||||
|
||||
/**
|
||||
* Represents the observable property backing the visibility property.
|
||||
*/
|
||||
public static visibilityProperty: dependencyObservable.Property;
|
||||
|
||||
/**
|
||||
* Gets or sets the text of the action item.
|
||||
*/
|
||||
@@ -112,6 +117,11 @@ declare module "ui/action-bar" {
|
||||
* Gets or sets the icon of the action item.
|
||||
*/
|
||||
icon: string;
|
||||
|
||||
/**
|
||||
* Gets or sets the visibility of the action item.
|
||||
*/
|
||||
visibility: string;
|
||||
|
||||
/**
|
||||
* Gets the action bar that contains the action item.
|
||||
|
||||
@@ -35,8 +35,8 @@ export class ActionBar extends common.ActionBar {
|
||||
|
||||
var viewController = (<UIViewController>this.page.ios);
|
||||
var navigationItem: UINavigationItem = viewController.navigationItem;
|
||||
var navController = frameModule.topmost().ios.controller;
|
||||
var navigationBar = navController.navigationBar;
|
||||
var navController = frameModule.topmost().ios.controller;
|
||||
var navigationBar = <UINavigationBar>navController.navigationBar;
|
||||
var previousController: UIViewController;
|
||||
|
||||
// Set Title
|
||||
@@ -66,7 +66,7 @@ export class ActionBar extends common.ActionBar {
|
||||
|
||||
// Set back button image
|
||||
var img: imageSource.ImageSource;
|
||||
if (this.navigationButton && this.navigationButton.icon) {
|
||||
if (this.navigationButton && common.isVisible(this.navigationButton) && this.navigationButton.icon) {
|
||||
img = imageSource.fromFileOrResource(this.navigationButton.icon);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,11 @@ export class ActionBar extends common.ActionBar {
|
||||
navigationBar.backIndicatorTransitionMaskImage = null;
|
||||
}
|
||||
|
||||
// Set back button visibility
|
||||
if (this.navigationButton) {
|
||||
navigationItem.setHidesBackButtonAnimated(!common.isVisible(this.navigationButton), true);
|
||||
}
|
||||
|
||||
// Populate action items
|
||||
this.populateMenuItems(navigationItem);
|
||||
|
||||
@@ -91,7 +96,7 @@ export class ActionBar extends common.ActionBar {
|
||||
}
|
||||
|
||||
private populateMenuItems(navigationItem: UINavigationItem) {
|
||||
var items = this.actionItems.getItems();
|
||||
var items = this.actionItems.getVisibleItems();
|
||||
var leftBarItems = [];
|
||||
var rightBarItems = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user