UNPKG

14.5 kBTypeScriptView Raw
1import { Property, CssProperty, CssAnimationProperty, InheritedProperty } from '../properties';
2import { BindingOptions } from '../bindable';
3import { Observable } from '../../../data/observable';
4import { Style } from '../../styling/style';
5import { CoreTypes } from '../../../core-types';
6import { Page } from '../../page';
7
8import { Order, FlexGrow, FlexShrink, FlexWrapBefore, AlignSelf } from '../../layouts/flexbox-layout';
9import { Length } from '../../styling/style-properties';
10import { DOMNode } from '../../../debugger/dom-node';
11
12/**
13 * Iterates through all child views (via visual tree) and executes a function.
14 * @param view - Starting view (parent container).
15 * @param callback - A function to execute on every child. If function returns false it breaks the iteration.
16 */
17export function eachDescendant(view: ViewBase, callback: (child: ViewBase) => boolean);
18
19/**
20 * Gets an ancestor from a given type.
21 * @param view - Starting view (child view).
22 * @param criterion - The type of ancestor view we are looking for. Could be a string containing a class name or an actual type.
23 * Returns an instance of a view (if found), otherwise undefined.
24 */
25export function getAncestor(view: ViewBase, criterion: string | Function): ViewBase;
26
27export function isEventOrGesture(name: string, view: ViewBase): boolean;
28
29/**
30 * Gets a child view by id.
31 * @param view - The parent (container) view of the view to look for.
32 * @param id - The id of the view to look for.
33 * Returns an instance of a view (if found), otherwise undefined.
34 */
35export function getViewById(view: ViewBase, id: string): ViewBase;
36
37/**
38 * Gets a child view by domId.
39 * @param view - The parent (container) view of the view to look for.
40 * @param domId - The id of the view to look for.
41 * Returns an instance of a view (if found), otherwise undefined.
42 */
43export function getViewByDomId(view: ViewBase, domId: number): ViewBase;
44
45export interface ShowModalOptions {
46 /**
47 * Any context you want to pass to the modally shown view. This same context will be available in the arguments of the shownModally event handler.
48 */
49 context: any;
50
51 /**
52 * A function that will be called when the view is closed. Any arguments provided when calling ShownModallyData.closeCallback will be available here.
53 */
54 closeCallback: Function;
55
56 /**
57 * An optional parameter specifying whether to show the modal view in full-screen mode.
58 */
59 fullscreen?: boolean;
60
61 /**
62 * An optional parameter specifying whether to show the modal view with animation.
63 */
64 animated?: boolean;
65
66 /**
67 * An optional parameter specifying whether to stretch the modal view when not in full-screen mode.
68 */
69 stretched?: boolean;
70
71 /**
72 * An optional parameter that specify options specific to iOS as an object.
73 */
74 ios?: {
75 /**
76 * The UIModalPresentationStyle to be used when showing the dialog in iOS .
77 */
78 presentationStyle?: any /* UIModalPresentationStyle */;
79 /**
80 * width of the popup dialog
81 */
82 width?: number;
83 /**
84 * height of the popup dialog
85 */
86 height?: number;
87 };
88 android?: {
89 /**
90 * @deprecated Use ShowModalOptions.cancelable instead.
91 * An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
92 */
93 cancelable?: boolean;
94 /**
95 * An optional parameter specifying the windowSoftInputMode of the dialog window
96 * For possible values see https://developer.android.com/reference/android/view/WindowManager.LayoutParams#softInputMode
97 */
98 windowSoftInputMode?: number;
99 };
100 /**
101 * An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
102 */
103 cancelable?: boolean;
104}
105
106export abstract class ViewBase extends Observable {
107 // Dynamic properties.
108 left: CoreTypes.LengthType;
109 top: CoreTypes.LengthType;
110 effectiveLeft: number;
111 effectiveTop: number;
112 dock: 'left' | 'top' | 'right' | 'bottom';
113 row: number;
114 col: number;
115 /**
116 * Setting `column` property is the same as `col`
117 */
118 column: number;
119 rowSpan: number;
120 colSpan: number;
121 /**
122 * Setting `columnSpan` property is the same as `colSpan`
123 */
124 columnSpan: number;
125 domNode: DOMNode;
126
127 order: Order;
128 flexGrow: FlexGrow;
129 flexShrink: FlexShrink;
130 flexWrapBefore: FlexWrapBefore;
131 alignSelf: AlignSelf;
132
133 /**
134 * @private
135 * Module name when the view is a module root. Otherwise, it is undefined.
136 */
137 _moduleName?: string;
138
139 //@private
140 /**
141 * @private
142 */
143 _oldLeft: number;
144 /**
145 * @private
146 */
147 _oldTop: number;
148 /**
149 * @private
150 */
151 _oldRight: number;
152 /**
153 * @private
154 */
155 _oldBottom: number;
156 /**
157 * @private
158 */
159 _defaultPaddingTop: number;
160 /**
161 * @private
162 */
163 _defaultPaddingRight: number;
164 /**
165 * @private
166 */
167 _defaultPaddingBottom: number;
168 /**
169 * @private
170 */
171 _defaultPaddingLeft: number;
172
173 /**
174 * A property bag holding suspended native updates.
175 * Native setters that had to execute while there was no native view,
176 * or the view was detached from the visual tree etc. will accumulate in this object,
177 * and will be applied when all prerequisites are met.
178 * @private
179 */
180 _suspendedUpdates: {
181 [propertyName: string]: Property<any, any> | CssProperty<Style, any> | CssAnimationProperty<Style, any>;
182 };
183 //@endprivate
184
185 /**
186 * Shows the View contained in moduleName as a modal view.
187 * @param moduleName - The name of the module to load starting from the application root.
188 * @param modalOptions - A ShowModalOptions instance
189 */
190 showModal(moduleName: string, modalOptions?: ShowModalOptions): ViewBase;
191
192 /**
193 * Shows the view passed as parameter as a modal view.
194 * @param view - View instance to be shown modally.
195 * @param modalOptions - A ShowModalOptions instance
196 */
197 showModal(view: ViewBase, modalOptions?: ShowModalOptions): ViewBase;
198
199 /**
200 * Closes the current modal view that this page is showing.
201 * @param context - Any context you want to pass back to the host when closing the modal view.
202 */
203 closeModal(context?: any): void;
204
205 public effectiveMinWidth: number;
206 public effectiveMinHeight: number;
207 public effectiveWidth: number;
208 public effectiveHeight: number;
209 public effectiveMarginTop: number;
210 public effectiveMarginRight: number;
211 public effectiveMarginBottom: number;
212 public effectiveMarginLeft: number;
213 public effectivePaddingTop: number;
214 public effectivePaddingRight: number;
215 public effectivePaddingBottom: number;
216 public effectivePaddingLeft: number;
217 public effectiveBorderTopWidth: number;
218 public effectiveBorderRightWidth: number;
219 public effectiveBorderBottomWidth: number;
220 public effectiveBorderLeftWidth: number;
221
222 /**
223 * String value used when hooking to loaded event.
224 */
225 public static loadedEvent: string;
226
227 /**
228 * String value used when hooking to unloaded event.
229 */
230 public static unloadedEvent: string;
231
232 /**
233 * String value used when hooking to creation event
234 */
235 public static createdEvent: string;
236
237 /**
238 * String value used when hooking to disposeNativeView event
239 */
240 public static disposeNativeViewEvent: string;
241
242 public ios: any;
243 public android: any;
244
245 /**
246 * returns the native UIViewController.
247 */
248 public viewController: any;
249
250 /**
251 * read-only. If you want to set out-of-band the nativeView use the setNativeView method.
252 */
253 public nativeViewProtected: any;
254 public nativeView: any;
255 public bindingContext: any;
256
257 /**
258 * Gets or sets if the view is reusable.
259 * Reusable views are not automatically destroyed when removed from the View tree.
260 */
261 public reusable: boolean;
262
263 /**
264 * Gets the name of the constructor function for this instance. E.g. for a Button class this will return "Button".
265 */
266 public typeName: string;
267
268 /**
269 * Gets the parent view. This property is read-only.
270 */
271 public readonly parent: ViewBase;
272
273 /**
274 * Gets the template parent or the native parent. Sets the template parent.
275 */
276 public parentNode: ViewBase;
277
278 /**
279 * Gets or sets the id for this view.
280 */
281 public id: string;
282
283 /**
284 * Gets or sets the CSS class name for this view.
285 */
286 public className: string;
287
288 /**
289 * Gets owner page. This is a read-only property.
290 */
291 public readonly page: Page;
292
293 /**
294 * Gets the style object associated to this view.
295 */
296 public readonly style: Style;
297
298 /**
299 * Returns true if visibility is set to 'collapse'.
300 * Readonly property
301 */
302 public isCollapsed: boolean;
303 public readonly isLoaded: boolean;
304
305 /**
306 * Returns the child view with the specified id.
307 */
308 public getViewById<T extends ViewBase>(id: string): T;
309
310 /**
311 * Returns the child view with the specified domId.
312 */
313 public getViewByDomId<T extends ViewBase>(id: number): T;
314
315 /**
316 * Load view.
317 * @param view to load.
318 */
319 public loadView(view: ViewBase): void;
320
321 /**
322 * Unload view.
323 * @param view to unload.
324 */
325 public unloadView(view: ViewBase): void;
326
327 public onLoaded(): void;
328 public onUnloaded(): void;
329 public onResumeNativeUpdates(): void;
330
331 public bind(options: BindingOptions, source?: Object): void;
332 public unbind(property: string): void;
333
334 /**
335 * Invalidates the layout of the view and triggers a new layout pass.
336 */
337 public requestLayout(): void;
338
339 /**
340 * Iterates over children of type ViewBase.
341 * @param callback Called for each child of type ViewBase. Iteration stops if this method returns falsy value.
342 */
343 public eachChild(callback: (child: ViewBase) => boolean): void;
344
345 public _addView(view: ViewBase, atIndex?: number): void;
346 /**
347 * Method is intended to be overridden by inheritors and used as "protected"
348 */
349 public _addViewCore(view: ViewBase, atIndex?: number): void;
350
351 public _removeView(view: ViewBase): void;
352 /**
353 * Method is intended to be overridden by inheritors and used as "protected"
354 */
355 public _removeViewCore(view: ViewBase): void;
356 public _parentChanged(oldParent: ViewBase): void;
357 /**
358 * Method is intended to be overridden by inheritors and used as "protected"
359 */
360 public _dialogClosed(): void;
361 /**
362 * Method is intended to be overridden by inheritors and used as "protected"
363 */
364 public _onRootViewReset(): void;
365
366 _domId: number;
367
368 _cssState: any /* "ui/styling/style-scope" */;
369 /**
370 * @private
371 * Notifies each child's css state for change, recursively.
372 * Either the style scope, className or id properties were changed.
373 */
374 _onCssStateChange(): void;
375
376 public cssClasses: Set<string>;
377 public cssPseudoClasses: Set<string>;
378
379 public _goToVisualState(state: string): void;
380
381 public setInlineStyle(style: string): void;
382
383 _context: any /* android.content.Context */;
384
385 /**
386 * Setups the UI for ViewBase and all its children recursively.
387 * This method should *not* be overridden by derived views.
388 */
389 _setupUI(context: any /* android.content.Context */, atIndex?: number): void;
390
391 /**
392 * Tears down the UI for ViewBase and all its children recursively.
393 * This method should *not* be overridden by derived views.
394 */
395 _tearDownUI(force?: boolean): void;
396
397 /**
398 * Tears down the UI of a reusable node by making it no longer reusable.
399 * @see _tearDownUI
400 * @param forceDestroyChildren Force destroy the children (even if they are reusable)
401 */
402 destroyNode(forceDestroyChildren?: boolean): void;
403
404 /**
405 * Creates a native view.
406 * Returns either android.view.View or UIView.
407 */
408 createNativeView(): Object;
409
410 /**
411 * Initializes properties/listeners of the native view.
412 */
413 initNativeView(): void;
414
415 /**
416 * Clean up references to the native view.
417 */
418 disposeNativeView(): void;
419
420 /**
421 * Resets properties/listeners set to the native view.
422 */
423 resetNativeView(): void;
424
425 /**
426 * Set the nativeView field performing extra checks and updates to the native properties on the new view.
427 * Use in cases where the createNativeView is not suitable.
428 * As an example use in item controls where the native parent view will create the native views for child items.
429 */
430 setNativeView(view: any): void;
431
432 _isAddedToNativeVisualTree: boolean;
433
434 /**
435 * Performs the core logic of adding a child view to the native visual tree. Returns true if the view's native representation has been successfully added, false otherwise.
436 */
437 _addViewToNativeVisualTree(view: ViewBase, atIndex?: number): boolean;
438 _removeViewFromNativeVisualTree(view: ViewBase): void;
439 _childIndexToNativeChildIndex(index?: number): number;
440
441 /**
442 * @protected
443 * @unstable
444 * A widget can call this method to add a matching css pseudo class.
445 */
446 public addPseudoClass(name: string): void;
447
448 /**
449 * @protected
450 * @unstable
451 * A widget can call this method to discard matching css pseudo class.
452 */
453 public deletePseudoClass(name: string): void;
454
455 /**
456 * @unstable
457 * Ensures a dom-node for this view.
458 */
459 public ensureDomNode();
460
461 public recycleNativeView: 'always' | 'never' | 'auto';
462
463 /**
464 * @private
465 */
466 public _isPaddingRelative: boolean;
467
468 /**
469 * @private
470 */
471 public _ignoreFlexMinWidthHeightReset: boolean;
472
473 public _styleScope: any;
474
475 /**
476 * @private
477 */
478 public _automaticallyAdjustsScrollViewInsets: boolean;
479 /**
480 * @private
481 */
482 _isStyleScopeHost: boolean;
483
484 /**
485 * @private
486 */
487 public _layoutParent(): void;
488
489 /**
490 * Determines the depth of suspended updates.
491 * When the value is 0 the current property updates are not batched nor scoped and must be immediately applied.
492 * If the value is 1 or greater, the current updates are batched and does not have to provide immediate update.
493 * Do not set this field, the _batchUpdate method is responsible to keep the count up to date,
494 * as well as adding/rmoving the view to/from the visual tree.
495 */
496 public _suspendNativeUpdatesCount: number;
497
498 /**
499 * Allow multiple updates to be performed on the instance at once.
500 */
501 public _batchUpdate<T>(callback: () => T): T;
502 /**
503 * @private
504 */
505 _setupAsRootView(context: any): void;
506
507 /**
508 * When returning true the callLoaded method will be run in setTimeout
509 * Method is intended to be overridden by inheritors and used as "protected"
510 */
511 _shouldDelayLayout(): boolean;
512
513 /**
514 * @private
515 */
516 _inheritStyleScope(styleScope: any /* StyleScope */): void;
517
518 /**
519 * @private
520 */
521 callLoaded(): void;
522
523 /**
524 * @private
525 */
526 callUnloaded(): void;
527 //@endprivate
528}
529
530export class Binding {
531 constructor(target: ViewBase, options: BindingOptions);
532 public bind(source: Object): void;
533 public unbind();
534}
535
536export const idProperty: Property<any, string>;
537export const classNameProperty: Property<any, string>;
538export const bindingContextProperty: InheritedProperty<any, any>;
539
540/**
541 * Converts string into boolean value.
542 * Throws error if value is not 'true' or 'false'.
543 */
544export function booleanConverter(v: string): boolean;
545
\No newline at end of file