提交 e275b77b 编写于 作者: E ester.zhou

Update docs (13290)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 a27bccb5
...@@ -436,8 +436,8 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a ...@@ -436,8 +436,8 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a
**Example** **Example**
```js ```js
// The source type is string. // The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
if (error) { if (error) {
...@@ -447,7 +447,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a ...@@ -447,7 +447,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a
console.log(`success to setWallpaper.`); console.log(`success to setWallpaper.`);
}); });
// The source type is image.PixelMap. // The source type is image.PixelMap.
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath); let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = { let opts = {
...@@ -467,7 +467,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a ...@@ -467,7 +467,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a
}).catch((error) => { }).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error)); console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
}); });
``` ```
## wallpaper.setWallpaper ## wallpaper.setWallpaper
...@@ -495,8 +495,8 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr ...@@ -495,8 +495,8 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
**Example** **Example**
```js ```js
// The source type is string. // The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`); console.log(`success to setWallpaper.`);
...@@ -504,7 +504,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr ...@@ -504,7 +504,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
console.error(`failed to setWallpaper because: ` + JSON.stringify(error)); console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
}); });
// The source type is image.PixelMap. // The source type is image.PixelMap.
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
let imageSource = image.createImageSource("file://" + wallpaperPath); let imageSource = image.createImageSource("file://" + wallpaperPath);
let opts = { let opts = {
...@@ -522,7 +522,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr ...@@ -522,7 +522,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
}).catch((error) => { }).catch((error) => {
console.error(`failed to createPixelMap because: ` + JSON.stringify(error)); console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
}); });
``` ```
## wallpaper.getFile<sup>8+</sup> ## wallpaper.getFile<sup>8+</sup>
...@@ -695,10 +695,10 @@ Unsubscribes from the wallpaper color change event. ...@@ -695,10 +695,10 @@ Unsubscribes from the wallpaper color change event.
console.log(`wallpaper color changed.`); console.log(`wallpaper color changed.`);
}; };
wallpaper.on('colorChange', listener); wallpaper.on('colorChange', listener);
// Unsubscribe from the listener. // Unsubscribe from the listener.
wallpaper.off('colorChange', listener); wallpaper.off('colorChange', listener);
// Unsubscribe from all subscriptions of the colorChange type. // Unsubscribe from all subscriptions of the colorChange type.
wallpaper.off('colorChange'); wallpaper.off('colorChange');
``` ```
......
...@@ -4,12 +4,17 @@ ...@@ -4,12 +4,17 @@
The custom font can be loaded from the font file in a project. The font file must be in .ttf or .otf format. The custom font can be loaded from the font file in a project. The font file must be in .ttf or .otf format.
> **NOTE**
>
> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
## Defining @font-face ## Defining @font-face
``` ```
@font-face { @font-face {
font-family: HWfont; font-family: font;
src: url('/common/HWfont.ttf'); src: url('/common/font.ttf');
} }
``` ```
...@@ -19,9 +24,9 @@ Customize a font. ...@@ -19,9 +24,9 @@ Customize a font.
**src** **src**
Supported sources of customized fonts: Supported sources of custom fonts:
- Font file in the project: Specify the path of the font file in the project through **url**. (You can use absolute paths only. For details, see [Resources and File Access Rules](https://gitee.com/openharmony/docs/blob/master/en/application-dev/ui/js-framework-file.md#section6620355202117).) - Font file in the project: Specify the absolute path of the font file in the project through **url**. For details, see [File Access Rules](../../ui/js-framework-file.md).
- You can set only one **src** attribute. - You can set only one **src** attribute.
## Using font-face ## Using font-face
...@@ -42,10 +47,10 @@ Page style: ...@@ -42,10 +47,10 @@ Page style:
``` ```
@font-face { @font-face {
font-family: HWfont; font-family: font;
src: url("/common/HWfont.ttf"); src: url("/common/font.ttf");
} }
.demo-text { .demo-text {
font-family: HWfont; font-family: font;
} }
``` ```
\ No newline at end of file
...@@ -27,17 +27,17 @@ loadAnimation( ...@@ -27,17 +27,17 @@ loadAnimation(
path: string, container: object, render: string, loop: boolean, autoplay: boolean, name: string ): AnimationItem path: string, container: object, render: string, loop: boolean, autoplay: boolean, name: string ): AnimationItem
Loads an animation. Before calling this API, declare the **Animator('__lottie_ets')** object and check that the canvas layout is complete. This method can be used together with a lifecycle callback of the **Canvas** component, for example, **onAppear()** and **onPageShow()**. Loads an animation. Before calling this API, declare the **Animator('__lottie_ets')** object and make sure the canvas layout is complete. This API can be used together with the lifecycle callback **onReady()** of the **Canvas** component.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------------- | --------------------------- | ---- | ---------------------------------------- | | -------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**| | path | string | Yes | Path of the animation resource file in the HAP file. The resource file must be in JSON format. Example: **path: "common/lottie/data.json"**|
| container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.| | container | object | Yes | Canvas drawing context. A **CanvasRenderingContext2D** object must be declared in advance.|
| render | string | Yes | Rendering type. The value can only be **"canvas"**. | | render | string | Yes | Rendering type. The value can only be **"canvas"**. |
| loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends; the default value is **true**. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.| | loop | boolean \| number | No | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends; the default value is **true**. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays.|
| autoplay | boolean | No | Whether to automatically play the animation.<br/>Default value: **true** | | autoplay | boolean | No | Whether to automatically play the animation.<br>Default value: **true** |
| name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation.<br/>Default value: null | | name | string | No | Custom animation name. In later versions, the name can be used to reference and control the animation.<br/>Default value: null |
| initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. | | initialSegment | [number, number] | No | Start frame and end frame of the animation, respectively. |
...@@ -46,15 +46,16 @@ Loads an animation. Before calling this API, declare the **Animator('__lottie_et ...@@ -46,15 +46,16 @@ Loads an animation. Before calling this API, declare the **Animator('__lottie_et
destroy(name: string): void destroy(name: string): void
Destroys the animation. This method must be called when a page exits. This method can be used together with a lifecycle callback of the **Canvas** component, for example, **onDisappear()** and **onPageHide()**. Destroys the animation. This API must be called when a page exits. This API can be used together with a lifecycle callback of the **Canvas** component, for example, **onDisappear()** and **onPageHide()**.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are destroyed.| | name | string | Yes | Name of the animation to destroy, which is the same as the **name** in the **loadAnimation** API. By default, all animations are destroyed. |
**Example** **Example**
```ts ```ts
// xxx.ets // xxx.ets
import lottie from '@ohos/lottieETS' import lottie from '@ohos/lottieETS'
...@@ -133,7 +134,7 @@ Plays a specified animation. ...@@ -133,7 +134,7 @@ Plays a specified animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are played.| | name | string | Yes | Name of the animation to play, which is the same as the **name** in the **loadAnimation** API. By default, all animations are played. |
**Example** **Example**
...@@ -152,7 +153,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani ...@@ -152,7 +153,7 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are paused.| | name | string | Yes | Name of the animation to pause, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused. |
**Example** **Example**
...@@ -165,13 +166,13 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani ...@@ -165,13 +166,13 @@ Pauses a specified animation. The next time **lottie.play()** is called, the ani
togglePause(name: string): void togglePause(name: string): void
Pauses or plays a specified animation. This method is equivalent to the switching between **lottie.play()** and **lottie.pause()**. Pauses or plays a specified animation. This API is equivalent to the switching between **lottie.play()** and **lottie.pause()**.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are paused.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are paused or played. |
**Example** **Example**
...@@ -190,7 +191,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an ...@@ -190,7 +191,7 @@ Stops the specified animation. The next time **lottie.play()** is called, the an
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are paused.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are stopped. |
**Example** **Example**
...@@ -209,8 +210,8 @@ Sets the playback speed of the specified animation. ...@@ -209,8 +210,8 @@ Sets the playback speed of the specified animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- | | ----- | ------ | ---- | ---------------------------------------- |
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is 0, the animation is paused. If the value is 1.0 or -1.0, the animation plays at the normal speed.| | speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays in forward direction. If the value is less than 0, the animation plays in reversed direction. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are stopped.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set. |
**Example** **Example**
...@@ -230,7 +231,7 @@ Sets the direction in which the specified animation plays. ...@@ -230,7 +231,7 @@ Sets the direction in which the specified animation plays.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| --------- | ------------------ | ---- | ---------------------------------------- | | --------- | ------------------ | ---- | ---------------------------------------- |
| direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 | | direction | AnimationDirection | Yes | Direction in which the animation plays. **1**: forwards; **-1**: backwards. When set to play backwards, the animation plays from the current playback progress to the first frame. When this setting is combined with **loop** being set to **true**, the animation plays backwards continuously. When the value of **speed** is less than 0, the animation also plays backwards.<br>AnimationDirection: 1 \| -1 |
| name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** interface. By default, all animations are set.| | name | string | Yes | Name of the target animation, which is the same as the **name** in the **loadAnimation** API. By default, all animations are set. |
**Example** **Example**
...@@ -241,7 +242,7 @@ Sets the direction in which the specified animation plays. ...@@ -241,7 +242,7 @@ Sets the direction in which the specified animation plays.
## AnimationItem ## AnimationItem
Defines an **AnimationItem** object, which is returned by the **loadAnimation** interface and has attributes and interfaces. The attributes are described as follows: Defines an **AnimationItem** object, which is returned by the **loadAnimation** API and has attributes and APIs. The attributes are described as follows:
| Name | Type | Description | | Name | Type | Description |
| ----------------- | ---------------------------------------- | ---------------------------------------- | | ----------------- | ---------------------------------------- | ---------------------------------------- |
...@@ -253,11 +254,11 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation** ...@@ -253,11 +254,11 @@ Defines an **AnimationItem** object, which is returned by the **loadAnimation**
| totalFrames | number | Total number of frames in the animation segment that is being played. | | totalFrames | number | Total number of frames in the animation segment that is being played. |
| frameRate | number | Frame rate (frame/s). | | frameRate | number | Frame rate (frame/s). |
| frameMult | number | Frame rate (frame/ms). | | frameMult | number | Frame rate (frame/ms). |
| playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused.|If the value is **1.0** or **-1.0**, the animation plays at the normal speed.| | playSpeed | number | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
| playDirection | number | Playback direction. The options are **1** (forward) and **-1** (backward). | | playDirection | number | Playback direction.<br>**1**: forward.<br/>**-1**: backward. |
| playCount | number | Number of times the animation plays. | | playCount | number | Number of times the animation plays. |
| isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. | | isPaused | boolean | Whether the current animation is paused. The value **true** means that the animation is paused. |
| autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()** interface needs to be called to start playing.| | autoplay | boolean | Whether to automatically play the animation upon completion of the loading. The value **false** means that the **play()** API needs to be called to start playing. |
| loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. | | loop | boolean \| number | If the value is of the Boolean type, this parameter indicates whether to repeat the animation cyclically after the animation ends. If the value is of the number type and is greater than or equal to 1, this parameter indicates the number of times the animation plays. |
| renderer | any | Animation rendering object, which depends on the rendering type. | | renderer | any | Animation rendering object, which depends on the rendering type. |
| animationID | string | Animation ID. | | animationID | string | Animation ID. |
...@@ -309,7 +310,7 @@ Destroys an animation. ...@@ -309,7 +310,7 @@ Destroys an animation.
pause(name?: string): void pause(name?: string): void
Pauses an animation. When the **play** interface is called next time, the animation is played from the current frame. Pauses an animation. When the **play** API is called next time, the animation is played from the current frame.
**Parameters** **Parameters**
...@@ -328,7 +329,7 @@ Pauses an animation. When the **play** interface is called next time, the animat ...@@ -328,7 +329,7 @@ Pauses an animation. When the **play** interface is called next time, the animat
togglePause(name?: string): void togglePause(name?: string): void
Pauses or plays an animation. This method is equivalent to the switching between **play** and **pause**. Pauses or plays an animation. This API is equivalent to the switching between **play** and **pause**.
**Parameters** **Parameters**
...@@ -347,7 +348,7 @@ Pauses or plays an animation. This method is equivalent to the switching between ...@@ -347,7 +348,7 @@ Pauses or plays an animation. This method is equivalent to the switching between
stop(name?: string): void stop(name?: string): void
Stops an animation. When the **play** interface is called next time, the animation is played from the first frame. Stops an animation. When the **play** API is called next time, the animation is played from the first frame.
**Parameters** **Parameters**
...@@ -372,7 +373,7 @@ Sets the playback speed of an animation. ...@@ -372,7 +373,7 @@ Sets the playback speed of an animation.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- | | ----- | ------ | ---- | ---------------------------------------- |
| speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is 0, the animation is paused.|If the value is **1.0** or **-1.0**, the animation plays at the normal speed.| | speed | number | Yes | Playback speed. The value is a floating-point number. If the value is greater than 0, the animation plays forward. If the value is less than 0, the animation plays backward. If the value is **0**, the animation is paused. If the value is **1.0** or **-1.0**, the animation plays at the normal speed. |
**Example** **Example**
...@@ -435,8 +436,8 @@ Sets the animation to start from the specified frame or time progress. ...@@ -435,8 +436,8 @@ Sets the animation to start from the specified frame or time progress.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------- | ---- | ---------------------------------------- | | ------- | ------- | ---- | ---------------------------------------- |
| value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. | | value | number | Yes | Frame ID (greater than or equal to 0) or time progress (ms) at which the animation will start. |
| isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress.<br>Default value: **false** | | isFrame | boolean | Yes | Whether to set the animation to start from the specified frame. The value **true** means to set the animation to start from the specified frame, and **false** means to set the animation to start from the specified time progress.<br/>Default value: **false** |
| name | string | No | Name of the target animation. By default, the value is null. | | name | string | No | Name of the target animation.<br/>Default value: null |
**Example** **Example**
...@@ -475,7 +476,7 @@ Sets the animation to play only the specified segment. ...@@ -475,7 +476,7 @@ Sets the animation to play only the specified segment.
resetSegments(forceFlag: boolean): void resetSegments(forceFlag: boolean): void
Resets the settings configured by the **playSegments** method to play all the frames. Resets the settings configured by the **playSegments** API to play all the frames.
**Parameters** **Parameters**
...@@ -526,7 +527,7 @@ Sets the precision of the **currentFrame** attribute to display floating-point n ...@@ -526,7 +527,7 @@ Sets the precision of the **currentFrame** attribute to display floating-point n
getDuration(inFrames?: boolean): void getDuration(inFrames?: boolean): void
Obtains the duration (irrelevant to the playback speed) or number of frames for playing an animation sequence. The settings are related to the input parameter **initialSegment** of the **Lottie.loadAnimation** interface. Obtains the duration (irrelevant to the playback speed) or number of frames for playing an animation sequence. The settings are related to the input parameter **initialSegment** of the **Lottie.loadAnimation** API.
**Parameters** **Parameters**
...@@ -545,7 +546,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for ...@@ -545,7 +546,7 @@ Obtains the duration (irrelevant to the playback speed) or number of frames for
addEventListener&lt;T = any&gt;(name: AnimationEventName, callback: AnimationEventCallback&lt;T&gt;): () =&gt; void addEventListener&lt;T = any&gt;(name: AnimationEventName, callback: AnimationEventCallback&lt;T&gt;): () =&gt; void
Adds an event listener. After the event is complete, the specified callback function is triggered. This method returns the function object that can delete the event listener. Adds an event listener. After the event is complete, the specified callback is triggered. This API returns the function object that can delete the event listener.
**Parameters** **Parameters**
...@@ -578,7 +579,7 @@ Removes an event listener. ...@@ -578,7 +579,7 @@ Removes an event listener.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| name | AnimationEventName | Yes | Animation event type. The available options are as follows:<br>'enterFrame', 'loopComplete', 'complete', 'segmentStart', 'destroy', 'config_ready', 'data_ready', 'DOMLoaded', 'error', 'data_failed', 'loaded_images'| | name | AnimationEventName | Yes | Animation event type. The available options are as follows:<br>'enterFrame', 'loopComplete', 'complete', 'segmentStart', 'destroy', 'config_ready', 'data_ready', 'DOMLoaded', 'error', 'data_failed', 'loaded_images'|
| callback | AnimationEventCallback&lt;T&gt; | Yes | Custom callback. By default, the value is null, meaning that all callbacks of the event will be removed. | | callback | AnimationEventCallback&lt;T&gt; | No | Custom callback. By default, the value is null, meaning that all callbacks of the event will be removed. |
**Example** **Example**
......
...@@ -14,7 +14,7 @@ This component can contain child components. ...@@ -14,7 +14,7 @@ This component can contain child components.
## APIs ## APIs
Swiper(value?:{controller?: SwiperController}) Swiper(controller?: SwiperController)
**Parameters** **Parameters**
...@@ -96,6 +96,10 @@ onChange(event: (index: number) => void) ...@@ -96,6 +96,10 @@ onChange(event: (index: number) => void)
Triggered when the index of the currently displayed child component changes. Triggered when the index of the currently displayed child component changes.
> **NOTE**
>
> When the **\<Swiper>** component is used together with **LazyForEach**, the subpage UI cannot be refreshed in the **onChange** event.
**Parameters** **Parameters**
| Name | Type | Mandatory.| Description| | Name | Type | Mandatory.| Description|
......
...@@ -137,4 +137,4 @@ struct GestureSettingsExample { ...@@ -137,4 +137,4 @@ struct GestureSettingsExample {
} }
``` ```
![zh-cn_image_0000001210195016](figures/zh-cn_image_0000001210195016.gif) ![en-us_image_0000001210195016](figures/en-us_image_0000001210195016.gif)
# @Prop # @Prop
**@Prop** and **@State** have the same semantics but different initialization modes. A **@Prop** decorated variable in a component must be initialized using the **@State** decorated variable in its parent component. The **@Prop** decorated variable can be modified in the component, but the modification is not updated to the parent component; the modification to the **@State** decorated variable is synchronized to the **@Prop** decorated variable. That is, **@Prop** establishes one-way data binding.
@Prop and @State have the same semantics but different initialization modes. Variables decorated by @Prop must be initialized using the @State decorated variable provided by their parent components. The @Prop decorated variable can be modified in the component, but the modification is not updated to the parent component; that is, @Prop uses one-way data binding.
The **@Prop** decorated state variable has the following features:
The @Prop state data has the following features:
- Support for simple types: The number, string, and boolean types are supported. - Support for simple types: The number, string, and boolean types are supported.
- Private: Data is accessed only within the component. - Private: Data is accessed only within the component.
- Support for multiple instances: A component can have multiple attributes decorated by @Prop. - Support for multiple instances: A component can have multiple attributes decorated by **@Prop**.
- Support for initialization with a value passed to the @Prop decorated variable: When a new instance of the component is created, all @Prop decorated variables must be initialized. Initialization inside the component is not supported. - Support for initialization with a value passed to the **@Prop** decorated variable: When a new instance of the component is created, all **@Prop** decorated variables must be initialized. Initialization inside the component is not supported.
## Example ## Example
...@@ -66,7 +65,8 @@ struct CountDownComponent { ...@@ -66,7 +65,8 @@ struct CountDownComponent {
} }
``` ```
In the preceding example, when you press +1 or -1, the status of the parent component changes and the build method is executed again. In this case, a new CountDownComponent is created. The countDownStartValue property of the parent component is used to initialize the @Prop decorated variable of the child component. When you tap the Try again button of the child component, the value of the @Prop decorated variable count is changed. As a result, the CountDownComponent is rendered again. However, the change of the count value does not affect the countDownStartValue value of the parent component. In the preceding example, when the user presses **+1** or **-1**, the status of the parent component changes and the **build** method is executed again. In this case, a new **CountDownComponent** instance is created. The **countDownStartValue** attribute of the parent component is used to initialize the **@Prop** decorated variable of the child component. When the **Try again** button of the child component is touched, the value of the **@Prop** decorated variable **count** is changed. As a result, the **CountDownComponent** is rendered again. However, the change of the **count** value does not affect the **countDownStartValue** value of the parent component.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**: > **NOTE**
> When a new component instance is created, all its @Prop decorated variables must be initialized. >
> When a new component instance is created, all its **@Prop** decorated variables must be initialized.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册