UNPKG

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