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 * @param path Path of the language resource key 20 * @param param Content used to replace placeholders during runtime. There are two types of placeholders available: 21 * 1. Named placeholder, for example, {name}. The actual content must be of the object type, for example, $t('strings.object', {name: 'Hello world'}). 22 * 2. Digit placeholder, for example, {0}. The actual content must be of the array type, for example, $t('strings.array', ['Hello world']). 23 * @returns content to display 24 */ 25 $t(path: string, param?: object | Array<any>): string; 26 27 /** 28 * An object that holds all DOM elements and component instances that have been registered with the refs attribute 29 */ 30 $refs: ElementReferences; 31} 32 33export interface ListScrollToOptions { 34 /** 35 * specified position. 36 */ 37 index: number; 38} 39 40export interface ListElement { 41 /** 42 * Scrolls the list to the position of the item at the specified index. 43 */ 44 scrollTo(position: ListScrollToOptions): void; 45} 46 47export interface ImageAnimatorElement { 48 /** 49 * Starts to play the frame animation of an image. If this method is called again, the playback starts from the first frame. 50 */ 51 start(): void; 52 /** 53 * Pauses the frame animation playback of an image. 54 */ 55 pause(): void; 56 /** 57 * Stops the frame animation playback of an image. 58 */ 59 stop(): void; 60 /** 61 * Resumes the frame animation playback of an image. 62 */ 63 resume(): void; 64 /** 65 * Obtains the playback state. Available values are as follows: 66 * Playing 67 * Paused 68 * Stopped 69 */ 70 getState(): "Playing" | "Paused" | "Stopped"; 71} 72 73export interface ElementReferences { 74 [k: string]: object & ListElement & ImageAnimatorElement; 75} 76 77export interface Options<T extends ViewModel, Data = DefaultData<T>> { 78 /** 79 * Data model of the page that can be converted into a JSON object. 80 * The attribute name cannot start with $ or an underscore (_) or contain the reserved words such as for, if, show, and tid. 81 * For a function, the return value must be an object. 82 * Set the value of data to the return value of the function during page initialization. 83 */ 84 data?: Data; 85 86 /** 87 * Called when the page is initialized. This function can be called only once in a lifecycle. 88 */ 89 onInit?(): void; 90 91 /** 92 * Called when the page is created. This function can be called only once in a lifecycle. 93 */ 94 onReady?(): void; 95 96 /** 97 * Called when the page is displayed. 98 */ 99 onShow?(): void; 100 101 /** 102 * Called when the application is created 103 */ 104 onCreate?(): void; 105 106 /** 107 * Called when the application is destroyed or called when the page is redirected to another one (without entering the navigation stack). 108 */ 109 onDestroy?(): void; 110} 111 112/** 113 * Used for ide. 114 * @systemapi 115 * @since 4 116 */ 117type DefaultData<T> = object; 118 119/** 120 * Used for ide. 121 * @systemapi 122 * @since 4 123 */ 124type CombinedOptions<T extends ViewModel, Data> = object & 125 Options<T, Data> & 126 ThisType<T & ViewModel & Data>; 127 128/** 129 * @syscap SystemCapability.ArkUI.ArkUI.Lite 130 * @systemapi 131 * @since 4 132 */ 133export declare function extendViewModel<T extends ViewModel, Data>( 134 options: CombinedOptions<T, Data> 135): ViewModel & Data; 136