• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16export interface ViewModel {
17  /**
18   * Displays content based on the current system language and a path of the language resource key specified through $t.
19   *
20   * @param { string } path - Path of the language resource key
21   * @param { object | Array<any> } [param] - Content used to replace placeholders during runtime. There are two types of placeholders available:
22   *              1. Named placeholder, for example, {name}. The actual content must be of the object type, for example, $t('strings.object', {name: 'Hello world'}).
23   *              2. Digit placeholder, for example, {0}. The actual content must be of the array type, for example, $t('strings.array', ['Hello world']).
24   * @returns { string } content to display
25   * @syscap SystemCapability.ArkUI.ArkUI.Lite
26   * @since 4
27   */
28  $t(path: string, param?: object | Array<any>): string;
29
30  /**
31   * An object that holds all DOM elements and component instances that have been registered with the refs attribute
32   *
33   * @type { ElementReferences }
34   * @syscap SystemCapability.ArkUI.ArkUI.Lite
35   * @since 4
36   */
37  $refs: ElementReferences;
38}
39
40export interface ListScrollToOptions {
41  /**
42   * specified position.
43   *
44   * @type { number }
45   * @syscap SystemCapability.ArkUI.ArkUI.Lite
46   * @since 4
47   */
48  index: number;
49}
50
51export interface ListElement {
52  /**
53   * Scrolls the list to the position of the item at the specified index.
54   *
55   * @param { ListScrollToOptions } position
56   * @syscap SystemCapability.ArkUI.ArkUI.Lite
57   * @since 4
58   */
59  scrollTo(position: ListScrollToOptions): void;
60}
61
62export interface ImageAnimatorElement {
63  /**
64   * Starts to play the frame animation of an image. If this method is called again, the playback starts from the first frame.
65   *
66   * @syscap SystemCapability.ArkUI.ArkUI.Lite
67   * @since 4
68   */
69  start(): void;
70  /**
71   * Pauses the frame animation playback of an image.
72   *
73   * @syscap SystemCapability.ArkUI.ArkUI.Lite
74   * @since 4
75   */
76  pause(): void;
77  /**
78   * Stops the frame animation playback of an image.
79   *
80   * @syscap SystemCapability.ArkUI.ArkUI.Lite
81   * @since 4
82   */
83  stop(): void;
84  /**
85   * Resumes the frame animation playback of an image.
86   *
87   * @syscap SystemCapability.ArkUI.ArkUI.Lite
88   * @since 4
89   */
90  resume(): void;
91  /**
92   * Obtains the playback state. Available values are as follows:
93   * Playing
94   * Paused
95   * Stopped
96   *
97   * @returns { "Playing" | "Paused" | "Stopped" }
98   * @syscap SystemCapability.ArkUI.ArkUI.Lite
99   * @since 4
100   */
101  getState(): "Playing" | "Paused" | "Stopped";
102}
103
104export interface ElementReferences {
105  [k: string]: object & ListElement & ImageAnimatorElement;
106}
107
108export interface Options<T extends ViewModel, Data = DefaultData<T>> {
109  /**
110   * Data model of the page that can be converted into a JSON object.
111   * The attribute name cannot start with $ or an underscore (_) or contain the reserved words such as for, if, show, and tid.
112   * For a function, the return value must be an object.
113   * Set the value of data to the return value of the function during page initialization.
114   *
115   * @type { ?Data }
116   * @syscap SystemCapability.ArkUI.ArkUI.Lite
117   * @since 4
118   */
119  data?: Data;
120
121  /**
122   * Called when the page is initialized. This function can be called only once in a lifecycle.
123   *
124   * @syscap SystemCapability.ArkUI.ArkUI.Lite
125   * @since 4
126   */
127  onInit?(): void;
128
129  /**
130   * Called when the page is created. This function can be called only once in a lifecycle.
131   *
132   * @syscap SystemCapability.ArkUI.ArkUI.Lite
133   * @since 4
134   */
135  onReady?(): void;
136
137  /**
138   * Called when the page is displayed.
139   *
140   * @syscap SystemCapability.ArkUI.ArkUI.Lite
141   * @since 4
142   */
143  onShow?(): void;
144
145  /**
146   * Called when the application is created
147   *
148   * @syscap SystemCapability.ArkUI.ArkUI.Lite
149   * @since 4
150   */
151  onCreate?(): void;
152
153  /**
154   * Called when the application is destroyed or called when the page is redirected to another one (without entering the navigation stack).
155   *
156   * @syscap SystemCapability.ArkUI.ArkUI.Lite
157   * @since 4
158   */
159  onDestroy?(): void;
160
161  /**
162   * Called when the user data need to be saved
163   *
164   * @param { Object } data - Indicates the user data to save.
165   * @returns { boolean } Returns {@code true} if the data is successfully saved; returns {@code false} otherwise.
166   * @syscap SystemCapability.ArkUI.ArkUI.Lite
167   * @since 10
168   */
169  onSaveData?(data: Object): boolean;
170
171  /**
172   * Called when the user data need to be restored
173   *
174   * @param { Object } data - Indicates the user data to restore.
175   * @syscap SystemCapability.ArkUI.ArkUI.Lite
176   * @since 10
177   */
178  onRestoreData?(data: Object): void;
179}
180
181/**
182 * Used for ide.
183 *
184 * @syscap SystemCapability.ArkUI.ArkUI.Lite
185 * @systemapi
186 * @since 4
187 */
188type DefaultData<T> = object;
189
190/**
191 * Used for ide.
192 *
193 * @syscap SystemCapability.ArkUI.ArkUI.Lite
194 * @systemapi
195 * @since 4
196 */
197type CombinedOptions<T extends ViewModel, Data> = object &
198  Options<T, Data> &
199  ThisType<T & ViewModel & Data>;
200
201/**
202 * @param { CombinedOptions<T, Data> } options
203 * @returns { ViewModel & Data }
204 * @syscap SystemCapability.ArkUI.ArkUI.Lite
205 * @systemapi
206 * @since 4
207 */
208export declare function extendViewModel<T extends ViewModel, Data>(
209  options: CombinedOptions<T, Data>
210): ViewModel & Data;
211