// Type definitions for Tabris.js 3.8.0
///
// General helper types
export interface Constructor {new(...args: any[]): T; }
type Omit = Pick>;
type ReadOnlyWidgetKeys = T extends {readonly bounds: any}
? Extract
: never;
type MethodKeysOf = { [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
// Tabris.js Helper Types
type JSXDefaultChildren = Flatten;
export type Properties<
T extends {set?: any},
U = Omit // prevent self-reference issues
> = Partial | ReadOnlyWidgetKeys>>
& {cid?: never, data?: any}; // prevent empty object type as possible result, would allow any object
type ListenersKeysOf = { [K in keyof T]: T[K] extends Listeners ? K : never }[keyof T];
export type UnpackListeners = T extends Listeners ? Listener : T;
export type EventOfListeners> = T extends Listeners ? U : never;
type ListenersMap = { [Key in ListenersKeysOf]?: UnpackListeners};
export type JSXShorthands = T extends {layoutData?: LayoutDataValue}
? {center?: true, stretch?: true, stretchX?: true, stretchY?: true}
: {};
export type JSXCandidate = {set: any; jsxAttributes: any}; // JSX.Element?
export type JSXAttributes<
T extends JSXCandidate,
U = Omit // prevent self-reference issues
> = Properties & ListenersMap & JSXShorthands;
/**
* The attributes object for the given widget type, includes all properties,
* events, children and shorthands. To be passed to a JSX element or new-less
* widget constructor call.
*
* The optional second parameter is the type of the "data" property.
*/
export type Attributes = T['jsxAttributes'] & {data?: TData};
export type JSXCompositeAttributes
= JSXAttributes & {apply?: RuleSet, children?: JSXChildren};
type ExtendedEvent = EventObject & EventData;
export type Listener = (ev: ExtendedEvent) => any;
type ListenersTriggerParam = Omit>;
type MinimalEventObject = {target: T};
type TargetType = E extends MinimalEventObject ? Target : object;
export interface Listeners {
// tslint:disable-next-line:callable-types
(listener: Listener>): TargetType;
}
export type JSXChildren = T|WidgetCollection|Array>|{cid?: never}|undefined;
export type SFC = (attributes: object|null, children: any[]) => T;
type Flatten = T|Array|undefined;
export type Factory<
OriginalConstructor extends Constructor & {prototype: Instance},
Instance extends JSXCandidate = InstanceType,
Selector extends Function = (...args: any[]) => Widget
> = {
/**
* Creates an instance of this type.
*
* The given attributes object may include properties,
* event listener and children, if supported.
*
* The second parameter should be given if this is the
* return value of a functional component. In this case the
* component itself (factory function) must be given to make it
* a valid selector for the widget selector API such as
* "$()" or the composite "find()" method.
*/
(attributes?: Attributes, selector?: Selector): Instance
};
export type CallableConstructor<
OriginalConstructor extends Constructor & {prototype: Instance},
Instance extends JSXCandidate = InstanceType,
Selector extends Function = (...args: any[]) => Widget
> = {
/** This constructor can be called as a factory, without "new". Doing so allows passing an attributes object which may include (in addition to the properties) children, event listeners and layout shorthands. */
new (...args: ConstructorParameters): Instance,
/**
* Creates an instance of this type.
*
* The given attributes object may include properties,
* event listener and children, if supported.
*
* The second parameter should be given if this is the
* return value of a functional component. In this case the
* component itself (factory function) must be given to make it
* a valid selector for the widget selector API such as
* "$()" or the composite "find()" method.
*/
(attributes?: Attributes, selector?: Selector): Instance,
prototype: Instance
};
export as namespace tabris;
export type BaseConstructor = Function & { prototype: T };
/**
* A plain object with following properties:
*
* **src**: *string*
* File system path, relative path or URL. The [data URI](https://en.wikipedia.org/wiki/Data_URI_scheme) scheme is also supported. Relative paths are resolved relative to 'package.json'. On Android the name of a bundled [drawable resource](https://developer.android.com/guide/topics/resources/drawable-resource.html) can be provided with the url scheme `android-drawable`, e.g. `android-drawable://ic_info_black`.
*
* **width**: *number | 'auto' (optional)*
* Image width in dip, extracted from the image file when missing or `'auto'`.
*
* **height**: *number | 'auto' (optional)*
* Image height in dip, extracted from the image file when missing or `'auto'`.
*
* **scale**: *number | 'auto' (optional)*
* Image scale factor, the image will be scaled down by this factor. The scale will be inferred from the image file name if it follows the pattern "@\x", e.g. `"image@2x.jpg"`. The pattern is ignored if `scale`, `width` or `height` are set to a number or if `scale` is set to `"auto"`.
*/
export type ImageSource = string | ImageBitmap | Blob;
export type ImageLikeObject = {src: ImageSource, scale?: number | "auto", width?: number | "auto", height?: number | "auto"};
/**
* Images can be specified as strings or Image/ImageLikeObject.
*
* An **Image** instance can be created using the **Image** constructor or using **Image.from**.
*
* The string shorthand `"image.jpg"` equals `{src: "image.jpg"}`.
*
* The scale can be part of the file name in the pattern of "@\x", e.g. `"image@2x.jpg"`. The pattern is ignored if `scale`, `width` or `height` are set to a number or if `scale` is set to `"auto"`.
*/
export type ImageValue = ImageLikeObject | Image | ImageSource | null;
export type ColorArray = [number, number, number, number]|[number, number, number];
export type ColorLikeObject = {red: number, green: number, blue: number, alpha?: number};
/**
* Colors can be specified as strings, arrays or Color/Color-like objects.
*
* A **Color** instance can be created with the **Color** constructor or using **Color.from**.
*
* A **Color**-like object is a plain object with "red", "green", "blue" and optional "alpha" properties.
* Example: **{red: 0, green: 127, blue: 255, alpha: 120}**
*
* A color array has consist of 3 or 4 numbers between (and including) 0 and 255,
* i.e. **[red, green, blue, alpha]**. If omitted, alpha is 255.
*
* As a string the following formats can be used:
* - **"#xxxxxx"**
* - **"#xxx"**
* - **"#xxxxxxxx"**
* - **"#xxxx"**
* - **"rgb(r, g, b)"** with **r**, **g** and **b** being numbers in the range 0..255.
* - **"rgba(r, g, b, a)"** with **a** being a number in the range 0..1.
* - a color name from the CSS3 specification.
* - **"transparent"** sets a fully transparent color. This is a shortcut for **"rgba(0, 0, 0, 0)"**.
* - **"initial"** resets the color to its (platform-dependent) default.
*
* Setting a ColorValue property to null also resets it to the default color.
*
* Type guards for `ColorValue` are available as **Color.isColorValue** and **Color.isValidColorValue**
*/
export type ColorValue = ColorLikeObject | ColorArray | string | 'initial' | null;
export type FontWeight = 'black' | 'bold' | 'medium' | 'thin' | 'light' | 'normal';
export type FontStyle = 'italic' | 'normal';
export type FontLikeObject = {size: number, family?: string[], weight?: FontWeight, style?: FontStyle};
/**
* Fonts can be specified as strings or Font/Font-like objects.
*
* A **Font** instance can be created with the **Font** constructor or using **Font.from**.
*
* A **Font**-like object is a plain object with "size" and optional "family", "weight" and "style" properties.
* Example: **{size: 16, family: ['serif'], weight: 'bold', style: 'italic'}**
*
* Generic font families supported across all platforms are **"serif"**, **"sans-serif"**, **"condensed"** and **"monospace"**.
* Supported font weights are **"light"**, **"thin"**, **"normal"**, **"medium"**, **"bold"** and **"black"**.
*
* As a string, the shorthand syntax known from CSS is used: **"[font-style] [font-weight] font-size [font-family[, font-family]*]"**. The font family may be omitted, in this case the default system font will be used. The value **"initial"** represents the platform default.
*/
export type FontValue = FontLikeObject|string|'initial'|null;
export interface PercentLikeObject {
percent: number;
}
export type PercentString = string;
/**
*
* Percents can be specified as strings or Percent/Percent-like objects.
*
* A **Percent** instance can be created with the **Percent** constructor or using **Percent.from**.
*
* A **Percent**-like object is a plain object with a *percent* property with a number between and including 0 and 100.
*
* A percent string contains a number between and including 0 and 100 and and ends with `%`.
*
*/
export type PercentValue = PercentString | PercentLikeObject;
/**
* Defines how the widget should be arranged. When setting the layout of a widget using **LayoutData**, all currently set layout attributes not in the new LayoutData object will be implicitly reset to null (i.e. "not specified").
*/
export type LayoutDataValue = LayoutDataLikeObject|'center'|'stretch'|'stretchX'|'stretchY';
export interface LayoutDataLikeObject {
left?: 'auto' | ConstraintValue;
right?: 'auto' | ConstraintValue;
top?: 'auto' | ConstraintValue;
bottom?: 'auto' | ConstraintValue;
centerX?: 'auto' | Offset | true;
centerY?: 'auto' | Offset | true;
baseline?: 'auto' | SiblingReferenceValue |true;
width?: 'auto' | Dimension;
height?: 'auto' | Dimension;
}
export interface LayoutDataProperties {
left?: 'auto' | Constraint;
right?: 'auto' | Constraint;
top?: 'auto' | Constraint;
bottom?: 'auto' | Constraint;
centerX?: 'auto' | Offset;
centerY?: 'auto' | Offset;
baseline?: 'auto' | SiblingReference;
width?: 'auto' | Dimension;
height?: 'auto' | Dimension;
}
export type LinearGradientLikeObject = {
colorStops: Array,
direction?: number | 'left' | 'top' | 'right' | 'bottom'
}
/**
* Linear gradients can be specified as strings or [LinearGradient](./LinearGradient.html) or
* `LinearGradient`-like objects.
*
* An `LinearGradient` instance can be created using the `LinearGradient` constructor or using
* `LinearGradient.from`.
*
* A `LinearGradient`-like object is a plain object with "colorStops" and optional "direction"
* properties.
* "colorStops" is an array containing atleast one `ColorValue` or `[ColorValue, PercentValue]`.
* "direction" is a number in degrees or one of "left", "top", "right" and "bottom".
*
* As string, following CSS subset can be used:
*
* ::= [ % ]
* ::= linear-gradient( [ deg | to ( left | top | right | bottom ), ] { , } )
*/
export type LinearGradientValue = LinearGradientLikeObject | string | 'initial' | null;
/**
* A Widget's bounds
*/
export interface Bounds {
/**
* the horizontal offset from the parent's left edge in dip
*/
left: number;
/**
* the vertical offset from the parent's top edge in dip
*/
top: number;
/**
* the width of the widget in dip
*/
width: number;
/**
* the height of the widget in dip
*/
height: number;
}
export interface Transformation {
/**
* Clock-wise rotation in radians. Defaults to \`0\`.
*/
rotation?: number;
/**
* Horizontal scale factor. Defaults to \`1\`.
*/
scaleX?: number;
/**
* Vertical scale factor. Defaults to \`1\`.
*/
scaleY?: number;
/**
* Horizontal translation (shift) in dip. Defaults to \`0\`.
*/
translationX?: number;
/**
* Vertical translation (shift) in dip. Defaults to \`0\`.
*/
translationY?: number;
/**
* Z-axis translation (shift) in dip. Defaults to \`0\`. Android 5.0+ only.
*/
translationZ?: number;
}
export type SelectorString = string;
export type SiblingSelectorString = string;
/**
* An expression or a predicate function to select a set of widgets.
*/
export type Selector<
Candidate extends Widget = Widget,
Result extends Candidate = Candidate
> = SelectorString | SelectorFunction | Constructor | SFC;
export type SelectorFunction = (widget: Candidate, index: number, collection: WidgetCollection) => boolean;
/**
* A positive float, or 0, representing device independent pixels.
*/
export type Dimension = number;
/**
* A positive or negative float, or 0, representing device independent pixels.
*/
export type Offset = number;
export type PrevString = 'prev()';
type NextString = 'next()';
export type SiblingReferenceSymbol = typeof LayoutData.next | typeof LayoutData.prev
export type SiblingReference = Widget | SiblingReferenceSymbol | SiblingSelectorString;
export type SiblingReferenceValue = Widget | SiblingReferenceSymbol | SiblingSelectorString;
export type ConstraintArray = [SiblingReferenceValue | PercentValue, Offset];
export type ConstraintArrayValue = [SiblingReference | PercentValue, Offset];
export type ConstraintLikeObject = {
reference: SiblingReferenceValue | PercentValue;
offset?: Offset;
}|{
reference?: SiblingReferenceValue | PercentValue;
offset: Offset;
};
/**
* Distance to a parent's or sibling's opposing edge in one of these formats:
* - **offset** the distance from the parent's opposing edge in device independent pixels
* - **percentage** the distance from the parent's opposing edge in percent of the parent's width
* - **Widget** attach this edge to the given siblings's opposing edge
* - **"selector"**
* - **"prev()"** Same as above, but as space-separated string list instead of array
* - **"selector offset"**
* - **"prev() offset"**
* - **[Widget, offset]** the distance from the given widget's opposing edge in pixel
* - **"Widget, offset"**Same as above, but as space-separated string list instead of array.
* - **[percentage, offset]** the distance from the parent's opposing edge in percent of the parent's width plus a fixed offset in pixels
* - **"percentage offset"** Same as above, but as space-separated string list instead of array
* - **[selector, offset]**
* - **["prev()", offset]**
*/
export type ConstraintValue = Constraint
| ConstraintArrayValue
| ConstraintLikeObject
| Offset
| PercentValue
| SiblingReferenceValue
| true;
export interface AnimationOptions {
/**
* Time until the animation starts in ms, defaults to 0.
*/
delay?: number;
/**
* Duration of the animation in ms.
*/
duration?: number;
/**
* Easing function applied to the animation.
*/
easing?: "linear"|"ease-in"|"ease-out"|"ease-in-out";
/**
* Number of times to repeat the animation, defaults to 0.
*/
repeat?: number;
/**
* If true, alternates the direction of the animation on every repeat.
*/
reverse?: boolean;
/**
* no effect, but will be given in animation events.
*/
name?: string;
}
/**
* Represents dimensions on four edges of a box, as used for padding.
*/
export type BoxDimensions = number | string | [number, number?, number?, number?] | {
/**
* The left part, in dip.
*/
left?: number;
/**
* The right part, in dip.
*/
right?: number;
/**
* The top part, in dip.
*/
top?: number;
/**
* The bottom part, in dip.
*/
bottom?: number;
}
export interface PropertyChangedEvent extends EventObject{
readonly value: U
originalEvent?: PropertyChangedEvent | null;
}
export class JsxProcessor {
public readonly jsxFactory: Symbol;
public readonly jsxType: Symbol;
createElement(type: {prototype: JSX.ElementClass, new(): object}|string, attributes: object, ...children: Array): JSX.ElementClass | string;
createIntrinsicElement(type: string, attributes: object): JSX.ElementClass | string;
createCustomComponent(type: {prototype: JSX.ElementClass, new(): object}, attributes: object): JSX.ElementClass | string;
createFunctionalComponent(type: ((param: object) => any), attributes: object): JSX.ElementClass | string;
createNativeObject(Type: {prototype: JSX.ElementClass, new(): NativeObject}, attributes: object): NativeObject;
}
export function asFactory<
OriginalConstructor extends Constructor & {prototype: Instance},
Instance extends JSXCandidate = InstanceType
> (constructor: OriginalConstructor): CallableConstructor;
export type ModuleLoader = (
module: Module,
exports: object,
require: (fn: string) => object,
__filename: string,
__dirname: string
) => void;
export type ResourceData, RawType = any> = Record>;
export type ColorResourceData = Record>;
export type FontResourceData = Record>;
export type TextResourceData = Record>;
export type RuleSetObject = ({[selectorOrAttribute: string]: any}) & {prototype?: never};
export type RuleSetStatic = RuleSetObject | Array;
export type RuleSetCallback = ((widget: Target) => RuleSetStatic) | null;
export type RuleSet = RuleSetStatic | RuleSetCallback | null;
export type ApplyAttributes> = ApplyAttributesTypedSetter | ApplyAttributesUntypedSetter | ApplyAttributesRuleSet;
export type ApplyAttributesTypedSetter> = {
target: WidgetConstructor,
selector?: string,
children?: Attributes,
attr?: Attributes
};
export type ApplyAttributesUntypedSetter = {
target?: never,
selector?: string,
children?: Attributes,
attr?: Attributes
};
export type ApplyAttributesRuleSet = {
children?: RuleSet
};
export namespace widgets {
export class ObservableData {
constructor(properties?: Record);
[Symbol.observable](): Observable>;
}
}
export type ObservableData = widgets.ObservableData;
export type ObservableDataConstructor = typeof widgets.ObservableData;
export interface ObservableDataFactory extends ObservableDataConstructor {
(properties?: T): ObservableData & T;
}
export const ObservableData: ObservableDataFactory;
declare var ImageDataConstructor: typeof ImageData;
declare var StorageConstructor: typeof Storage;
declare var WebSocketConstructor: typeof WebSocket;
declare var XMLHttpRequestConstructor: typeof XMLHttpRequest;
declare var CryptoConstructor: typeof Crypto;
declare var cryptoObject: Crypto;
declare var workerConstructor: typeof Worker;
declare var RequestConstructor: typeof Request;
declare var ResponseConstructor: typeof Response;
declare var HeadersConstructor: typeof Headers;
declare var fetchFunction: typeof fetch;
declare var $Function: typeof $;
export {
ImageDataConstructor as ImageData,
StorageConstructor as Storage,
WebSocketConstructor as WebSocket,
XMLHttpRequestConstructor as XMLHttpRequest,
CryptoConstructor as Crypto,
cryptoObject as crypto,
RequestConstructor as Request,
ResponseConstructor as Response,
HeadersConstructor as Headers,
fetchFunction as fetch,
$Function as $,
Setter as Set
};
type ResourcesConstructorOptions = {
data: ResourceRawData,
config?: ResourceConfig,
base?: ResourceBaseData,
validator?: (value: any) => value is RawType,
converter?: (raw: RawType) => ResourceType,
type?: Constructor
};
type ResourceBuildOptions = {
validator: (value: any) => value is ResourceType,
type?: Constructor
} | {
validator?: (value: any) => value is ResourceType,
type: Constructor
};
type ResourceBuildConvertOptions = {
validator?: (value: any) => value is RawType,
converter: (raw: RawType) => ResourceType,
type?: Constructor
};
type ResourceBuilderConstructorOptions = {
validator?: (value: any) => value is RawType,
converter?: (raw: RawType) => ResourceType,
type?: Constructor
};
type ResourceRawData = NeverResources
& Selectable
& Partial>;
type ResourceDataWithConfig = NeverResources
& Selectable
& ResourceInlineConfig;
type ResourceConfig = {
scaleFactor?: ScaleFactor,
fallbackLanguage?: string
};
type ResourceInlineConfig = {
$schema?: string,
$scaleFactor?: ScaleFactor,
$fallbackLanguage?: string
};
type ScaleFactor = 'nearest' | 'higher' | 'lower';
type Selectable = T | {[key: string]: Selectable} | undefined | {inherit: boolean} | {ref: string};
type ResourceBaseData = NeverResources & {readonly [resourceName: string]: ResourceType | undefined};
type NamedResources = {
[T in Exclude]: ResourceType
};
type ReservedResourceKeys = keyof ResourceInlineConfig | keyof NeverResources | 'toString' | 'valueOf' | symbol | number;
// TypeScript does now allow reg-ex checks,
// so these only catch the "worst" cases
type NeverResources = {
_?: never,
'#'?: never,
'!'?: never,
'*'?: never,
'@'?: never,
' '?: never,
'on'?: never
};
// This type needs to be less strict than FontLikeObject to satisfy tsc when using FontResources.from with JSON
type FontResourceValue = {size: number, family?: string[], weight?: string, style?: string} | string;
export type TeardownLogic = Function | {unsubscribe: Function} | void;
export type SubscriptionHandler = (
this: Observable,
subscriber: Subscriber
) => TeardownLogic;
export interface Observer {
next: NextCb;
error: ErrorCb;
complete: CompleteCb;
}
export type NextCb = ((value: T) => void);
export type ErrorCb = ((value: any) => void);
export type CompleteCb = (() => void);
export interface PartialObserver {
next?: (value: T) => any;
error?: (ex: any) => any
complete?: () => any
}
export interface Subscription {
readonly closed: boolean;
unsubscribe: () => void;
}
export interface Subscriber extends Observer {
readonly closed: boolean;
}
declare global {
interface SymbolConstructor {
readonly observable: symbol;
}
}
// Action
export namespace widgets {
/**
* An executable item that is integrated in the application's navigation menu. Add a *select* listener
* to react to action taps.
*/
export class Action extends Widget {
/**
* An executable item that is integrated in the application's navigation menu. Add a *select* listener
* to react to action taps.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* Appends this widget to the given `NavigationView` instance.
* @param parent
*/
appendTo(parent: NavigationView): this;
/**
* Inserts this widget directly after the given Action.
* @param widget
*/
insertAfter(widget: Action): this;
/**
* Inserts this widget directly before the given Action.
* @param widget
*/
insertBefore(widget: Action): this;
/**
* Returns the `NavigationView` the `Action` is hosted in or `null` if it has no parent.
*/
parent(): NavigationView;
/**
* Returns a (possibly empty) collection of all siblings of this widget that match the given selector.
* @param selector A selector expression or a predicate function to filter the results.
*/
siblings(selector?: Selector): WidgetCollection;
/**
* Icon image for the action.
* On iOS the `image` is tinted with the apps default accent color whereas on Android the `image` is
* shown as is. When an action is placed into a `NavigationView`, the `NavigationView` property
* `actionColor` can be used to adjust the action tint color.
*/
image: ImageValue;
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: JSXDefaultChildren};
/**
* Actions with 'default' placement will be visible in the toolbar if enough space is available,
* otherwise moved to the overflow section. Setting the property to 'overflow' makes the action appear
* there exclusively. Lastly, 'navigation' puts the action in the position normally occupied by the
* drawer/back button. When 'navigation' is used, only the `Action` image will be shown. If multiple
* actions have this value only the first one is displayed.
*/
placement: 'default' | 'navigation' | 'overflow';
/**
* The text to be displayed for the action.
* When an action is placed into a `NavigationView`, the `NavigationView` property `actionTextColor` can
* be used to adjust the action title color on Android.
*/
title: string;
/**
* Fired when the action is invoked.
*/
onSelect: Listeners>;
/**
* Fired when the [*image*](#image) property has changed.
*/
onImageChanged: ChangeListeners;
/**
* Fired when the [*placement*](#placement) property has changed.
*/
onPlacementChanged: ChangeListeners;
/**
* Fired when the [*title*](#title) property has changed.
*/
onTitleChanged: ChangeListeners;
}
}
export type Action = widgets.Action;
export type ActionConstructor = typeof widgets.Action;
export interface ActionFactory extends Factory, ActionConstructor {}
export const Action: ActionFactory;
// ActionSheet
export interface ActionSheetCloseEvent
extends EventObject
{
readonly action: ActionSheetItem | null;
readonly index: number | null;
}
export interface ActionSheetSelectEvent
extends EventObject
{
readonly action: ActionSheetItem;
readonly index: number;
}
/**
* A pop up dialog that offers a selection. Is automatically disposed when closed.
*/
export class ActionSheet extends Popup {
/**
* A pop up dialog that offers a selection. Is automatically disposed when closed.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* Makes the given action sheet visible. Meant to be used with inline-JSX. In TypeScript it also casts
* the given JSX element from `any` to an actual ActionSheet.
* @param actionSheet The action sheet to open
*/
static open(actionSheet: ActionSheet): ActionSheet;
/**
* An array of objects describing the actions to be displayed. The entries may be instances of
* `ActionSheetItem` *or plain objects* with some or all of the same properties.
*/
actions: Array<{title: string, image?: ImageValue, style?: 'default'|'cancel'|'destructive'}>;
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: Flatten};
/**
* A descriptive message for the available actions.
*/
message: string;
/**
* The title of the action sheet.
*/
title: string;
/**
* Fired when the action sheet was closed.
*/
onClose: Listeners>;
/**
* Fired when an action was selected. Note: on iOS, tapping outside of an ActionSheet will also fire a
* `select` event. Its parameter will be an index of a button with type `cancel`. This happens despite
* the fact that no button has been pressed.
*/
onSelect: Listeners>;
/**
* Fired when the [*actions*](#actions) property has changed.
*/
onActionsChanged: ChangeListeners;
/**
* Fired when the [*message*](#message) property has changed.
*/
onMessageChanged: ChangeListeners;
/**
* Fired when the [*title*](#title) property has changed.
*/
onTitleChanged: ChangeListeners;
}
// ActionSheetItem
/**
* Describes an entry in an [`ActionSheet`](./ActionSheet.md).
*/
export class ActionSheetItem {
/**
* Describes an entry in an [`ActionSheet`](./ActionSheet.md).
*/
public constructor(properties?: {title: string, image?: ImageValue, style?: 'default'|'cancel'|'destructive'});
readonly [JSX.jsxFactory]: JSX.JsxFactory;
/**
* An image to be displayed for this item in the `ActionSheet`
* @constant
*/
image: ImageValue;
/**
* @constant
*/
readonly jsxAttributes: {title?: string, image?: ImageValue, style?: 'default'|'cancel'|'destructive', children?: JSXDefaultChildren};
/**
* The style of presentation for this item in the `ActionSheet`. With the style `cancel` or
* `destructive` are displayed in a special way.
* Note: On iPad, an action with style `cancel` will not be shown in the ActionSheet as per [Apple's
* design
* approach](https://developer.apple.com/documentation/uikit/windows_and_screens/getting_the_user_s_attention_with_alerts_and_action_sheets).
* If such button is added tapping outside of ActionSheet is equivalent to pressing the `cancel` action
* on iPad. In case of tapping outside an appropriate event will be sent by the native side as if such
* button was pressed
* @constant
*/
style: 'default' | 'cancel' | 'destructive';
/**
* The text to be displayed for this item in the `ActionSheet`.
* @constant
*/
title: string;
}
// ActivityIndicator
export namespace widgets {
/**
* A widget representing a spinning indicator for indeterminate loading / processing time.
*/
export class ActivityIndicator extends Widget {
/**
* A widget representing a spinning indicator for indeterminate loading / processing time.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: JSXDefaultChildren};
/**
* The color of the indicator.
*/
tintColor: ColorValue;
/**
* Fired when the [*tintColor*](#tintColor) property has changed.
*/
onTintColorChanged: ChangeListeners;
}
}
export type ActivityIndicator = widgets.ActivityIndicator;
export type ActivityIndicatorConstructor = typeof widgets.ActivityIndicator;
export interface ActivityIndicatorFactory extends Factory, ActivityIndicatorConstructor {}
export const ActivityIndicator: ActivityIndicatorFactory;
// AlertDialog
export interface AlertDialogCloseEvent
extends EventObject
{
readonly button: 'ok' | 'cancel' | 'neutral' | null;
readonly texts: string[];
}
/**
* An `AlertDialog` represents a native dialog pop-up showing a message and up to three buttons. Is
* automatically disposed when closed.
*/
export class AlertDialog extends Popup {
/**
* An `AlertDialog` represents a native dialog pop-up showing a message and up to three buttons. Is
* automatically disposed when closed.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties>);
/**
* Makes the given alert dialog visible. Meant to be used with inline-JSX. In TypeScript it also casts
* the given JSX element from `any` to an actual AlertDialog.
* @param alertDialog The alert dialog to open
*/
static open(alertDialog: AlertDialog): AlertDialog;
/**
* Creates and opens an alert dialog with one 'OK' button and the given message.
* @param message The message to display
*/
static open(message: string): AlertDialog;
/**
* An object with the texts of the buttons to display. There are up to three buttons: `ok`, `cancel` and
* `neutral`. If no text is given for a button it will not be displayed. Example: `{ok: 'Yes', cancel:
* 'No'}` shows 'Yes' and 'No', but no 'neutral' button.
*/
buttons: {ok?: string, cancel?: string, neutral?: string};
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: Flatten, textInputs?: never};
/**
* The message to display inside the dialog.
*/
message: string;
/**
* A composite that may contain `TextInput` widgets to be displayed alongside the `title` and `message`.
* The text values inserted by the user can be read in the dialogs `close` event via its `texts`
* property. Eg.: `dialog.on('close', (e) => e.texts[0])`
* In an AlertDialog JSX element the TextInput widgets may be given as child elements.
* @constant
*/
readonly textInputs: ContentView;
/**
* The title of the dialog.
*/
title: string;
/**
* Fired when the dialog was closed for any reason.
*/
onClose: Listeners>;
/**
* Fired when the dialog was closed by pressing the 'cancel' button.
*/
onCloseCancel: Listeners>;
/**
* Fired when the dialog was closed by pressing the 'neutral' button.
*/
onCloseNeutral: Listeners>;
/**
* Fired when the dialog was closed by pressing the 'ok' button.
*/
onCloseOk: Listeners>;
/**
* Fired when the [*buttons*](#buttons) property has changed.
*/
onButtonsChanged: ChangeListeners;
/**
* Fired when the [*message*](#message) property has changed.
*/
onMessageChanged: ChangeListeners;
/**
* Fired when the [*title*](#title) property has changed.
*/
onTitleChanged: ChangeListeners;
}
// Button
export namespace widgets {
/**
* A push button. Can contain a text or an image.
*/
export class Button extends Widget {
/**
* A push button. Can contain a text or an image.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* The horizontal alignment of the button text.
*/
alignment: 'centerX' | 'left' | 'right';
/**
* Control how the button text is capitalized.
* * `'default'` - The platform decides on the capitalization
* * `'none'` - The text is displayed unaltered
* * `'all'` - Every letter is capitalized
*/
autoCapitalize: 'default' | 'none' | 'all';
/**
* The font used for the button text.
*/
font: FontValue;
/**
* An image to be displayed on the button.
*/
image: ImageValue;
/**
* A color to change the `image` appearance. All opaque parts of the image will be tinted with the given
* color. Set to `initial` to remove the effect.
*/
imageTintColor: ColorValue;
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: Flatten};
/**
* Controls the line width of a button with the `style` _outline_.
*/
strokeColor: ColorValue;
/**
* Controls the line color of a button with the `style` _outline_. Uses a platform-specific default if
* set to `null`.
*/
strokeWidth: number | null;
/**
* The `style` controls the appearance of a `Button` and has to be provided in its constructor. The
* `default` style creates a platform specific button, which is flat on iOS and has an elevation and
* shadow on Android. In addition the following specific style values can be used:
* - `elevate` A button with a platform specific background color, elevation and a surrounding drop
* shadow. Only supported on Android
* - `flat` A button with no elevation and a platform specific background color
* - `outline` A button with a transparent background and an outline stroke which can be controlled via
* the properties `strokeWidth` and `strokeColor`
* - `text` A button with no background and only consisting of its text label.
* @constant
*/
style: 'default' | 'elevate' | 'flat' | 'outline' | 'text';
/**
* The button's label text.
*/
text: string;
/**
* The color of the text.
*/
textColor: ColorValue;
/**
* Fired when the button is pressed.
*/
onSelect: Listeners>;
/**
* Fired when the [*alignment*](#alignment) property has changed.
*/
onAlignmentChanged: ChangeListeners;
/**
* Fired when the [*autoCapitalize*](#autoCapitalize) property has changed.
*/
onAutoCapitalizeChanged: ChangeListeners;
/**
* Fired when the [*font*](#font) property has changed.
*/
onFontChanged: ChangeListeners;
/**
* Fired when the [*image*](#image) property has changed.
*/
onImageChanged: ChangeListeners;
/**
* Fired when the [*imageTintColor*](#imageTintColor) property has changed.
*/
onImageTintColorChanged: ChangeListeners;
/**
* Fired when the [*strokeColor*](#strokeColor) property has changed.
*/
onStrokeColorChanged: ChangeListeners;
/**
* Fired when the [*strokeWidth*](#strokeWidth) property has changed.
*/
onStrokeWidthChanged: ChangeListeners;
/**
* Fired when the [*text*](#text) property has changed.
*/
onTextChanged: ChangeListeners;
/**
* Fired when the [*textColor*](#textColor) property has changed.
*/
onTextColorChanged: ChangeListeners;
}
}
export type Button = widgets.Button;
export type ButtonConstructor = typeof widgets.Button;
export interface ButtonFactory extends Factory, ButtonConstructor {}
export const Button: ButtonFactory;
// Camera
/**
* A `Camera` provides access to the device's camera. The `Camera` can be used as a source for a
* `CameraView` to display a live preview feed or to capture a photo.
* In order to capture an image or to show a camera preview image the app has to have the
* [`'camera'`](../permissions.md#category-camera) [permission](./permission.md).
*/
export class Camera extends NativeObject {
/**
* A `Camera` provides access to the device's camera. The `Camera` can be used as a source for a
* `CameraView` to display a live preview feed or to capture a photo.
* In order to capture an image or to show a camera preview image the app has to have the
* [`'camera'`](../permissions.md#category-camera) [permission](./permission.md).
*/
private constructor();
/**
* Captures an image and returns a result object when the returned promise resolves successfully. The
* `Camera` has to be in an `active` state to capture an image. The result object has an `image`
* property of type `Blob` which contains the jpg encoded image, as well as a `width` and `height`
* property describing the dimensions of the captured image.
* @param options A set of capture options to apply when taking a picture. If `flash` is set to `'auto'` the device will decide (based on the lighting conditions) whether to activate the flashlight.
*/
captureImage(options?: {flash?: 'auto' | 'on' | 'off'}): Promise<{image: Blob, width: number, height: number}>;
/**
* Setting `active` to true activates the camera. If it is currently assigned to a `CameraView`, the
* `CameraView` will now show the video feed from the `Camera`. It is then possible to capture an image
* via the `captureImage()` method.
* Setting `active` to false stops the camera and disables any video feed shown on a `CameraView`.
* It is recommended to stop the `Camera` when not in use in order to preserve battery life.
*/
active: boolean;
/**
* An array of resolutions supported by the camera. Each array entry is an object consisting of `width`
* and `height`. Eg.: `{width: 4000, height: 3000}
*/
readonly availableCaptureResolutions: Array<{width: number, height: number}>;
/**
* The id of the device camera given by the native platform.
* @constant
*/
readonly cameraId: string;
/**
* An object determining the pixel dimensions of the captured image. Has to be an object containing
* `width` and `height` properties of type `number`. The list of natively available resolutions can be
* obtained from the `availableCaptureResolutions` property.
* If the given `captureResolution` is not in the list of `availableCaptureResolutions`, a closely
* matching resolution larger than the given resolution is used. When no `captureResolution` is given
* (value is `null`), the best possible match for the device is chosen automatically. The physical
* dimensions of the captured image should be checked on the resolved result object of the
* `captureImage()` method.
* When setting the `captureResolution` on the iOS platform, a small grace period should pass before
* capturing an image. Otherwise the image might turn out incorrectly exposed.
*/
captureResolution: {width: number, height: number};
/**
* The position of the camera on the device. The `external` position is used for devices like usb
* cameras.
* @constant
*/
readonly position: 'front' | 'back' | 'external';
/**
* Fired when the [*active*](#active) property has changed.
*/
onActiveChanged: ChangeListeners;
/**
* Fired when the [*availableCaptureResolutions*](#availableCaptureResolutions) property has changed.
*/
onAvailableCaptureResolutionsChanged: ChangeListeners;
/**
* Fired when the [*captureResolution*](#captureResolution) property has changed.
*/
onCaptureResolutionChanged: ChangeListeners;
}
// CameraView
export namespace widgets {
/**
* A widget to preview a `Camera` feed.
* In order to show a camera preview image the app has to hold the `'camera'` permission.
*/
export class CameraView extends Widget {
/**
* A widget to preview a `Camera` feed.
* In order to show a camera preview image the app has to hold the `'camera'` permission.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* The source video feed to display. In order to show a preview the `Camera` has to be in an active
* state. When the `Camera` is inactive or no `Camera` is assigned the `CameraView` shows a blank
* screen.
* It is recommended to deactivate the `Camera` when not in use in order to preserve battery life.
*/
camera: Camera;
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: JSXDefaultChildren};
/**
* How to scale the camera preview image.
* - `fit` will scale the image proportionally to fit into the view, possible leaving some empty space
* at the edges. That is, the image will be displayed as large as possible while being fully contained
* in the view.
* - `fill` will scale the image proportionally to fill the entire view, possibly cutting off parts of
* the image. That is, the image will be displayed as small as possible while covering the entire view.
*/
scaleMode: 'fit' | 'fill';
/**
* Fired when the [*camera*](#camera) property has changed.
*/
onCameraChanged: ChangeListeners;
/**
* Fired when the [*scaleMode*](#scaleMode) property has changed.
*/
onScaleModeChanged: ChangeListeners;
}
}
export type CameraView = widgets.CameraView;
export type CameraViewConstructor = typeof widgets.CameraView;
export interface CameraViewFactory extends Factory, CameraViewConstructor {}
export const CameraView: CameraViewFactory;
// Canvas
export namespace widgets {
/**
* Canvas is a widget that can be used to draw graphics using a [canvas context](./CanvasContext.md).
*/
export class Canvas extends Composite {
/**
* Canvas is a widget that can be used to draw graphics using a [canvas context](./CanvasContext.md).
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* Returns the drawing context with the given size.
* @param contextType The context identifier. Only `"2d"` is supported.
* @param width the width of the canvas context to create
* @param height the height of the canvas context to create
*/
getContext(contextType: string, width: number, height: number): CanvasContext;
/**
* Creates a Blob object representing the image contained in the canvas. This is a non-blocking
* operation.
* @param callback Callback that will be called with the resulting blob.
* @param mimeType The expected image format. If `mimeType` is not specified or invalid, the image type is `image/png`. **On iOS the type `image/webp` is not supported. A png will be returned instead.**
* @param quality A Number between 0 and 1 specifying the image quality. A lower number results in a smaller file size at the same resolution. If `quality` is not specified or invalid the value `0.92` is for `image/jpeg` and `0.80` for `image/webp` respectively. The value has no effect for `image/png`.
*/
toBlob(callback: ((blob:Blob) => void), mimeType?: 'image/png' | 'image/jpeg' | 'image/webp', quality?: number): void;
}
}
export type Canvas = widgets.Canvas;
export type CanvasConstructor = typeof widgets.Canvas;
export interface CanvasFactory extends Factory, CanvasConstructor {}
export const Canvas: CanvasFactory;
// CanvasContext
/**
* The CanvasContext is used for drawing onto the [canvas](./Canvas.md). It is a subset of the HTML5
* [CanvasRenderingContext2D](https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D).
*/
export class CanvasContext {
/**
* The CanvasContext is used for drawing onto the [canvas](./Canvas.md). It is a subset of the HTML5
* [CanvasRenderingContext2D](https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D).
*/
private constructor();
/**
* Adds an arc to the path which is centered at *(x, y)* position with radius *r* starting at
* *startAngle* and ending at *endAngle* going in the given direction by *anticlockwise* (defaulting to
* clockwise).
* @param x The x coordinate of the arc's center.
* @param y The y coordinate of the arc's center.
* @param radius The arc's radius.
* @param startAngle The angle in radians at which the arc starts, measured clockwise from the positive x axis.
* @param endAngle The angle in radians at which the arc ends, measured clockwise from the positive x axis.
* @param anticlockwise if true, causes the arc to be drawn counter-clockwise between the two angles.
*/
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
/**
* Starts a new path by emptying the list of sub-paths.
*/
beginPath(): void;
/**
* Adds a cubic Bézier curve to the path. The starting point is the last point in the current path.
* @param cp1x The x axis of the coordinate for the first control point.
* @param cp1y The y axis of the coordinate for the first control point.
* @param cp2x The x axis of the coordinate for the second control point.
* @param cp2y The y axis of the coordinate for the second control point.
* @param x The x axis of the coordinate for the end point.
* @param y The y axis of the coordinate for the end point.
*/
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
/**
* Sets all pixels in the rectangle defined by starting point *(x, y)* and size *(width, height)* to
* transparent, erasing any previously drawn content.
* @param x The x axis of the rectangle's upper-left corner.
* @param y The y axis of the rectangle's upper-left corner.
* @param width The rectangle's width.
* @param height The rectangles height.
*/
clearRect(x: number, y: number, width: number, height: number): void;
/**
* Adds a straight line from the current point to the start of the current sub-path.
*/
closePath(): void;
/**
* creates a new, blank ImageData object with the specified dimensions. All of the pixels in the new
* object are transparent black.
* @param width The width of the new ImageData object.
* @param height The height of the new ImageData object.
*/
createImageData(width: number, height: number): ImageData;
/**
* creates a new, blank ImageData object with the same dimensions as the specified existing ImageData
* object. All of the pixels in the new object are transparent black.
* @param imageData An existing ImageData object from which to copy the width and height.
*/
createImageData(imageData: ImageData): ImageData;
/**
* Draws the entire given ImageBitmap at the given coordinates (dx, dy) in its natural size.
* @param image An ImageBitmap object that has not been closed yet.
* @param dx Destination x-coordinate of the upper-left corner of the image
* @param dy Destination y-coordinate of the upper-left corner of the image
*/
drawImage(image: ImageBitmap, dx: number, dy: number): void;
/**
* Draws the entire given ImageBitmap at the given coordinates (dx, dy) in the given dimension (dWidth,
* dHeight).
* @param image An ImageBitmap object that has not been closed yet.
* @param dx Destination x-coordinate of the upper-left corner of the image
* @param dy Destination y-coordinate of the upper-left corner of the image
* @param dWidth Destination width of the image
* @param dHeight Destination height of the image
*/
drawImage(image: ImageBitmap, dx: number, dy: number, dWidth: number, dHeight: number): void;
/**
* Draws a section (sx, sy, sWidth, sHeight) of the given ImageBitmap at the given coordinates (dx, dy)
* in the given dimension (dWidth, dHeight).
* @param image An ImageBitmap object that has not been closed yet.
* @param sx Source x-coordinate of the upper-left corner of the image
* @param sy Source y-coordinate of the upper-left corner of the image
* @param sWidth Source width of the image
* @param sHeight Source height of the image
* @param dx Destination x-coordinate of the upper-left corner of the image
* @param dy Destination y-coordinate of the upper-left corner of the image
* @param dWidth Destination width of the image
* @param dHeight Destination height of the image
*/
drawImage(image: ImageBitmap, sx: number, sy: number, sWidth: number, sHeight: number, dx: number, dy: number, dWidth: number, dHeight: number): void;
/**
* Fills the current or path with the current fill style.
*/
fill(): void;
/**
* draws a filled rectangle at *(x, y)* position whose size is determined by *width* and *height*. and
* whose color is determined by the fillStyle attribute.
* @param x The x axis of the rectangle's upper-left corner.
* @param y The y axis of the rectangle's upper-left corner.
* @param width The rectangle's width.
* @param height The rectangles height.
*/
fillRect(x: number, y: number, width: number, height: number): void;
/**
* Fills a given text at the given *(x, y)* position using the current *textAlign* and *textBaseline*
* values.
* @param text The text to render.
* @param x The x axis of the coordinate for the text starting point.
* @param y The y axis of the coordinate for the text starting point.
*/
fillText(text: string, x: number, y: number): void;
/**
* Returns an ImageData object representing the underlying pixel data for the area of the canvas denoted
* by the given rectangle.
* @param x The x axis of the rectangle's upper-left corner.
* @param y The y axis of the rectangle's upper-left corner.
* @param width The rectangle's width.
* @param height The rectangle's height.
*/
getImageData(x: number, y: number, width: number, height: number): ImageData;
/**
* Connects the last point in the sub-path to the *(x, y)* coordinates with a straight line.
* @param x The x axis of the coordinate for the end of the line.
* @param y The y axis of the coordinate for the end of the line.
*/
lineTo(x: number, y: number): void;
/**
* Moves the starting point of a new sub-path to the *(x, y)* coordinates.
* @param x The x axis of the point.
* @param y The y axis of the point.
*/
moveTo(x: number, y: number): void;
/**
* Paints data from the given ImageData object onto the bitmap at coordinates (x, y).
* @param imageData An ImageData object containing the array of pixel values.
* @param x x-coordinate of the upper-left corner of the image data rectangle
* @param y y-coordinate of the upper-left corner of the image data rectangle
*/
putImageData(imageData: ImageData, x: number, y: number): void;
/**
* Adds a quadratic Bézier curve to the path. The starting point is the last point in the current path.
* @param cpx The x axis of the coordinate for the control point.
* @param cpy The y axis of the coordinate for the control point.
* @param x The x axis of the coordinate for the end point.
* @param y The y axis of the coordinate for the end point.
*/
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
/**
* Creates a path for a rectangle with the top-left corner at *(x, y)*
* @param x The x axis of the rectangle's upper-left corner.
* @param y The y axis of the rectangle's upper-left corner.
* @param width The rectangle's width.
* @param height The rectangles height.
*/
rect(x: number, y: number, width: number, height: number): void;
/**
* Restores the most recently saved canvas state by popping the top entry in the drawing state stack.
*/
restore(): void;
/**
* Adds a rotation to the transformation matrix.
* @param angle The angle to rotate clockwise in radians.
*/
rotate(angle: number): void;
/**
* Saves the entire state of the canvas by pushing the current state onto a stack.
*/
save(): void;
/**
* Adds a scaling transformation to the canvas units by x horizontally and by y vertically.
* @param x Scaling factor in the horizontal direction.
* @param y Scaling factor in the vertical direction.
*/
scale(x: number, y: number): void;
/**
* resets (overrides) the current transformation to the identity matrix and then invokes a
* transformation described by the arguments of this method. The matrix has the following format:
* [[a, c, e],
* [b, d, f],
* [0, 0, 1]]
* @param a Horizontal scaling.
* @param b Horizontal skewing.
* @param c Vertical skewing.
* @param d Vertical scaling.
* @param e Horizontal moving.
* @param f Vertical moving.
*/
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
/**
* Strokes the current path with the current stroke style.
*/
stroke(): void;
/**
* draws the outline of a rectangle at *(x, y)* position whose size is determined by *width* and
* *height* using the current stroke style.
* @param x The x axis of the rectangle's upper-left corner.
* @param y The y axis of the rectangle's upper-left corner.
* @param width The rectangle's width.
* @param height The rectangles height.
*/
strokeRect(x: number, y: number, width: number, height: number): void;
/**
* Strokes a given text at the given *(x, y)* position using the current *textAlign* and *textBaseline*
* values.
* @param text The text to render.
* @param x The x axis of the coordinate for the text starting point.
* @param y The y axis of the coordinate for the text starting point.
*/
strokeText(text: string, x: number, y: number): void;
/**
* Multiplies the current transformation with the matrix described by the arguments of this method. The
* matrix has the following format:
* [[a, c, e],
* [b, d, f],
* [0, 0, 1]]
* @param a Horizontal scaling.
* @param b Horizontal skewing.
* @param c Vertical skewing.
* @param d Vertical scaling.
* @param e Horizontal moving.
* @param f Vertical moving.
*/
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
/**
* Adds a translation transformation by moving the canvas and its origin *x* horizontally and *y*
* vertically on the grid.
* @param x The distance to move in the horizontal direction.
* @param y The distance to move in the vertical direction.
*/
translate(x: number, y: number): void;
/**
* Specifies the color to use inside shapes.
*/
fillStyle: ColorValue;
/**
* Specifies the current text style being used when drawing text.
*/
font: FontValue;
/**
* Determines how the end points of every line are drawn.
*/
lineCap: 'butt' | 'round' | 'square';
/**
* Determines how two connecting segments in a shape are joined together.
*/
lineJoin: 'bevel' | 'miter' | 'round';
/**
* The thickness of lines in space units.
*/
lineWidth: number;
/**
* Specifies the color to use for the lines around shapes.
*/
strokeStyle: ColorValue;
/**
* Specifies the current text alignment being used when drawing text.
*/
textAlign: 'center' | 'end' | 'left' | 'right' | 'start';
/**
* Specifies the current text baseline being used when drawing text.
*/
textBaseline: 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top';
}
// ChangeListeners
/**
* Represents a collection of listeners for a property change event. Differs from its superclass in the
* constructor signature and the additional [`values`](#values) property.
*/
export class ChangeListeners extends Listeners> {
/**
* Represents a collection of listeners for a property change event. Differs from its superclass in the
* constructor signature and the additional [`values`](#values) property.
*/
public constructor(target: Target, property: Property);
/**
* An observable instance that directly provides the changed values instead of the event object. Also,
* the current value will be emitted immediately upon subscription. Completes when the target is
* disposed.
* @constant
*/
readonly values: Observable;
}
// CheckBox
export interface CheckBoxSelectEvent
extends EventObject
{
readonly checked: boolean;
}
export namespace widgets {
/**
* A check box widget.
*/
export class CheckBox extends Widget {
/**
* A check box widget.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
/**
* The checked state of the check box.
*/
checked: boolean;
/**
* The color of the selectable area in checked state. Will fall back to `tintColor` if not set.
*/
checkedTintColor: ColorValue;
/**
* The font used for the text.
*/
font: FontValue;
/**
* @constant
*/
readonly jsxAttributes: JSXAttributes & {children?: JSXDefaultChildren};
/**
* The label text of the check box.
*/
text: string;
/**
* The color of the text.
*/
textColor: ColorValue;
/**
* The color of the selectable area.
*/
tintColor: ColorValue;
/**
* Fired when the check box is checked or unchecked by the user.
*/
onSelect: Listeners>;
/**
* Fired when the [*checked*](#checked) property has changed.
*/
onCheckedChanged: ChangeListeners;
/**
* Fired when the [*checkedTintColor*](#checkedTintColor) property has changed.
*/
onCheckedTintColorChanged: ChangeListeners;
/**
* Fired when the [*font*](#font) property has changed.
*/
onFontChanged: ChangeListeners;
/**
* Fired when the [*text*](#text) property has changed.
*/
onTextChanged: ChangeListeners;
/**
* Fired when the [*textColor*](#textColor) property has changed.
*/
onTextColorChanged: ChangeListeners;
/**
* Fired when the [*tintColor*](#tintColor) property has changed.
*/
onTintColorChanged: ChangeListeners;
}
}
export type CheckBox = widgets.CheckBox;
export type CheckBoxConstructor = typeof widgets.CheckBox;
export interface CheckBoxFactory extends Factory, CheckBoxConstructor {}
export const CheckBox: CheckBoxFactory;
// CollectionView
export interface CollectionViewScrollEvent
extends EventObject
{
readonly deltaX: number;
readonly deltaY: number;
}
export namespace widgets {
/**
* A scrollable list that displays data items in cells, one per row. Cells are created on demand by the
* *createCell* callback and reused on scrolling.
*/
export class CollectionView extends Composite {
/**
* A scrollable list that displays data items in cells, one per row. Cells are created on demand by the
* *createCell* callback and reused on scrolling.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties, 'firstVisibleIndex' | 'lastVisibleIndex'>> & Partial, 'cellHeight' | 'cellType' | 'createCell' | 'updateCell'>>);
/**
* Returns the cell currently associated with the given item index. Returns `null` if the item is not
* currently displayed.
* @param itemIndex The index of the item as given in `updateCell`.
*/
cellByItemIndex(itemIndex: number): CellWidgetType | null;
/**
* Inserts one or more items at the given index. When no *count* is specified, a single item will be
* added at the given *index*. New cells may be created if needed. The `updateCell` callback will only
* be called for those new items that become immediately visible. Note that inserting new items changes
* the index of all subsequent items. This operation will update the `itemCount` property.
* @param index
* @param count The position to insert the items at. A negative index is interpreted as relative to the end. If the given index is greater than the item count, new items will be appended at the end.
*/
insert(index: number, count?: number): void;
/**
* Determines the item index currently associated with the given cell.
* @param widget A widget instance created by `createCell`, or a child of that widget.
*/
itemIndex(widget: Widget): number;
/**
* Loads a new model with the given *itemCount*. This operation will update the `itemCount` property.
* @param itemCount The number of items in the model to load.
*/
load(itemCount: number): void;
/**
* Triggers an update of the item at the given *index* by calling the `updateCell` callback of the
* corresponding. If no *index* is given, all visible items will be updated.
* @param index The index of the item that was changed.
*/
refresh(index?: number): void;
/**
* Removes one or more items beginning with the given index. When no *count* is given, only the item at
* *index* will be removed. Note that this changes the index of all subsequent items, however. This
* operation will update the `itemCount` property.
* @param index The index of the first item to remove. A negative value is interpreted as relative to the end.
* @param count The number of items to remove.
*/
remove(index: number, count?: number): void;
/**
* Scrolls the item with the given index into view.
* @param index The index of the item to reveal. If this is negative, it is interpreted as relative to the end
* @param options An additional object to control the animation.
- `animate` allows to scroll to an item in an animated fashion. The `animate` property defaults to `true` when no options object is given.
- `offset` shifts the targeted scroll position by a device independent pixel value. When `offset` is used the targeted reveal scroll position will start from the top of the `CollectionView`. Applying `offset` will perform the `reveal()` operation without an animation, ignoring the `animate` property.
*/
reveal(index: number, options?: {animate?: boolean, offset?: number}): void;
/**
* Sets all key-value pairs in the properties object as widget properties.
* **Important TypeScript note:** When called on `this` you may need to specify your custom type like
* this: `this.set({propA: valueA});`
* @param properties
*/
set(properties: Properties & Partial>): this;
/**
* The height of a collection cell. If set to `'auto'`, the cell height will be calculated individually
* for each cell. If set to a function, this function will be called for every item, providing the item
* index and the cell type as parameters, and must return the cell height for the given item.
* Note: On iOS `"auto"` may cause significant performance downgrade as it requires additional layouting
* passes to calculate cell height internally. If possible please use a combination of fixed
* `itemHeight` and `cellType` properties to specify different height for different cells.
*/
cellHeight: number | 'auto' | ((index:number, cellType:string) => number | 'auto');
/**
* The name of the cell type to use for the item at the given index. This name will be passed to the
* `createCell` and `cellHeight` callbacks. Cells will be reused only for those items that map to the
* same cell type. If set to a function, this function will be called for every item, providing the item
* index as a parameter, and must return a unique name for the cell type to use for the given item.
*/
cellType: string | ((index:number) => string) | null;
/**
* The number of columns to display in the collection view. If set to a value `n > 1`, each row will
* contain `n` items. The available space will be equally distributed between columns.
*/
columnCount: number;
/**
* A callback used to create a new reusable cell widget for a given type. This callback will be called
* by the framework and the created cell will be reused for different items. The created widget should
* be populated in the `updateCell` function.
*/
createCell: ((cellType:string) => CellWidgetType);
/**
* Enables the fast scroll thumb that can be dragged to quickly scroll through the list of items. The
* feature is enabled by default in iOS devices starting from version 13 and cannot be disabled anymore.
*/
fastScroll: boolean;
/**
* The index of the first item that is currently visible on screen.
*/
readonly firstVisibleIndex: number;
/**
* The number of items to display. To add or remove items later, use the methods `insert()` and
* `remove()` instead of setting the `itemCount`. To display a new list of items, use the `load()`
* method.
*/
itemCount: number;
/**
* @constant
*/
readonly jsxAttributes: JSXCompositeAttributes & Partial> & Partial> ;
/**
* The index of the last item that is currently visible on screen.
*/
readonly lastVisibleIndex: number;
/**
* Enables the user to trigger a refresh by using the pull-to-refresh gesture.
*/
refreshEnabled: boolean;
/**
* Whether the refresh indicator is currently visible. Will be set to `true` when a *refresh* event is
* triggered. Reset it to `false` when the refresh is finished.
*/
refreshIndicator: boolean;
/**
* The message text displayed together with the refresh indicator.
*/
refreshMessage: string;
/**
* Allows to show or hide the scroll bar. When the scroll bar is hidden, it will be briefly visible
* while scrolling.
*/
scrollbarVisible: boolean;
/**
* A callback used to update a given cell widget to display the item with the given index. This callback
* will be called by the framework.
*/
updateCell: ((cell:CellWidgetType, index:number) => void);
/**
* Fired when the user requested a refresh. An event listener should reset the *refreshIndicator*
* property when refresh is finished.
*/
onRefresh: Listeners>;
/**
* Fired while the collection view is scrolling.
*/
onScroll: Listeners>;
/**
* Fired when the [*cellHeight*](#cellHeight) property has changed.
*/
onCellHeightChanged: ChangeListeners;
/**
* Fired when the [*cellType*](#cellType) property has changed.
*/
onCellTypeChanged: ChangeListeners;
/**
* Fired when the [*columnCount*](#columnCount) property has changed.
*/
onColumnCountChanged: ChangeListeners;
/**
* Fired when the [*createCell*](#createCell) property has changed.
*/
onCreateCellChanged: ChangeListeners;
/**
* Fired when the [*fastScroll*](#fastScroll) property has changed.
*/
onFastScrollChanged: ChangeListeners;
/**
* Fired when the [*firstVisibleIndex*](#firstVisibleIndex) property has changed.
*/
onFirstVisibleIndexChanged: ChangeListeners;
/**
* Fired when the [*itemCount*](#itemCount) property has changed.
*/
onItemCountChanged: ChangeListeners;
/**
* Fired when the [*lastVisibleIndex*](#lastVisibleIndex) property has changed.
*/
onLastVisibleIndexChanged: ChangeListeners;
/**
* Fired when the [*refreshEnabled*](#refreshEnabled) property has changed.
*/
onRefreshEnabledChanged: ChangeListeners;
/**
* Fired when the [*refreshIndicator*](#refreshIndicator) property has changed.
*/
onRefreshIndicatorChanged: ChangeListeners;
/**
* Fired when the [*refreshMessage*](#refreshMessage) property has changed.
*/
onRefreshMessageChanged: ChangeListeners;
/**
* Fired when the [*scrollbarVisible*](#scrollbarVisible) property has changed.
*/
onScrollbarVisibleChanged: ChangeListeners;
/**
* Fired when the [*updateCell*](#updateCell) property has changed.
*/
onUpdateCellChanged: ChangeListeners;
}
}
export type CollectionView = widgets.CollectionView;
export type CollectionViewConstructor = typeof widgets.CollectionView;
export interface CollectionViewFactory extends Factory, CollectionViewConstructor {}
export const CollectionView: CollectionViewFactory;
// Color
/**
* Represents a color. See also ${doc:ColorValue}
*/
export class Color {
/**
* Represents a color. See also ${doc:ColorValue}
*/
public constructor(red: number, green: number, blue: number, alpha?: number);
/**
* Tests if the given value is a `Color` instance that is deeply equal to this one.
* @param value
*/
equals(value: Color): boolean;
/**
* Returns a array representation of the color in the format of `[red, green, blue, alpha]`. Each value
* is a number between (and in including) 0 and 255.
*/
toArray(): [number, number, number, number];
/**
* Returns a string representation of the color. Is either in `rgb(red, green, blue)` or `rgba(red,
* green, blue, alpha)` format. Note that alpha is a value between 0 and 1 in the string representation,
* but between 0 and 255 on the Color object.
*/
toString(): string;
/**
* Creates a new instance of Color using any valid color expression. For any other value, including
* `null` and `'initial'` the method throws.
* @param colorValue The value to create a Color instance from
*/
static from(colorValue: ColorValue): Color;
/**
* Returns true if value is a ColorValue. This includes `null` and `'initial'`. Use this to check if a
* value will be accepted by a color property. This is also a valid TypeScript type guard function.
* @param value The value to test
*/
static isColorValue(value: any): value is ColorValue;
/**
* Returns true if value is a valid ColorValue. This excludes `null` and `'initial'`. Use this to check
* if a value will be accepted by Color.from. This is also a valid TypeScript type guard function.
* @param value The value to test
*/
static isValidColorValue(value: any): value is ColorValue;
/**
* A number between and including 0 and 255
* @constant
*/
readonly alpha: number;
/**
* A number between and including 0 and 255
* @constant
*/
readonly blue: number;
/**
* A number between and including 0 and 255
* @constant
*/
readonly green: number;
/**
* A number between and including 0 and 255
* @constant
*/
readonly red: number;
/**
* @constant
*/
static readonly aqua: Color;
/**
* @constant
*/
static readonly black: Color;
/**
* @constant
*/
static readonly blue: Color;
/**
* @constant
*/
static readonly fuchsia: Color;
/**
* @constant
*/
static readonly gray: Color;
/**
* @constant
*/
static readonly green: Color;
/**
* @constant
*/
static readonly lime: Color;
/**
* @constant
*/
static readonly maroon: Color;
/**
* @constant
*/
static readonly navy: Color;
/**
* @constant
*/
static readonly olive: Color;
/**
* @constant
*/
static readonly purple: Color;
/**
* @constant
*/
static readonly red: Color;
/**
* @constant
*/
static readonly silver: Color;
/**
* @constant
*/
static readonly teal: Color;
/**
* @constant
*/
static readonly transparent: Color;
/**
* @constant
*/
static readonly white: Color;
/**
* @constant
*/
static readonly yellow: Color;
}
// ColorResources
/**
* This is the base class for all color resource dictionaries. Instances can be obtained via the `from`
* method, or by subclassing. All members of a `ColorResources` (or subclass) instance will be of the
* type `Color`.
*/
export class ColorResources extends Resources {
/**
* This is the base class for all color resource dictionaries. Instances can be obtained via the `from`
* method, or by subclassing. All members of a `ColorResources` (or subclass) instance will be of the
* type `Color`.
*/
protected constructor(options: ResourcesConstructorOptions);
/**
* Creates a colors dictionary from the given raw "data" object. All colors from the given "base"
* dictionary are inherited unless overwritten.
* Entries in the "data" object starting with "$" are considered configuration options and will not
* become entries in the final colors dictionary.
* @param base A plain object or another `ColorResources` instance containing values to inherit by the new `ColorResources` dictionary.
* @param data The raw data (plain object) to create the dictionary from. The format must match the [Tabris.js colors JSON schema](${doc:colors.json}).
*/
static from , Data extends ResourceDataWithConfig>(base: Base, data: Data): NamedResources;
/**
* Creates a colors dictionary from the given raw "data" object. The format must match the [Tabris.js
* colors JSON schema](${doc:colors.json}). Entries in the "data" object starting with "$" are
* considered configuration options and will not become entries in the final colors dictionary.
* @param data The raw data (plain object) to create the dictionary from. The format must match the [Tabris.js colors JSON schema](${doc:colors.json}).
*/
static from>(data: Data): NamedResources;
}
// Composite
export interface CompositeAddChildEvent
extends EventObject
{
readonly child: Widget;
readonly index: number;
}
export interface CompositeRemoveChildEvent
extends EventObject
{
readonly child: Widget;
readonly index: number;
}
export namespace widgets {
/**
* An empty widget that can contain other widgets.
*/
export class Composite extends Widget {
/**
* An empty widget that can contain other widgets.
*
* This constructor can be called as a factory, without "new". Doing so allows passing an attributes
* object which may include (in addition to the properties) children, event listeners and layout
* shorthands.
*/
public constructor(properties?: Properties);
private $flushChildren(): void;
/**
* Called by the framework with each widget that is about to be added as a child of this composite. May
* be overwritten to reject some or all children by returning `false`.
* @param child
*/
protected _acceptChild(child: Widget): boolean;
/**
* Called by the framework with a child to be assigned to this composite. Triggers the 'addChild' event.
* May be overwritten to run any code prior or after the child is inserted.
* @param child
* @param index
*/
protected _addChild(child: Widget, index?: number): void;
/**
* Identical to the `apply(options, rules)` method, but intended to be used by subclasses in case the
* `children` method was overwritten . See "[Encapsulation](../selector.md#encapsulation)"
* @param options If mode is set to `'strict'` the function checks that all selector match at least one widget, and that id selector match exactly one widget. A `trigger` is string to be associated with the given rulset. If set to `'update'`, the ruleset will be applied once immediately and then again every time `apply('update')` is called. If set to any event-attribute name, such as `'onTap'`, it will automatically re-apply the ruleset when this event is triggered.
* @param rules The ruleset to apply. May also be given as a callback which is passed to the widget instance and must return the actual ruleset.
*/
protected _apply(options: {mode?: 'default'|'strict', trigger?: ListenersKeysOf | 'update' | '*' | symbol}, rules: RuleSet): this;
/**
* Identical to the `apply(rules)` method, but intended to be used by subclasses in case the `children`
* method was overwritten . See "[Encapsulation](../selector.md#encapsulation)"
* @param rules The ruleset to apply. May also be given as a callback which is passed to the widget instance and must return the actual ruleset.
*/
protected _apply(rules: RuleSet