1/* 2 * Copyright (C) 2025 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 * @file 17 * @kit ArkUI 18 * @arkts 1.2 19 */ 20 21import { memo, ComponentBuilder, __memo_context_type, __memo_id_type } from "../stateManagement/runtime"; 22import { ExtendableComponent } from './extendableComponent'; 23import { GeometryInfo, Layoutable, Measurable, SizeResult } from './common' 24import { ConstraintSizeOptions } from './units' 25import { Builder } from './builder' 26import { LocalStorage } from './../stateManagement/storages/localStorage'; 27import { UIContext } from './../../../api/@ohos.arkui.UIContext' 28import { WatchFuncType } from '../stateManagement/decorators/decoratorWatch' 29import { ProvideDecoratedVariable } from '../stateManagement/decorators/decoratorProvide' 30import { ConsumeDecoratedVariable } from '../stateManagement/decorators/decoratorConsume' 31 32/** 33 * Defines Entry Annotation. 34 * 35 * Entry is an Annotation and it supports parameters. 36 * @syscap SystemCapability.ArkUI.ArkUI.Full 37 * @crossplatform 38 * @atomicservice 39 * @since 20 40 */ 41@Retention({policy: "SOURCE"}) 42export @interface Entry { 43 /** 44 * Named route name. 45 * 46 * @type { string } 47 * @syscap SystemCapability.ArkUI.ArkUI.Full 48 * @atomicservice 49 * @since 20 50 */ 51 routeName: string = ""; 52 53 /** 54 * Name of the function which returns LocalStorage instance. 55 * 56 * @type { string } 57 * @syscap SystemCapability.ArkUI.ArkUI.Full 58 * @atomicservice 59 * @since 20 60 */ 61 storage: string = ""; 62 63 /** 64 * Determines whether to use the LocalStorage instance object returned by UIContext.getSharedLocalStorage() interface. 65 * 66 * @type { boolean } 67 * @syscap SystemCapability.ArkUI.ArkUI.Full 68 * @crossplatform 69 * @atomicservice 70 * @since 20 71 */ 72 useSharedStorage: boolean = false; 73} 74 75/** 76 * Defining Component Annotation 77 * 78 * Component is an Annotation to define a custom component using state management V1. 79 * @syscap SystemCapability.ArkUI.ArkUI.Full 80 * @crossplatform 81 * @atomicservice 82 * @since 20 83 */ 84@Retention({policy: "SOURCE"}) 85export @interface Component {} 86 87/** 88 * Defining ComponentV2 Annotation 89 * 90 * ComponentV2 is an Annotation to define a custom component using state management V2. 91 * @syscap SystemCapability.ArkUI.ArkUI.Full 92 * @crossplatform 93 * @atomicservice 94 * @since 20 95 */ 96@Retention({policy: "SOURCE"}) 97export @interface ComponentV2 {} 98 99/** 100 * Defining Reusable Annotation that is used to decorate @Component. 101 * 102 * @syscap SystemCapability.ArkUI.ArkUI.Full 103 * @crossplatform 104 * @atomicservice 105 * @since 20 106 */ 107@Retention({policy: "SOURCE"}) 108export @interface Reusable {} 109 110/** 111 * Defining ReusableV2 Annotation that is used to decorate @ComponentV2. 112 * 113 * @syscap SystemCapability.ArkUI.ArkUI.Full 114 * @crossplatform 115 * @atomicservice 116 * @since 20 117 */ 118@Retention({policy: "SOURCE"}) 119export @interface ReusableV2 {} 120 121/** 122 * Defining CustomLayout Annotation that is used to decorate @Component and @ComponentV2. 123 * 124 * @syscap SystemCapability.ArkUI.ArkUI.Full 125 * @crossplatform 126 * @atomicservice 127 * @since 20 128 */ 129@Retention({policy: "SOURCE"}) 130export @interface CustomLayout {} 131 132/** 133 * Defining CustomDialog Annotation 134 * 135 * CustomDialog is an Annotation to define a custom dialog. 136 * @syscap SystemCapability.ArkUI.ArkUI.Full 137 * @crossplatform 138 * @atomicservice 139 * @since 20 140 */ 141@Retention({policy: "SOURCE"}) 142export @interface CustomDialog {} 143 144/** 145 * Definition of base custom dialog class. 146 * 147 * @extends ExtendableComponent 148 * @syscap SystemCapability.ArkUI.ArkUI.Full 149 * @crossplatform 150 * @atomicservice 151 * @since 20 152 */ 153export declare abstract class BaseCustomDialog<T extends BaseCustomDialog<T, T_Options>, T_Options> extends ExtendableComponent { 154 /** 155 * Constructor to use to create a custom dialog instance. 156 * @param {boolean} [useSharedStorage] - determine whether to use the LocalStorage instance object returned by UIContext.getSharedLocalStorage() interface. 157 * @param {LocalStorage} [storage] - localStorage instance. 158 * @syscap SystemCapability.ArkUI.ArkUI.Full 159 * @since 20 160 */ 161 constructor(useSharedStorage?: boolean, storage?: LocalStorage); 162 163 /** 164 * Define the constructor of custom dialog 165 * 166 * @param { () => T } factory - factory to create instance of custom dialog 167 * @param { T_Options } initializers - initial data for all the fields in custom dialog 168 * @param { @Builder () => void } content - tail closure for custom dialog 169 * @syscap SystemCapability.ArkUI.ArkUI.Full 170 * @crossplatform 171 * @atomicservice 172 * @since 20 173 */ 174 @ComponentBuilder 175 static $_instantiate( 176 factory: () => T, 177 initializers?: T_Options, 178 @Builder content?: () => void 179 ): T 180} 181 182/** 183 * Definition of base custom component, which is base class of custom component. 184 * 185 * @extends ExtendableComponent 186 * @implements CommonAttribute 187 * @syscap SystemCapability.ArkUI.ArkUI.Full 188 * @crossplatform 189 * @atomicservice 190 * @since 20 191 */ 192export declare abstract class BaseCustomComponent extends ExtendableComponent { 193 /** 194 * aboutToRecycle Method. 195 * 196 * @syscap SystemCapability.ArkUI.ArkUI.Full 197 * @crossplatform 198 * @atomicservice 199 * @since 20 200 */ 201 aboutToRecycle(): void; 202} 203 204export declare abstract class CustomComponent<T extends CustomComponent<T, T_Options>, T_Options> { 205 public addProvidedVar<T>(varName: string, providedPropName: string, initValue: T, allowOverride: boolean = false, watchFunc?: WatchFuncType): ProvideDecoratedVariable<T>; 206 public initConsume<T>(varName: string, providedPropName: string, watchFunc?: WatchFuncType): ConsumeDecoratedVariable<T>; 207 @memo 208 @ComponentBuilder 209 static $_instantiate<S extends CustomComponent<S, S_Options>, S_Options>( 210 factory: () => S, 211 initializers?: S_Options, 212 @memo 213 content?: () => void, 214 reuseKey?: string 215 ): S; 216 217 // Life cycle for custom component 218 aboutToAppear(): void 219 aboutToDisappear(): void 220 onDidBuild(): void 221 222 onPageShow(): void 223 onPageHide(): void 224 onBackPress(): boolean 225 getUIContext(): UIContext 226 227 @memo 228 build(): void; 229 230 aboutToReuse(): void 231 aboutToRecycle(): void 232} 233 234/** 235 * Definition of V2 custom component class. 236 * 237 * @extends BaseCustomComponent 238 * @syscap SystemCapability.ArkUI.ArkUI.Full 239 * @crossplatform 240 * @atomicservice 241 * @since 20 242 */ 243export declare abstract class CustomComponentV2<T extends CustomComponentV2<T, T_Options>, T_Options> extends BaseCustomComponent { 244 /** 245 * Define the constructor of custom component 246 * 247 * @param { () => T } factory - factory to create instance of custom component 248 * @param { T_Options } initializers - initial data for all the fields in custom component 249 * @param { string } reuseId - reuse id for reusable. Only valid if custom component decorated with @Reusable 250 * @param { @Builder () => void } content - tail closure for custom component 251 * @syscap SystemCapability.ArkUI.ArkUI.Full 252 * @crossplatform 253 * @atomicservice 254 * @since 20 255 */ 256 @ComponentBuilder 257 static $_instantiate( 258 factory: () => T, 259 initializers?: T_Options, 260 reuseId?: string, 261 @Builder content?: () => void 262 ): T 263 264 /** 265 * aboutToReuse Method 266 * 267 * @syscap SystemCapability.ArkUI.ArkUI.Full 268 * @crossplatform 269 * @atomicservice 270 * @since 20 271 */ 272 aboutToReuse(): void; 273} 274 275/** 276 * Defining interface of PageLifeCycle for custom component, when decorate with @Entry. 277 * 278 * @syscap SystemCapability.ArkUI.ArkUI.Full 279 * @crossplatform 280 * @atomicservice 281 * @since 20 282 */ 283export interface PageLifeCycle { 284 /** 285 * onPageShow Method. 286 * 287 * The page is triggered once each time it is displayed, including scenarios such as the routing process and the application entering the foreground 288 * 289 * @syscap SystemCapability.ArkUI.ArkUI.Full 290 * @crossplatform 291 * @atomicservice 292 * @since 20 293 */ 294 onPageShow(): void {} 295 296 /** 297 * onPageHide Method. 298 * 299 * It is triggered once each time the page is hidden, including scenarios such as the routing process and the application entering the background 300 * 301 * @syscap SystemCapability.ArkUI.ArkUI.Full 302 * @crossplatform 303 * @atomicservice 304 * @since 20 305 */ 306 onPageHide(): void {} 307 308 /** 309 * onBackPress Method. 310 * 311 * Triggered when the user clicks the back button 312 * 313 * @returns { boolean } true means that the page itself processes the return logic. 314 * false means that the default return logic is used. 315 * @syscap SystemCapability.ArkUI.ArkUI.Full 316 * @crossplatform 317 * @atomicservice 318 * @since 20 319 */ 320 onBackPress(): boolean { return false } 321 322 /** 323 * PageTransition Method. 324 * Implement Animation when enter this page or move to other pages. 325 * 326 * @syscap SystemCapability.ArkUI.ArkUI.Full 327 * @crossplatform 328 * @atomicservice 329 * @since 20 330 */ 331 pageTransition(): void {} 332 333 /** 334 * Triggered when the Entry custom component has been pushed with singleton mode. 335 * 336 * @param { object | undefined | null } param - New parameters pushed with singleton mode. 337 * @syscap SystemCapability.ArkUI.ArkUI.Full 338 * @crossplatform 339 * @atomicservice 340 * @since 20 341 */ 342 onNewParam(param: object | undefined | null): void {} 343} 344 345/** 346 * Defining interface of LayoutCallback for custom component, when decorate with @Layoutable. 347 * 348 * @syscap SystemCapability.ArkUI.ArkUI.Full 349 * @crossplatform 350 * @atomicservice 351 * @since 20 352 */ 353export interface LayoutCallback { 354 /** 355 * Custom component override this method to layout each of its sub components. 356 * 357 * @param { GeometryInfo } selfLayoutInfo 358 * @param { Array<Layoutable> } children 359 * @param { ConstraintSizeOptions } constraint 360 * @syscap SystemCapability.ArkUI.ArkUI.Full 361 * @crossplatform 362 * @atomicservice 363 * @since 20 364 */ 365 onPlaceChildren(selfLayoutInfo: GeometryInfo, children: Array<Layoutable>, constraint: ConstraintSizeOptions): void {} 366 367 /** 368 * Custom component override this method to measure each of its sub components. 369 * @param { GeometryInfo } selfLayoutInfo 370 * @param { Array<Measurable> } children - indicate the measure child 371 * @param { ConstraintSizeOptions } constraint - indicate child constraint size 372 * @returns { SizeResult } 373 * @syscap SystemCapability.ArkUI.ArkUI.Full 374 * @crossplatform 375 * @atomicservice 376 * @since 20 377 */ 378 onMeasureSize(selfLayoutInfo: GeometryInfo, children: Array<Measurable>, constraint: ConstraintSizeOptions): SizeResult { 379 return {width: 0, height: 0} as SizeResult 380 } 381} 382