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