• 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
16/**
17 * @file
18 * @kit ArkUI
19 */
20
21/**
22 * View model
23 * @interface ViewModel
24 * @syscap SystemCapability.ArkUI.ArkUI.Lite
25 * @since 4
26 */
27export interface ViewModel {
28  /**
29   * Displays content based on the current system language and a path of the language resource key specified through $t.
30   *
31   * @param { string } path - Path of the language resource key
32   * @param { object | Array<any> } [param] - Content used to replace placeholders during runtime. There are two types of placeholders available:
33   *              1. Named placeholder, for example, {name}. The actual content must be of the object type, for example, $t('strings.object', {name: 'Hello world'}).
34   *              2. Digit placeholder, for example, {0}. The actual content must be of the array type, for example, $t('strings.array', ['Hello world']).
35   * @returns { string } content to display
36   * @syscap SystemCapability.ArkUI.ArkUI.Lite
37   * @since 4
38   */
39  $t(path: string, param?: object | Array<any>): string;
40
41  /**
42   * An object that holds all DOM elements and component instances that have been registered with the refs attribute
43   *
44   * @type { ElementReferences }
45   * @syscap SystemCapability.ArkUI.ArkUI.Lite
46   * @since 4
47   */
48  $refs: ElementReferences;
49}
50
51/**
52 * List scroll to options
53 * @interface ListScrollToOptions
54 * @syscap SystemCapability.ArkUI.ArkUI.Lite
55 * @since 4
56 */
57export interface ListScrollToOptions {
58  /**
59   * specified position.
60   *
61   * @type { number }
62   * @syscap SystemCapability.ArkUI.ArkUI.Lite
63   * @since 4
64   */
65  index: number;
66}
67
68/**
69 * List element
70 * @interface ListElement
71 * @syscap SystemCapability.ArkUI.ArkUI.Lite
72 * @since 4
73 */
74export interface ListElement {
75  /**
76   * Scrolls the list to the position of the item at the specified index.
77   *
78   * @param { ListScrollToOptions } position
79   * @syscap SystemCapability.ArkUI.ArkUI.Lite
80   * @since 4
81   */
82  scrollTo(position: ListScrollToOptions): void;
83}
84
85/**
86 * Image animator element
87 * @interface ImageAnimatorElement
88 * @syscap SystemCapability.ArkUI.ArkUI.Lite
89 * @since 4
90 */
91export interface ImageAnimatorElement {
92  /**
93   * Starts to play the frame animation of an image. If this method is called again, the playback starts from the first frame.
94   *
95   * @syscap SystemCapability.ArkUI.ArkUI.Lite
96   * @since 4
97   */
98  start(): void;
99  /**
100   * Pauses the frame animation playback of an image.
101   *
102   * @syscap SystemCapability.ArkUI.ArkUI.Lite
103   * @since 4
104   */
105  pause(): void;
106  /**
107   * Stops the frame animation playback of an image.
108   *
109   * @syscap SystemCapability.ArkUI.ArkUI.Lite
110   * @since 4
111   */
112  stop(): void;
113  /**
114   * Resumes the frame animation playback of an image.
115   *
116   * @syscap SystemCapability.ArkUI.ArkUI.Lite
117   * @since 4
118   */
119  resume(): void;
120  /**
121   * Obtains the playback state. Available values are as follows:
122   * Playing
123   * Paused
124   * Stopped
125   *
126   * @returns { "Playing" | "Paused" | "Stopped" }
127   * @syscap SystemCapability.ArkUI.ArkUI.Lite
128   * @since 4
129   */
130  getState(): "Playing" | "Paused" | "Stopped";
131}
132
133/**
134 * Element References
135 * @interface ElementReferences
136 * @syscap SystemCapability.ArkUI.ArkUI.Lite
137 * @since 4
138 */
139export interface ElementReferences {
140  [k: string]: object & ListElement & ImageAnimatorElement;
141}
142
143/**
144 * Options type
145 * @interface Options
146 * @syscap SystemCapability.ArkUI.ArkUI.Lite
147 * @since 4
148 */
149export interface Options<T extends ViewModel, Data = DefaultData<T>> {
150  /**
151   * Data model of the page that can be converted into a JSON object.
152   * The attribute name cannot start with $ or an underscore (_) or contain the reserved words such as for, if, show, and tid.
153   * For a function, the return value must be an object.
154   * Set the value of data to the return value of the function during page initialization.
155   *
156   * @type { ?Data }
157   * @syscap SystemCapability.ArkUI.ArkUI.Lite
158   * @since 4
159   */
160  data?: Data;
161
162  /**
163   * Called when the page is initialized. This function can be called only once in a lifecycle.
164   *
165   * @syscap SystemCapability.ArkUI.ArkUI.Lite
166   * @since 4
167   */
168  onInit?(): void;
169
170  /**
171   * Called when the page is created. This function can be called only once in a lifecycle.
172   *
173   * @syscap SystemCapability.ArkUI.ArkUI.Lite
174   * @since 4
175   */
176  onReady?(): void;
177
178  /**
179   * Called when the page is displayed.
180   *
181   * @syscap SystemCapability.ArkUI.ArkUI.Lite
182   * @since 4
183   */
184  onShow?(): void;
185
186  /**
187   * Called when the application is created
188   *
189   * @syscap SystemCapability.ArkUI.ArkUI.Lite
190   * @since 4
191   */
192  onCreate?(): void;
193
194  /**
195   * Called when the application is destroyed or called when the page is redirected to another one (without entering the navigation stack).
196   *
197   * @syscap SystemCapability.ArkUI.ArkUI.Lite
198   * @since 4
199   */
200  onDestroy?(): void;
201
202  /**
203   * Called when the user data need to be saved
204   *
205   * @param { Object } data - Indicates the user data to save.
206   * @returns { boolean } Returns {@code true} if the data is successfully saved; returns {@code false} otherwise.
207   * @syscap SystemCapability.ArkUI.ArkUI.Lite
208   * @since 10
209   */
210  onSaveData?(data: Object): boolean;
211
212  /**
213   * Called when the user data need to be restored
214   *
215   * @param { Object } data - Indicates the user data to restore.
216   * @syscap SystemCapability.ArkUI.ArkUI.Lite
217   * @since 10
218   */
219  onRestoreData?(data: Object): void;
220}
221
222/**
223 * Used for ide.
224 *
225 * @syscap SystemCapability.ArkUI.ArkUI.Lite
226 * @systemapi
227 * @since 4
228 */
229type DefaultData<T> = object;
230
231/**
232 * Used for ide.
233 *
234 * @syscap SystemCapability.ArkUI.ArkUI.Lite
235 * @systemapi
236 * @since 4
237 */
238type CombinedOptions<T extends ViewModel, Data> = object &
239  Options<T, Data> &
240  ThisType<T & ViewModel & Data>;
241
242/**
243 * @param { CombinedOptions<T, Data> } options
244 * @returns { ViewModel & Data }
245 * @syscap SystemCapability.ArkUI.ArkUI.Lite
246 * @systemapi
247 * @since 4
248 */
249export declare function extendViewModel<T extends ViewModel, Data>(
250  options: CombinedOptions<T, Data>
251): ViewModel & Data;
252