@nativescript/core
Version:
A JavaScript library providing an easy to use api for interacting with iOS and Android platform APIs.
493 lines (492 loc) • 17.9 kB
TypeScript
import { AlignSelf, FlexGrow, FlexShrink, FlexWrapBefore, Order } from '../../layouts/flexbox-layout';
import { Page } from '../../page';
import { CoreTypes } from '../../../core-types';
import { Property, CssProperty, CssAnimationProperty, InheritedProperty } from '../properties';
import { BindingOptions } from '../bindable';
import { Observable } from '../../../data/observable';
import { Style } from '../../styling/style';
import type { ModalTransition } from '../../transition/modal-transition';
import * as dnm from '../../../debugger/dom-node';
import * as ssm from '../../styling/style-scope';
import { ViewBase as ViewBaseDefinition } from '.';
export interface ModalTransitionType {
name?: string;
instance?: ModalTransition;
duration?: number;
curve?: any;
}
export interface ShowModalOptions {
/**
* 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.
*/
context: any;
/**
* A function that will be called when the view is closed. Any arguments provided when calling ShownModallyData.closeCallback will be available here.
*/
closeCallback: (...args: any[]) => void;
/**
* An optional parameter specifying whether to show the modal view in full-screen mode.
*/
fullscreen?: boolean;
/**
* An optional parameter specifying whether to show the modal view with animation.
*/
animated?: boolean;
/**
* An optional parameter specifying whether to stretch the modal view when not in full-screen mode.
*/
stretched?: boolean;
/**
* An optional custom transition effect
*/
transition?: ModalTransitionType;
/**
* An optional parameter that specify options specific to iOS as an object.
*/
ios?: {
/**
* The UIModalPresentationStyle to be used when showing the dialog in iOS .
*/
presentationStyle?: any;
/**
* width of the popup dialog
*/
width?: number;
/**
* height of the popup dialog
*/
height?: number;
};
android?: {
/**
* @deprecated Use ShowModalOptions.cancelable instead.
* An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
*/
cancelable?: boolean;
/**
* An optional parameter specifying the windowSoftInputMode of the dialog window.
* For possible values see https://developer.android.com/reference/android/view/WindowManager.LayoutParams#softInputMode
*/
windowSoftInputMode?: number;
};
/**
* An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
*/
cancelable?: boolean;
}
/**
* Gets an ancestor from a given type.
* @param view - Starting view (child view).
* @param criterion - The type of ancestor view we are looking for. Could be a string containing a class name or an actual type.
* Returns an instance of a view (if found), otherwise undefined.
*/
export declare function getAncestor(view: ViewBaseDefinition, criterion: string | {
new (): any;
}): ViewBaseDefinition;
/**
* Gets a child view by id.
* @param view - The parent (container) view of the view to look for.
* @param id - The id of the view to look for.
* Returns an instance of a view (if found), otherwise undefined.
*/
export declare function getViewById(view: ViewBaseDefinition, id: string): ViewBaseDefinition;
/**
* Gets a child view by domId.
* @param view - The parent (container) view of the view to look for.
* @param domId - The id of the view to look for.
* Returns an instance of a view (if found), otherwise undefined.
*/
export declare function getViewByDomId(view: ViewBaseDefinition, domId: number): ViewBaseDefinition;
/**
* Gets a child view by selector.
* @param view - The parent (container) view of the view to look for.
* @param selector - The selector of the view to look for.
* Returns an instance of a view (if found), otherwise undefined.
*/
export declare function querySelectorAll(view: ViewBaseDefinition, selector: string): Array<ViewBaseDefinition>;
/**
* Iterates through all child views (via visual tree) and executes a function.
* @param view - Starting view (parent container).
* @param callback - A function to execute on every child. If function returns false it breaks the iteration.
*/
export declare function eachDescendant(view: ViewBaseDefinition, callback: (child: ViewBaseDefinition) => boolean): void;
declare enum SuspendType {
Incremental = 0,
Loaded = 1048576,
NativeView = 2097152,
UISetup = 4194304,
IncrementalCountMask = -7340033
}
declare namespace SuspendType {
function toString(type: SuspendType): string;
}
export declare abstract class ViewBase extends Observable implements ViewBaseDefinition {
/**
* String value used when hooking to loaded event.
*/
static loadedEvent: string;
/**
* String value used when hooking to unloaded event.
*/
static unloadedEvent: string;
/**
* String value used when hooking to creation event
*/
static createdEvent: string;
/**
* String value used when hooking to disposeNativeView event
*/
static disposeNativeViewEvent: string;
private _onLoadedCalled;
private _onUnloadedCalled;
private _iosView;
private _androidView;
private _style;
private _isLoaded;
private _visualState;
private _templateParent;
private __nativeView;
domNode: dnm.DOMNode;
recycleNativeView: 'always' | 'never' | 'auto';
/**
* returns the native UIViewController.
*/
viewController: any;
bindingContext: any;
/**
* read-only. If you want to set out-of-band the nativeView use the setNativeView method.
*/
nativeViewProtected: any;
/**
* Gets the parent view. This property is read-only.
*/
parent: ViewBase;
/**
* Returns true if visibility is set to 'collapse'.
* Default(false) set in prototype
* Readonly property
*/
isCollapsed: any;
/**
* Gets or sets the id for this view.
*/
id: string;
/**
* Gets or sets the CSS class name for this view.
*/
className: string;
/**
* Gets or sets the shared transition tag for animated view transitions
*/
sharedTransitionTag: string;
/**
* Opt out of shared transition under different binding conditions
*/
sharedTransitionIgnore: boolean;
/**
* Default visual state, defaults to 'normal'
*/
defaultVisualState: string;
_domId: number;
_context: any;
_isAddedToNativeVisualTree: boolean;
_cssState: ssm.CssState;
_styleScope: ssm.StyleScope;
/**
* A property bag holding suspended native updates.
* Native setters that had to execute while there was no native view,
* or the view was detached from the visual tree etc. will accumulate in this object,
* and will be applied when all prerequisites are met.
* @private
*/
_suspendedUpdates: {
[propertyName: string]: Property<ViewBase, any> | CssProperty<Style, any> | CssAnimationProperty<Style, any>;
};
/**
* Determines the depth of suspended updates.
* When the value is 0 the current property updates are not batched nor scoped and must be immediately applied.
* If the value is 1 or greater, the current updates are batched and does not have to provide immediate update.
* Do not set this field, the _batchUpdate method is responsible to keep the count up to date,
* as well as adding/rmoving the view to/from the visual tree.
*/
_suspendNativeUpdatesCount: number;
_isStyleScopeHost: boolean;
_automaticallyAdjustsScrollViewInsets: boolean;
left: CoreTypes.LengthType;
top: CoreTypes.LengthType;
effectiveLeft: number;
effectiveTop: number;
dock: 'left' | 'top' | 'right' | 'bottom';
row: number;
col: number;
column: number;
rowSpan: number;
colSpan: number;
columnSpan: number;
order: Order;
flexGrow: FlexGrow;
flexShrink: FlexShrink;
flexWrapBefore: FlexWrapBefore;
alignSelf: AlignSelf;
_oldLeft: number;
_oldTop: number;
_oldRight: number;
_oldBottom: number;
_ignoreFlexMinWidthHeightReset: boolean;
effectiveMinWidth: number;
effectiveMinHeight: number;
effectiveWidth: number;
effectiveHeight: number;
effectiveMarginTop: number;
effectiveMarginRight: number;
effectiveMarginBottom: number;
effectiveMarginLeft: number;
effectivePaddingTop: number;
effectivePaddingRight: number;
effectivePaddingBottom: number;
effectivePaddingLeft: number;
effectiveBorderTopWidth: number;
effectiveBorderRightWidth: number;
effectiveBorderBottomWidth: number;
effectiveBorderLeftWidth: number;
_defaultPaddingTop: number;
_defaultPaddingRight: number;
_defaultPaddingBottom: number;
_defaultPaddingLeft: number;
_isPaddingRelative: boolean;
/**
* @private
* Module name when the view is a module root. Otherwise, it is undefined.
*/
_moduleName: string;
/**
* Gets or sets if the view is reusable.
* Reusable views are not automatically destroyed when removed from the View tree.
*/
reusable: boolean;
constructor();
/**
* Gets the template parent or the native parent. Sets the template parent.
*/
get parentNode(): ViewBase;
set parentNode(node: ViewBase);
get nativeView(): any;
set nativeView(value: any);
/**
* Gets the name of the constructor function for this instance. E.g. for a Button class this will return "Button".
*/
get typeName(): string;
/**
* Gets the style object associated to this view.
*/
get style(): Style;
set style(inlineStyle: Style);
get android(): any;
get ios(): any;
get isLoaded(): boolean;
get ['class'](): string;
set ['class'](v: string);
/**
* Returns the child view with the specified id.
*/
getViewById<T extends ViewBaseDefinition>(id: string): T;
/**
* Returns the child view with the specified domId.
*/
getViewByDomId<T extends ViewBaseDefinition>(domId: number): T;
/**
* Gets owner page. This is a read-only property.
*/
get page(): Page;
/**
* @unstable
* Ensures a dom-node for this view.
*/
ensureDomNode(): void;
set(name: string, value: any): void;
onLoaded(): void;
onUnloaded(): void;
_layoutParent(): void;
_suspendNativeUpdates(type: SuspendType): void;
_resumeNativeUpdates(type: SuspendType): void;
/**
* Allow multiple updates to be performed on the instance at once.
*/
_batchUpdate<T>(callback: () => T): T;
private setFlag;
private isFlagSet;
private callFunctionWithSuper;
callLoaded(): void;
callUnloaded(): void;
private notifyPseudoClassChanged;
private pseudoClassAliases;
cssClasses: Set<string>;
cssPseudoClasses: Set<string>;
private getAllAliasedStates;
/**
* @protected
* @unstable
* A widget can call this method to add a matching css pseudo class.
*/
addPseudoClass(name: string): void;
/**
* @protected
* @unstable
* A widget can call this method to discard matching css pseudo class.
*/
deletePseudoClass(name: string): void;
private bindingContextChanged;
private bindings;
private shouldAddHandlerToParentBindingContextChanged;
private bindingContextBoundToParentBindingContextChanged;
bind(options: BindingOptions, source?: Object): void;
unbind(property: string): void;
private performLayout;
/**
* Invalidates the layout of the view and triggers a new layout pass.
*/
requestLayout(): void;
/**
* Iterates over children of type ViewBase.
* @param callback Called for each child of type ViewBase. Iteration stops if this method returns falsy value.
*/
eachChild(callback: (child: ViewBase) => boolean): void;
_inheritStyles(view: ViewBase): void;
_addView(view: ViewBase, atIndex?: number): void;
/**
* Method is intended to be overridden by inheritors and used as "protected"
*/
_addViewCore(view: ViewBase, atIndex?: number): void;
/**
* Load view.
* @param view to load.
*/
loadView(view: ViewBase): void;
/**
* When returning true the callLoaded method will be run in setTimeout
* Method is intended to be overridden by inheritors and used as "protected"
*/
_shouldDelayLayout(): boolean;
/**
* Unload view.
* @param view to unload.
*/
unloadView(view: ViewBase): void;
/**
* 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.
*/
_removeView(view: ViewBase): void;
/**
* Method is intended to be overridden by inheritors and used as "protected"
*/
_removeViewCore(view: ViewBase): void;
/**
* Creates a native view.
* Returns either android.view.View or UIView.
*/
createNativeView(): Object;
/**
* Clean up references to the native view.
*/
disposeNativeView(): void;
/**
* Initializes properties/listeners of the native view.
*/
initNativeView(): void;
/**
* Resets properties/listeners set to the native view.
*/
resetNativeView(): void;
private resetNativeViewInternal;
/**
* if _setupAsRootView is called it means it is not supposed to be
* added to a parent. However parent can be set before for the purpose
* of CSS variables/classes. That variable ensures that _addViewToNativeVisualTree
* is not called in _setupAsRootView
*/
mIsRootView: boolean;
_setupAsRootView(context: any): void;
/**
* Setups the UI for ViewBase and all its children recursively.
* This method should *not* be overridden by derived views.
*/
_setupUI(context: any, atIndex?: number, parentIsLoaded?: boolean): void;
/**
* Set the nativeView field performing extra checks and updates to the native properties on the new view.
* Use in cases where the createNativeView is not suitable.
* As an example use in item controls where the native parent view will create the native views for child items.
*/
setNativeView(value: any): void;
/**
* Tears down the UI of a reusable node by making it no longer reusable.
* @see _tearDownUI
* @param forceDestroyChildren Force destroy the children (even if they are reusable)
*/
destroyNode(forceDestroyChildren?: boolean): void;
/**
* Tears down the UI for ViewBase and all its children recursively.
* This method should *not* be overridden by derived views.
*/
_tearDownUI(force?: boolean): void;
_childIndexToNativeChildIndex(index?: number): number;
/**
* 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.
* Method is intended to be overridden by inheritors and used as "protected".
*/
_addViewToNativeVisualTree(view: ViewBase, atIndex?: number): boolean;
/**
* Method is intended to be overridden by inheritors and used as "protected"
*/
_removeViewFromNativeVisualTree(view: ViewBase): void;
get visualState(): string;
_goToVisualState(state: string): void;
/**
* @deprecated
*
* This used to be the way to set attribute values in early {N} versions.
* Now attributes are expected to be set as plain properties on the view instances.
*/
_applyXmlAttribute(attribute: string, value: string): boolean;
setInlineStyle(style: string): void;
_parentChanged(oldParent: ViewBase): void;
onResumeNativeUpdates(): void;
toString(): string;
/**
* @private
* Notifies each child's css state for change, recursively.
* Either the style scope, className or id properties were changed.
*/
_onCssStateChange(): void;
_inheritStyleScope(styleScope: ssm.StyleScope): void;
/**
* Shows the view passed as parameter as a modal view.
* @param view - View instance to be shown modally.
* @param modalOptions - A ShowModalOptions instance
*/
showModal(view: ViewBase, modalOptions?: ShowModalOptions): ViewBase;
/**
* Shows the View contained in moduleName as a modal view.
* @param moduleName - The name of the module to load starting from the application root.
* @param modalOptions - A ShowModalOptions instance
*/
showModal(moduleName: string, modalOptions?: ShowModalOptions): ViewBase;
/**
* Closes the current modal view that this page is showing.
* @param context - Any context you want to pass back to the host when closing the modal view.
*/
closeModal(...args: any[]): void;
/**
* Method is intended to be overridden by inheritors and used as "protected"
*/
_dialogClosed(): void;
/**
* Method is intended to be overridden by inheritors and used as "protected"
*/
_onRootViewReset(): void;
}
export declare const bindingContextProperty: InheritedProperty<ViewBaseDefinition, any>;
export declare const hiddenProperty: Property<ViewBaseDefinition, boolean>;
export declare const classNameProperty: Property<ViewBaseDefinition, string>;
export declare const idProperty: Property<ViewBaseDefinition, string>;
export declare function booleanConverter(v: string | boolean): boolean;
export {};