UNPKG

6.93 kBTypeScriptView Raw
1import { View } from '../core/view';
2import { ViewBase } from '../core/view-base';
3import { EventData } from '../../data/observable';
4
5/**
6 * Provides an abstraction over the ActionBar (android) and NavigationBar (iOS).
7 */
8export class ActionBar extends View {
9 /**
10 * Gets or sets the action bar title.
11 */
12 title: string;
13
14 /**
15 * Gets or sets the title view. When set - replaces the title with a custom view.
16 */
17 titleView: View;
18
19 /**
20 * Gets or sets the navigation button (a.k.a. the back button).
21 */
22 navigationButton: NavigationButton;
23
24 /**
25 * Removes the shadow/border at the bottom of the ActionBar and removes translucency on iOS.
26 * Default false.
27 */
28 flat: boolean;
29
30 /**
31 * Gets the collection of action items.
32 */
33 actionItems: ActionItems;
34
35 /**
36 * Gets the android specific options of the action bar.
37 */
38 android: AndroidActionBarSettings;
39
40 /**
41 * Gets the native iOS [UINavigationBar](https://developer.apple.com/documentation/uikit/uinavigationbar) that represents the user interface for this component. Valid only when running on iOS.
42 */
43 ios: any /* UITabBarController */;
44
45 /**
46 * Gets or set the UIImageRenderingMode of the action bar icons in iOS. Defaults to "alwaysOriginal"
47 * Valid values are:
48 * - automatic
49 * - alwaysOriginal
50 * - alwaysTemplate
51 */
52 iosIconRenderingMode: 'automatic' | 'alwaysOriginal' | 'alwaysTemplate';
53
54 public effectiveContentInsetLeft: number;
55 public effectiveContentInsetRight: number;
56
57 /**
58 * Updates the action bar.
59 */
60 update();
61
62 //@private
63 /**
64 * @private
65 */
66 _isEmpty(): boolean;
67 /**
68 * @private
69 */
70 _getActualSize?: { width: number; height: number };
71 //@endprivate
72}
73
74/**
75 * Represents a collection of ActionItems.
76 */
77export class ActionItems {
78 /**
79 * Adds an item to the collection.
80 * @param item - the item to be added
81 */
82 addItem(item: ActionItem): void;
83
84 /**
85 * Removes an item to the collection.
86 * @param item - The item to be removed.
87 */
88 removeItem(item: ActionItem): void;
89
90 /**
91 * Gets an array of the current action items in the collection.
92 */
93 getItems(): Array<ActionItem>;
94
95 /**
96 * Gets an item at a specified index.
97 * @param index - The index.
98 */
99 getItemAt(index: number): ActionItem;
100}
101
102/**
103 * Represents an action item in the action bar.
104 */
105export class ActionItem extends ViewBase {
106 /**
107 * Gets or sets the text of the action item.
108 */
109 text: string;
110
111 /**
112 * Gets or sets the icon of the action item.
113 */
114 icon: string;
115
116 /**
117 * Gets or sets the custom action view of the action item.
118 */
119 actionView: View;
120
121 /**
122 * Gets or sets the visibility of the action item.
123 */
124 visibility: string;
125
126 /**
127 * Gets the action bar that contains the action item.
128 */
129 actionBar: ActionBar;
130
131 /**
132 * A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
133 * @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
134 * @param callback - Callback function which will be executed when event is raised.
135 * @param thisArg - An optional parameter which will be used as `this` context for callback execution.
136 */
137 on(eventNames: string, callback: (data: EventData) => void): void;
138
139 /**
140 * Raised when a tap event occurs.
141 */
142 on(event: 'tap', callback: (args: EventData) => void): void;
143
144 //@private
145 /**
146 * @private
147 */
148 _raiseTap(): void;
149 //@endprivate
150
151 /**
152 * Gets the iOS specific options of the action item.
153 */
154 // @ts-ignore
155 ios: IOSActionItemSettings;
156
157 /**
158 * Gets the Android specific options of the action item.
159 */
160 // @ts-ignore
161 android: AndroidActionItemSettings;
162}
163
164/**
165 * Represents Android specific options of the action item.
166 */
167export interface AndroidActionItemSettings {
168 /**
169 * Gets or sets the position of the action item in the action bar.
170 * 1. actionBar - item is shown in the action bar.
171 * 2. actionBarIfRoom - item is shown in the action bar if there is room for it. Otherwise it is put in the popup menu.
172 * 3. popup - item is shown in the popup menu.
173 * Note: Property not applicable to NavigationButton
174 */
175 position: 'actionBar' | 'actionBarIfRoom' | 'popup';
176
177 /**
178 * Gets or sets the name of the system drawable resource to be displayed.
179 * Use this property instead of ActionItem.icon if you want to diplsay a built-in Android system icon.
180 * The value should be a string such as 'ic_menu_search' if you want to display the built-in Android Menu Search icon for example.
181 * For a full list of Android drawable names, please visit http://androiddrawables.com
182 */
183 systemIcon: string;
184}
185
186/**
187 * Represents iOS specific options of the action item.
188 */
189export interface IOSActionItemSettings {
190 /**
191 * Gets or sets the position of the action item in the action bar.
192 * 1. left - items is shown at the left part of the navigation bar. This is the default value.
193 * 2. right - items is shown at the right part of the navigation bar.
194 * Note: Property not applicable to NavigationButton
195 */
196 position: 'left' | 'right';
197
198 /**
199 * Gets or sets a number representing the iOS system item to be displayed.
200 * Use this property instead of ActionItem.icon if you want to diplsay a built-in iOS system icon.
201 * Note: Property not applicable to NavigationButton
202 * The value should be a number from the UIBarButtonSystemItem enumeration
203 * (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIBarButtonItem_Class/#//apple_ref/c/tdef/UIBarButtonSystemItem)
204 * 0: Done
205 * 1: Cancel
206 * 2: Edit
207 * 3: Save
208 * 4: Add
209 * 5: FlexibleSpace
210 * 6: FixedSpace
211 * 7: Compose
212 * 8: Reply
213 * 9: Action
214 * 10: Organize
215 * 11: Bookmarks
216 * 12: Search
217 * 13: Refresh
218 * 14: Stop
219 * 15: Camera
220 * 16: Trash
221 * 17: Play
222 * 18: Pause
223 * 19: Rewind
224 * 20: FastForward
225 * 21: Undo
226 * 22: Redo
227 * 23: PageCurl
228 */
229 systemIcon: number;
230}
231
232/**
233 * Represents Android specific options of the action bar.
234 */
235export interface AndroidActionBarSettings {
236 /**
237 * Gets or sets the action bar icon.
238 */
239 icon: string;
240
241 /**
242 * Gets or sets the visibility of the action bar icon.
243 * The icon is visible by default in pre-lollipop (API level < 20) versions of android and is hidden in lollipop (API level >= 20)
244 * The possible values are:
245 * 1. auto - the default behavior. This is the default value.
246 * 2. always - the icon is always shown.
247 * 3. never - the icon is always hidden.
248 */
249 iconVisibility: string;
250}
251
252/**
253 * Represents the navigation (a.k.a. "back") button.
254 */
255export class NavigationButton extends ActionItem {
256 //@private
257 /**
258 * @private
259 */
260 _navigationItem?: any;
261 //@endprivate
262}
263
264/** @internal */
265export function _setNavBarColor(navBar: any /* UINavigationBar */, color: any /* UIColor */);
266/** @internal */
267export function _setNavBarBackgroundColor(navBar: any /* UINavigationBar */, color: any /* UIColor */);