diff --git a/en/application-dev/application-models/arkts-ui-widget-page-animation.md b/en/application-dev/application-models/arkts-ui-widget-page-animation.md index 0cb8e356c61155d367e55c0f39bbf491d03e2e12..ff479a47e17cadc04c38ecdc3931b5aa1b3d687f 100644 --- a/en/application-dev/application-models/arkts-ui-widget-page-animation.md +++ b/en/application-dev/application-models/arkts-ui-widget-page-animation.md @@ -1,7 +1,7 @@ # Using Animations in the Widget -To make your ArkTS widget more engaging, you can apply animations to it, including [explicit animation](../reference/arkui-ts/ts-explicit-animation.md), [attribute animation](../reference/arkui-ts/ts-animatorproperty.md), and [component transition](../reference/arkui-ts/ts-transition-animation-component.md). Just note the following restrictions when using the animations in ArkTS widgets. +To make your ArkTS widget more engaging, you can apply animations to it, including [explicit animation](../reference/arkui-ts/ts-explicit-animation.md), [property animation](../reference/arkui-ts/ts-animatorproperty.md), and [component transition](../reference/arkui-ts/ts-transition-animation-component.md). Just note the following restrictions when using the animations in ArkTS widgets. **Table 1** Restrictions on animation parameters diff --git a/en/application-dev/application-models/arkts-ui-widget-working-principles.md b/en/application-dev/application-models/arkts-ui-widget-working-principles.md index 25cb66f1b05eaf845c11ab05350f2e705de6cec8..a8599ca8827c2d41c3ff1be032151c1f6debead9 100644 --- a/en/application-dev/application-models/arkts-ui-widget-working-principles.md +++ b/en/application-dev/application-models/arkts-ui-widget-working-principles.md @@ -35,7 +35,7 @@ As a quick entry to applications, ArkTS widgets outperform JS widgets in the fol ![WidgetProject](figures/WidgetProject.png) - More widget features - - Animation: ArkTS widgets support the [attribute animation](../reference/arkui-ts/ts-animatorproperty.md) and [explicit animation](../reference/arkui-ts/ts-explicit-animation.md) capabilities, which can be leveraged to deliver a more engaging experience. + - Animation: ArkTS widgets support the [property animation](../reference/arkui-ts/ts-animatorproperty.md) and [explicit animation](../reference/arkui-ts/ts-explicit-animation.md) capabilities, which can be leveraged to deliver a more engaging experience. - Custom drawing: ArkTS widgets allow you to draw graphics with the [\](../reference/arkui-ts/ts-components-canvas-canvas.md) component to present information more vividly. - Logic code execution: The capability to run logic code in widgets means that service logic can be self-closed in widgets, expanding the use cases of widgets. diff --git a/en/application-dev/quick-start/Readme-EN.md b/en/application-dev/quick-start/Readme-EN.md index 7e6d0acac8ef49b1d6cb38a294d490c6f9a6144c..518ace9f58af6fc85388ab6e21f1eea36753a5b9 100644 --- a/en/application-dev/quick-start/Readme-EN.md +++ b/en/application-dev/quick-start/Readme-EN.md @@ -2,7 +2,7 @@ - Getting Started - [Before You Start](start-overview.md) - - [Getting Started with ArkTS in Stage Model](start-with-ets-stage.md) + - [Building the First ArkTS Application in Stage Model](start-with-ets-stage.md) - Development Fundamentals - Application Package Fundamentals - [Application Package Overview](application-package-overview.md) @@ -55,6 +55,7 @@ - [\@Styles Decorator: Definition of Resusable Styles](arkts-style.md) - [\@Extend Decorator: Extension of Built-in Components](arkts-extend.md) - [stateStyles Decorator: Polymorphic Style](arkts-statestyles.md) + - [\@AnimatableExtend Decorator: Definition of Animatable Attributes](arkts-animatable-extend.md) - State Management - [State Management Overview](arkts-state-management-overview.md) - Component State Management diff --git a/en/application-dev/quick-start/module-configuration-file.md b/en/application-dev/quick-start/module-configuration-file.md index 60a0baa6a6046da92101a1dcff891a6ed16d774d..5fe815d3e9df1e60501504dab5b38f3b860e9b93 100644 --- a/en/application-dev/quick-start/module-configuration-file.md +++ b/en/application-dev/quick-start/module-configuration-file.md @@ -93,7 +93,6 @@ As shown above, the **module.json5** file contains several tags. | [dependencies](#dependencies)| List of shared libraries on which the current module depends during running.| Object array| Yes (initial value: left empty) | | targetModuleName | Target module of the bundle. The value is a string with a maximum of 31 bytes. It must be unique in the entire application.|String|Yes (if the initial value is used, the target module is not a module with the overlay feature)| | targetPriority | Priority of the module. When **targetModuleName** is set, the module is a module with the overlay feature. The value ranges from 1 to 100.|Number|Yes (initial value: **1**)| -| [proxyDatas(deprecated)](#proxydatasdeprecated) | This API is deprecated since API version 10. You are advised to use **proxydata** instead. List of data proxies provided by the module.| Object array| Yes (initial value: left empty)| | [proxyData](#proxydata) | List of data proxies provided by the module.| Object array| Yes (initial value: left empty)| | isolationMode | Multi-process configuration of the module. The options are as follows:
- **nonisolationFirst**: The module preferentially runs in a non-independent process.
- **isolationFirst**: The module preferentially runs in an independent process.
- **isolationOnly**: The module runs only in an independent process.
- **nonisolationOnly**: The module runs only in non-independent processes.|String|Yes (initial value: **nonisolationFirst**)| | generateBuildHash |Whether the hash value of the HAP or HSP file is generated by the packaging tool. The hash value (if any) is used to determine whether the application needs to be updated when the system is updated in OTA mode but the **versionCode** value of the application remains unchanged.
This tag is enabled only when the **generateBuildHash** tag in the [app.json5](./app-configuration-file.md) file is **false**.**
**NOTE**
This tag applies only to system applications.**|Boolean|Yes (initial value: **false**)| @@ -421,7 +420,7 @@ Example of the **extensionAbilities** structure: ## requestPermissions -The **requestPermissions** tag represents a set of permissions that the application needs to request from the system for running correctly. +The **requestPermissions** tag represents a set of permissions that the application needs to request from the system for running correctly. For details about how to request permissions, see [Applying for Permissions](../security/accesstoken-guidelines.md). > **NOTE** > @@ -738,40 +737,6 @@ Example of the **dependencies** structure: } ``` -## proxyDatas(deprecated) - ->This API is supported since API version 10 and deprecated since API version 10. You are advised to use [proxyData](#proxydata) instead. - -The **proxyDatas** tag provides the list of data proxies provided by the module. It can be configured only for entry and feature modules. - -**Table 21** proxyDatas -| Name | Description | Data Type| Initial Value Allowed| -| ----------- | ------------------------------ | -------- | ---------- | -| uri | URI of the data proxy. The URIs configured for different data proxies must be unique and must be in the *datashareproxy://Current application package name/xxx* format. | String | No| -| requiredReadPermission | Permission required for reading data from the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| -| requiredWritePermission | Permission required for writing data to the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| -| [metadata](#metadata)| Metadata of the data proxy. Only the **name** and **resource** fields can be configured.| Object| Yes (initial value: left empty)| - -Example of the **proxyDatas** structure: - -```json -{ - "module": { - "proxyDatas": [ - { - "uri":"datashareproxy://com.ohos.datashare/event/Meeting", - "requiredReadPermission": "ohos.permission.GET_BUNDLE_INFO", - "requiredWritePermission": "ohos.permission.GET_BUNDLE_INFO", - "metadata": { - "name": "datashare_metadata", - "resource": "$profile:datashare" - } - } - ] - } -} -``` - ## proxyData The **proxyDatas** tag provides the list of data proxies provided by the module. It can be configured only for entry and feature modules. @@ -780,8 +745,8 @@ The **proxyDatas** tag provides the list of data proxies provided by the module. | Name | Description | Data Type| Initial Value Allowed| | ----------- | ------------------------------ | -------- | ---------- | | uri | URI of the data proxy. The URIs configured for different data proxies must be unique and must be in the *datashareproxy://Current application package name/xxx* format. | String | No| -| requiredReadPermission | Permission required for reading data from the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| -| requiredWritePermission | Permission required for writing data to the data proxy. For non-system applications, this field is mandatory, and the permission level must be system_basic or system_core. For system applications, this field is optional, and the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| +| requiredReadPermission | Permission required for reading data from the data proxy. If it is not specified, other applications will not be able to use the data proxy. For non-system applications, the level of the set permission must be system_basic or system_core. For system applications, the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| +| requiredWritePermission | Permission required for writing data to the data proxy. If it is not specified, other applications will not be able to use the data proxy. For non-system applications, the level of the set permission must be system_basic or system_core. For system applications, the permission level is not limited. For details about the permission level, see [Application Permission List](../security/permission-list.md).| String | Yes (initial value: left empty)| | [metadata](#metadata)| Metadata of the data proxy. Only the **name** and **resource** fields can be configured.| Object| Yes (initial value: left empty)| Example of the **proxyData** structure: diff --git a/en/application-dev/quick-start/start-overview.md b/en/application-dev/quick-start/start-overview.md index 2bc53666dce570f5c9c5c9c5a0b8c48e353422d2..df1178706cc93fac75f9f443dcff2627b026b9c8 100644 --- a/en/application-dev/quick-start/start-overview.md +++ b/en/application-dev/quick-start/start-overview.md @@ -44,4 +44,4 @@ To help you better understand the preceding basic concepts and application devel 2. Install DevEco Studio and configure the development environment. For details, see [Setting Up the Development Environment](https://developer.harmonyos.com/en/docs/documentation/doc-guides-V3/environment_config-0000001052902427-V3). -When you are done, follow the instructions in [Getting Started with ArkTS in Stage Model](start-with-ets-stage.md). +When you are done, you can set out to [build your first ArkTS application in the stage model](start-with-ets-stage.md). diff --git a/en/application-dev/quick-start/start-with-ets-stage.md b/en/application-dev/quick-start/start-with-ets-stage.md index ec3ab196bb1d0edb494d2a26be688b4b455a714a..789f4c05e28730d4f2851fc507af6bc4a8af1d9b 100644 --- a/en/application-dev/quick-start/start-with-ets-stage.md +++ b/en/application-dev/quick-start/start-with-ets-stage.md @@ -1,4 +1,4 @@ -# Getting Started with ArkTS in Stage Model +# Building the First ArkTS Application in Stage Model > **NOTE** diff --git a/en/application-dev/reference/arkui-ts/Readme-EN.md b/en/application-dev/reference/arkui-ts/Readme-EN.md index e0820748c9835894107fc01fa549602fca25a9b5..dc797984418a04ea512fedca19380592545a3bea 100644 --- a/en/application-dev/reference/arkui-ts/Readme-EN.md +++ b/en/application-dev/reference/arkui-ts/Readme-EN.md @@ -164,8 +164,8 @@ - Advanced Components - [@ohos.multimedia.avCastPicker (AVCastPicker)](ohos-multimedia-avcastpicker.md) - Animation - - [AnimatorProperty](ts-animatorproperty.md) - - [Explicit Animatio](ts-explicit-animation.md) + - [Property Animation](ts-animatorproperty.md) + - [Explicit Animation](ts-explicit-animation.md) - Transition Animation - [Page Transition](ts-page-transition-animation.md) - [Component Transition](ts-transition-animation-component.md) diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001174422896.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001174422896.gif new file mode 100644 index 0000000000000000000000000000000000000000..65dce0858d00df7ce62b578ce8de8b3f153d006e Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001174422896.gif differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001219982726.png b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001219982726.png new file mode 100644 index 0000000000000000000000000000000000000000..5cd212a78358d5443699725e6a963514768cb9e6 Binary files /dev/null and b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001219982726.png differ diff --git a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001256978381.gif b/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001256978381.gif deleted file mode 100644 index 1cd6ff13714a55e253e9649c007080b47f02f791..0000000000000000000000000000000000000000 Binary files a/en/application-dev/reference/arkui-ts/figures/en-us_image_0000001256978381.gif and /dev/null differ diff --git a/en/application-dev/reference/arkui-ts/ts-animatorproperty.md b/en/application-dev/reference/arkui-ts/ts-animatorproperty.md index 00095beb0f5a5739de8a9ab62da63a1807e475c5..ddc44429c9b5c501af18ace6b65806d776df2942 100644 --- a/en/application-dev/reference/arkui-ts/ts-animatorproperty.md +++ b/en/application-dev/reference/arkui-ts/ts-animatorproperty.md @@ -1,12 +1,12 @@ -# Property Animator +# Property Animation -You can create a property animator to animate certain universal attributes of a component, including **width**, **height**, **backgroundColor**, **opacity**, **scale**, **rotate**, and **translate**. +You can animate certain properties of a component, including **width**, **height**, **backgroundColor**, **opacity**, **scale**, **rotate**, and **translate**. > **NOTE** > > This event is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. -animation(value: {duration?: number, tempo?: number, curve?: string | Curve | ICurve, delay?:number, iterations: number, playMode?: PlayMode, onFinish?: () => void}) +animation(value: {duration?: number, tempo?: number, curve?: string | Curve | ICurve, delay?:number, iterations?: number, playMode?: PlayMode, onFinish?: () => void}) Since API version 9, this API is supported in ArkTS widgets. diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md b/en/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md index e3681f6afdac7edc34bed701c1905c30857480d8..1c145a93206ecf99984346c0833750bda113d5cf 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md @@ -44,16 +44,16 @@ Since API version 9, this API is supported in ArkTS widgets. In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. -| Name | Type| Mandatory| Description| -| ------------- | ------- | ---- | -------- | -| closeEffect | boolean | Yes| Whether to disable the rotation and shadow effects for the component.
Default value: **false**
**NOTE**
This attribute enables or disables the shadow effect only when **trackShadow** is not set.
The shadow effect enabled through this attribute is in the default style.| -| valueColors10+ | Array<[ResourceColor](ts-types.md#resourcecolor) \| [LinearGradient](#lineargradient10)> | Yes| Array of data segment colors. A value of the **ResourceColor** type indicates a solid color, and A value of the **LinearGradient** type indicates a color gradient.| -| trackBackgroundColor10+ | [ResourceColor](ts-types.md#resourcecolor) | Yes| Background color.
The value is in hexadecimal ARGB notation. The first two digits indicate opacity.
Default value: **'#08182431'**| -| strokeWidth10+ | [Length](ts-types.md#Length) | Yes| Stroke width of the border.
Default value: **24**
Unit: vp
**NOTE**
A value less than 0 evaluates to the default value.
This attribute does not take effect when the data panel type is **DataPanelType.Line**.| -| trackShadow10+ | [DataPanelShadowOption](#datapanelshadowoption10) | Yes| Shadow style.
**NOTE**
If this attribute is set to **null**, the shadow effect is disabled.| +| Name | Type| Description| +| ------------- | ------- | -------- | +| closeEffect | boolean | Whether to disable the rotation and shadow effects for the component.
Default value: **false**
**NOTE**
This attribute enables or disables the shadow effect only when **trackShadow** is not set.
The shadow effect enabled through this attribute is in the default style.| +| valueColors10+ | Array<[ResourceColor](ts-types.md#resourcecolor) \| [LinearGradient](#lineargradient10)> | Array of data segment colors. A value of the **ResourceColor** type indicates a solid color, and A value of the **LinearGradient** type indicates a color gradient.| +| trackBackgroundColor10+ | [ResourceColor](ts-types.md#resourcecolor) | Background color.
The value is in hexadecimal ARGB notation. The first two digits indicate opacity.
Default value: **'#08182431'**| +| strokeWidth10+ | [Length](ts-types.md#Length) | Stroke width of the border.
Default value: **24**
Unit: vp
**NOTE**
A value less than 0 evaluates to the default value.
This attribute does not take effect when the data panel type is **DataPanelType.Line**.| +| trackShadow10+ | [DataPanelShadowOptions](#datapanelshadowoptions10) | Shadow style.
**NOTE**
If this attribute is set to **null**, the shadow effect is disabled.| -## DataPanelShadowOption10+ +## DataPanelShadowOptions10+ | Name | Type| Mandatory| Description| | ------------- | ------- | ---- | -------- | | radius | number \| [Resource](ts-types.md#resource)| No| Shadow blur radius.
Default value: **5**
Unit: vp
**NOTE**
A value less than or equal to 0 evaluates to the default value.| diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-imagespan.md b/en/application-dev/reference/arkui-ts/ts-basic-components-imagespan.md index db8fbb1fa0a3e809409aa4afba07eb7696fc539c..9cfb2b31661b0ed834c68aeff4acce07ae0166c0 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-imagespan.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-imagespan.md @@ -25,11 +25,11 @@ ImageSpan(value: ResourceStr | PixelMap) ## Attributes -Among all the [universal events](ts-universal-attributes-size.md), only **width**, **height**, and **size** are supported. +The [universal attribute](ts-universal-attributes-size.md) methods can be used to set the size, background, and border. | Name| Type| Description| | -------- | -------- | -------- | -| verticalAlign | [ImageSpanAlignment](#imagespanalignment) | Alignment mode of the image with the text.| +| verticalAlign | [ImageSpanAlignment](#imagespanalignment) | Alignment mode of the image with the text.
Default value: **ImageSpanAlignment.BOTTOM**| | objectFit | [ImageFit](ts-appendix-enums.md#imagefit) | Image scale type.
Default value: **ImageFit.Cover**| ## ImageSpanAlignment @@ -57,7 +57,7 @@ struct SpanExample { Text() { Span('This is the Span and ImageSpan component').fontSize(25).textCase(TextCase.Normal) .decoration({ type: TextDecorationType.None, color: Color.Pink }) - }.width('100%') + }.width('100%').textAlign(TextAlign.Center) Text() { ImageSpan($r('app.media.icon')) .width('200px') @@ -85,7 +85,6 @@ struct SpanExample { .decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(50) } .width('100%') - .backgroundColor(Color.Orange) .textIndent(50) }.width('100%').height('100%').padding({ left: 0, right: 0, top: 0 }) } diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-marquee.md b/en/application-dev/reference/arkui-ts/ts-basic-components-marquee.md index e14c0aee93857ea01cdec4f6e2843b273de28e97..c8b19032cf4bc784fa8159692f076b2d5ddf5a75 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-marquee.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-marquee.md @@ -30,7 +30,7 @@ Since API version 9, this API is supported in ArkTS widgets. | src | string | Yes| Text to scroll.| ## Attributes - +In addition to the universal text attributes **fontColor**, **fontSize**, **fontWeight**, and **fontFamily**, the following attributes are supported. | Name | Type| Description | | ---------- | -------- | ------------------------------------------------------------ | | allowScale | boolean | Whether to allow text to scale.
This attribute is not supported currently.
Default value: **false** | diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-richeditor.md b/en/application-dev/reference/arkui-ts/ts-basic-components-richeditor.md index d69ec2a9e833bec992c52ccd759519d131145487..23d1dd164423c71f692e07fe8600a791f94466e7 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-richeditor.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-richeditor.md @@ -1,6 +1,6 @@ # RichEditor -The \ is a component that supports interactive text editing and mixture of text and imagery. +The **\** is a component that supports interactive text editing and mixture of text and imagery. > **NOTE** > @@ -114,7 +114,7 @@ Provides the image span style information returned by the backend. | ------ | -------- | ---- | -------------------------------------- | | size | [number, number] | Yes| Width and height of the image.| | verticalAlign | [ImageSpanAlignment](ts-basic-components-imagespan.md#imagespanalignment) | Yes | Vertical alignment mode of the image.| -| objectFit | [ImageFit]((ts-basic-components-imagespan.md#imagefit)) | Yes| Scale mode of the image.| +| objectFit | [ImageFit](ts-basic-components-imagespan.md#imagefit) | Yes| Scale mode of the image.| ## RichEditorOptions @@ -158,7 +158,7 @@ Sets the cursor position. | Name| Type| Mandatory| Description | | ------ | -------- | ---- | -------------------------------------- | -| offset | number | Yes| Offset of the cursor.| +| offset | number | Yes| Offset of the cursor. If the value is out of the text range, the setting fails.| **Return value** @@ -265,8 +265,8 @@ Defines the text span style options. | Name| Type| Mandatory| Description | | ------ | -------- | ---- | -------------------------------------- | -| start | number | No| Start position of the text span whose style needs to be updated. If this parameter is omitted, the value **0** will be used.| -| end | number | No| End position of the text span whose style needs to be updated. If this parameter is omitted, it indicates the end of the text span.| +| start | number | No| Start position of the text span whose style needs to be updated. If this parameter is omitted or set to a negative value, the value **0** will be used.| +| end | number | No| End position of the text span whose style needs to be updated. If this parameter is omitted or set to a value beyond the text range, it indicates the end of the text span.| | textStyle | [RichEditorTextStyle](#richeditortextstyle) | Yes| Text style.| @@ -276,8 +276,8 @@ Defines the image span style options. | Name| Type| Mandatory| Description | | ------ | -------- | ---- | -------------------------------------- | -| start | number | No| Start position of the image span whose style needs to be updated. If this parameter is omitted, the value **0** will be used.| -| end | number | No| End position of the image span whose style needs to be updated. If this parameter is omitted, it indicates the end of the image span.| +| start | number | No| Start position of the image span whose style needs to be updated. If this parameter is omitted or set to a negative value, the value **0** will be used.| +| end | number | No| End position of the image span whose style needs to be updated. If this parameter is omitted or set to a value beyond the text range, it indicates the end of the image span.| | imageStyle | [RichEditorImageSpanStyle](#richeditorimagespanstyle) | Yes| Image style.| @@ -296,12 +296,12 @@ Provides the text style information. | Name| Type| Mandatory| Description | | ------ | -------- | ---- | -------------------------------------- | -| fontColor | [ResourceColor](ts-types.md#resourcecolor) | No| Font color.| -| fontSize | [Length](ts-types.md#length) \| number | No| Font size.| -| fontStyle | [FontStyle](ts-appendix-enums.md#fontstyle) | No| Font style.| -| fontWeight | [FontWeight](ts-appendix-enums.md#fontweight) \| number \| string | No| Font weight.| -| fontFamily | [ResourceStr](ts-types.md#resourcestr) \| number \| string | No| Font family. Default value: **'HarmonyOS Sans'**.
Currently, only the default font is supported.| -| decoration | {
type: [TextDecorationType](ts-appendix-enums.md#textdecorationtype),
color?: [ResourceColor](ts-types.md#resourcecolor)
} \| number \| string | No| Style and color of the text decorative line.| +| fontColor | [ResourceColor](ts-types.md#resourcecolor) | No| Font color.
Default value: **Color.Black**| +| fontSize | [Length](ts-types.md#length) \| number | No| Font size.
Default value: **16fp**| +| fontStyle | [FontStyle](ts-appendix-enums.md#fontstyle) | No| Font style.
Default value: **FontStyle.Normal**| +| fontWeight | [FontWeight](ts-appendix-enums.md#fontweight) \| number \| string | No| Font weight.
Default value: **FontWeight.Normal**| +| fontFamily | [ResourceStr](ts-types.md#resourcestr) \| number \| string | No| Font family. Default value: **'HarmonyOS Sans'**.
Currently, only the default font is supported.
Default font: **'HarmonyOS Sans'**| +| decoration | {
type: [TextDecorationType](ts-appendix-enums.md#textdecorationtype),
color?: [ResourceColor](ts-types.md#resourcecolor)
} | No| Style and color of the text decorative line.
Default value: {
type: TextDecorationType.None,
color: Color.Black
}| ## RichEditorImageSpanOptions @@ -320,8 +320,8 @@ Provides the image span style information. | Name| Type| Mandatory| Description | | ------ | -------- | ---- | -------------------------------------- | | size | [Dimension, Dimension] | No| Width and height of the image.| -| verticalAlign | [ImageSpanAlignment](ts-basic-components-imagespan.md#imagespanalignment) | No | Vertical alignment mode of the image.| -| objectFit | [ImageFit]((ts-basic-components-imagespan.md#imagefit)) | No| Scale mode of the image.| +| verticalAlign | [ImageSpanAlignment](ts-basic-components-imagespan.md#imagespanalignment) | No | Vertical alignment mode of the image.
Default value: **ImageSpanAlignment.BASELINE**| +| objectFit | [ImageFit](ts-appendix-enums.md#imagefit) | No| Scale mode of the image.
Default value: **ImageFit.Cover**| ## RichEditorRange @@ -329,8 +329,8 @@ Provides the span range information. | Name| Type| Mandatory| Description | | ------ | -------- | ---- | -------------------------------------- | -| start | number | No| Start position. If this parameter is omitted, the value **0** will be used.| -| end | number | No| End position. If this parameter is omitted, it indicates the very end.| +| start | number | No| Start position. If this parameter is omitted or set to a negative value, the value **0** will be used.| +| end | number | No| End position of the image span whose style needs to be updated. If this parameter is omitted or set to a value beyond the text range, it indicates the very end.| ## Example diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-richtext.md b/en/application-dev/reference/arkui-ts/ts-basic-components-richtext.md index 6ab3c683bb77721868f160850eba311054ed5c5c..e7093230c1146b5c18238ea115189f13ce8de2cf 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-richtext.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-richtext.md @@ -52,6 +52,19 @@ Among the [universal attributes](ts-universal-attributes-size.md), only the **wi | style | Defines the inline style of an element and is placed inside the tag. Use quotation marks (') to separate the styling text and use semicolons (;) to separate styles, for example, **style='width: 500px;height: 500px;border: 1px solid;margin: 0 auto;'**.| \

This is a heading\

\

This is text\

| | \ | Embeds or references a client-side script, such as JavaScript.| \ | + +## Precautions + +The underlying layer of the **\** component uses the **\** component to provide basic capabilities, including but not limited to HTML page parsing and rendering. However, the **\** component is resources consuming. In scenarios where the **\** component is repeatedly used, for example, when it is repeatedly used in a list, frame freezing or slow response may occur. + +The **\** component complies with the constraints of the **\** component. A typical scenario is as follows: + +The default viewport size of a mobile device is 980 px. This default value ensures that most web pages can be browsed properly on the mobile device. If the width of the **\** component is less than this value, the HTML content specified by **content** may generate a scrollable page that is wrapped by the **\** component. If you want to replace the default value, add the following tags to **content**: + +```html + +``` + ## Example You can preview how this component looks on a real device. The preview is not yet available in the DevEco Studio Previewer. @@ -83,7 +96,7 @@ struct RichTextExample { console.info('RichText onComplete'); }) .width(500) - .height(400) + .height(500) .backgroundColor(0XBDDB69) RichText('layoutWeight(1)') .onStart(() => { @@ -111,7 +124,3 @@ struct RichTextExample { ``` ![richText](figures/richText.png) - -## Precautions - -The underlying layer of the **\** component reuses the **\** component to provide basic capabilities, including but not limited to HTML page parsing and rendering. However, the **\** component is resources consuming. In scenarios where the **\** component is repeatedly used, for example, when it is repeatedly used in a list, frame freezing or slow response may occur. diff --git a/en/application-dev/reference/arkui-ts/ts-container-panel.md b/en/application-dev/reference/arkui-ts/ts-container-panel.md index 395f32d6e9ec42c8578e76084631319f935be6b9..b0359c645851f1e28e8f3ab8a3371d3f501df89d 100644 --- a/en/application-dev/reference/arkui-ts/ts-container-panel.md +++ b/en/application-dev/reference/arkui-ts/ts-container-panel.md @@ -103,4 +103,4 @@ struct PanelExample { } ``` -![en-us_image_0000001256978381](figures/en-us_image_0000001256978381.gif) +![en-us_image_0000001174422896](figures/en-us_image_0000001174422896.gif) diff --git a/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md b/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md index 1ba996fc0ef670359687c3e94bb6cadf704f92c5..0b61ab7aa573d325cbcc563e584313aebea45085 100644 --- a/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md +++ b/en/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md @@ -33,7 +33,7 @@ Since API version 9, this API is supported in ArkTS widgets. | [lineCap](#linecap) | CanvasLineCap | Style of the line endpoints. The options are as follows:
- **butt**: The endpoints of the line are squared off.
- **round**: The endpoints of the line are rounded.
- **square**: The endpoints of the line are squared off, and each endpoint has added a rectangle whose length is the same as the line thickness and whose width is half of the line thickness.
- Default value: **'butt'**
Since API version 9, this API is supported in ArkTS widgets.| | [lineJoin](#linejoin) | CanvasLineJoin | Style of the shape used to join line segments. The options are as follows:
- **round**: The intersection is a sector, whose radius at the rounded corner is equal to the line width.
- **bevel**: The intersection is a triangle. The rectangular corner of each line is independent.
- **miter**: The intersection has a miter corner by extending the outside edges of the lines until they meet. You can view the effect of this attribute in **miterLimit**.
- Default value: **'miter'**
Since API version 9, this API is supported in ArkTS widgets.| | [miterLimit](#miterlimit) | number | Maximum miter length. The miter length is the distance between the inner corner and the outer corner where two lines meet.
- Default value: **10**
Since API version 9, this API is supported in ArkTS widgets.| -| [font](#font) | string | Font style.
Syntax: ctx.font='font-size font-family'
- (Optional) **font-size**: font size and row height. The unit can only be pixels.
(Optional) **font-family**: font family.
Syntax: ctx.font='font-style font-weight font-size font-family'
- (Optional) **font-style**: font style. Available values are **normal** and **italic**.
- (Optional) **font-weight**: font weight. Available values are as follows: **normal**, **bold**, **bolder**, **lighter**, **100**, **200**, **300**, **400**, **500**, **600**, **700**, **800**, **900**.
- (Optional) **font-size**: font size and line height. The unit must be specified and can only be px or vp.
- (Optional) **font-family**: font family. Available values are **sans-serif**, **serif**, and **monospace**.
Default value: **'normal normal 14px sans-serif'**
Since API version 9, this API is supported in ArkTS widgets.| +| [font](#font) | string | Font style.
Syntax: ctx.font='font-size font-family'
- (Optional) **font-size**: font size and line height. The unit can only be pixels.
(Optional) **font-family**: font family.
Syntax: ctx.font='font-style font-weight font-size font-family'
- (Optional) **font-style**: font style. Available values are **normal** and **italic**.
- (Optional) **font-weight**: font weight. Available values are as follows: **normal**, **bold**, **bolder**, **lighter**, **100**, **200**, **300**, **400**, **500**, **600**, **700**, **800**, **900**.
- (Optional) **font-size**: font size and line height. The unit can be px or vp and must be specified.
- (Optional) **font-family**: font family. Available values are **sans-serif**, **serif**, and **monospace**.
Default value: **'normal normal 14px sans-serif'**
Since API version 9, this API is supported in ArkTS widgets.| | [textAlign](#textalign) | CanvasTextAlign | Text alignment mode. Available values are as follows:
- **left**: The text is left-aligned.
- **right**: The text is right-aligned.
- **center**: The text is center-aligned.
- **start**: The text is aligned with the start bound.
- **end**: The text is aligned with the end bound.
**NOTE**

In the **ltr** layout mode, the value **'start'** equals **'left'**. In the **rtl** layout mode, the value **'start'** equals **'right'**.
- Default value: **'left'**
Since API version 9, this API is supported in ArkTS widgets.| | [textBaseline](#textbaseline) | CanvasTextBaseline | Horizontal alignment mode of text. Available values are as follows:
- **alphabetic**: The text baseline is the normal alphabetic baseline.
- **top**: The text baseline is on the top of the text bounding box.
- **hanging**: The text baseline is a hanging baseline over the text.
- **middle**: The text baseline is in the middle of the text bounding box.
**'ideographic'**: The text baseline is the ideographic baseline. If a character exceeds the alphabetic baseline, the ideographic baseline is located at the bottom of the excess character.
- **bottom**: The text baseline is at the bottom of the text bounding box. Its difference from the ideographic baseline is that the ideographic baseline does not consider letters in the next line.
- Default value: **'alphabetic'**
Since API version 9, this API is supported in ArkTS widgets.| | [globalAlpha](#globalalpha) | number | Opacity.
**0.0**: completely transparent.
**1.0**: completely opaque. | @@ -61,7 +61,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct FillStyleExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -70,9 +70,41 @@ struct FillStyleExample { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillStyle = '#0000ff' - this.offContext.fillRect(20, 20, 150, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = '#0000ff' + offContext.fillRect(20, 20, 150, 100) + var image = this.offCanvas.transferToImageBitmap() + this.context.transferFromImageBitmap(image) + }) + } + .width('100%') + .height('100%') + } +} +``` + + + +```ts +// xxx.ets +@Entry +@Component +struct FillStyleExample { + private settings: RenderingContextSettings = new RenderingContextSettings(true) + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Canvas(this.context) + .width('100%') + .height('100%') + .backgroundColor('#ffff00') + .onReady(() =>{ + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = 0x0000FF + offContext.fillRect(20, 20, 150, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -94,7 +126,7 @@ struct FillStyleExample { struct LineWidthExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -103,9 +135,10 @@ struct LineWidthExample { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.lineWidth = 5 - this.offContext.strokeRect(25, 25, 85, 105) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.lineWidth = 5 + offContext.strokeRect(25, 25, 85, 105) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -127,7 +160,7 @@ struct LineWidthExample { struct StrokeStyleExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -136,10 +169,43 @@ struct StrokeStyleExample { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.lineWidth = 10 - this.offContext.strokeStyle = '#0000ff' - this.offContext.strokeRect(25, 25, 155, 105) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.lineWidth = 10 + offContext.strokeStyle = '#0000ff' + offContext.strokeRect(25, 25, 155, 105) + var image = this.offCanvas.transferToImageBitmap() + this.context.transferFromImageBitmap(image) + }) + } + .width('100%') + .height('100%') + } +} +``` + + + +```ts +// xxx.ets +@Entry +@Component +struct StrokeStyleExample { + private settings: RenderingContextSettings = new RenderingContextSettings(true) + private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Canvas(this.context) + .width('100%') + .height('100%') + .backgroundColor('#ffff00') + .onReady(() =>{ + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.lineWidth = 10 + offContext.strokeStyle = 0x0000ff + offContext.strokeRect(25, 25, 155, 105) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -161,7 +227,7 @@ struct StrokeStyleExample { struct LineCapExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -170,13 +236,14 @@ struct LineCapExample { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.lineWidth = 8 - this.offContext.beginPath() - this.offContext.lineCap = 'round' - this.offContext.moveTo(30, 50) - this.offContext.lineTo(220, 50) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.lineWidth = 8 + offContext.beginPath() + offContext.lineCap = 'round' + offContext.moveTo(30, 50) + offContext.lineTo(220, 50) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -198,7 +265,7 @@ struct LineCapExample { struct LineJoinExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -207,14 +274,15 @@ struct LineJoinExample { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.lineWidth = 8 - this.offContext.lineJoin = 'miter' - this.offContext.moveTo(30, 30) - this.offContext.lineTo(120, 60) - this.offContext.lineTo(30, 110) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.lineWidth = 8 + offContext.lineJoin = 'miter' + offContext.moveTo(30, 30) + offContext.lineTo(120, 60) + offContext.lineTo(30, 110) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -236,7 +304,7 @@ struct LineJoinExample { struct MiterLimit { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -245,14 +313,15 @@ struct MiterLimit { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.lineWidth = 8 - this.offContext.lineJoin = 'miter' - this.offContext.miterLimit = 3 - this.offContext.moveTo(30, 30) - this.offContext.lineTo(60, 35) - this.offContext.lineTo(30, 37) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.lineWidth = 8 + offContext.lineJoin = 'miter' + offContext.miterLimit = 3 + offContext.moveTo(30, 30) + offContext.lineTo(60, 35) + offContext.lineTo(30, 37) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -274,7 +343,7 @@ struct MiterLimit { struct Fonts { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -283,9 +352,10 @@ struct Fonts { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.font = '30px sans-serif' - this.offContext.fillText("Hello World", 20, 60) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.font = '30px sans-serif' + offContext.fillText("Hello World", 20, 60) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -307,7 +377,7 @@ struct Fonts { struct CanvasExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -316,24 +386,25 @@ struct CanvasExample { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.strokeStyle = '#0000ff' - this.offContext.moveTo(140, 10) - this.offContext.lineTo(140, 160) - this.offContext.stroke() - - this.offContext.font = '18px sans-serif' - - this.offContext.textAlign = 'start' - this.offContext.fillText('textAlign=start', 140, 60) - this.offContext.textAlign = 'end' - this.offContext.fillText('textAlign=end', 140, 80) - this.offContext.textAlign = 'left' - this.offContext.fillText('textAlign=left', 140, 100) - this.offContext.textAlign = 'center' - this.offContext.fillText('textAlign=center',140, 120) - this.offContext.textAlign = 'right' - this.offContext.fillText('textAlign=right',140, 140) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.strokeStyle = '#0000ff' + offContext.moveTo(140, 10) + offContext.lineTo(140, 160) + offContext.stroke() + + offContext.font = '18px sans-serif' + + offContext.textAlign = 'start' + offContext.fillText('textAlign=start', 140, 60) + offContext.textAlign = 'end' + offContext.fillText('textAlign=end', 140, 80) + offContext.textAlign = 'left' + offContext.fillText('textAlign=left', 140, 100) + offContext.textAlign = 'center' + offContext.fillText('textAlign=center',140, 120) + offContext.textAlign = 'right' + offContext.fillText('textAlign=right',140, 140) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -355,7 +426,7 @@ struct CanvasExample { struct TextBaseline { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -364,24 +435,25 @@ struct TextBaseline { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.strokeStyle = '#0000ff' - this.offContext.moveTo(0, 120) - this.offContext.lineTo(400, 120) - this.offContext.stroke() - - this.offContext.font = '20px sans-serif' - - this.offContext.textBaseline = 'top' - this.offContext.fillText('Top', 10, 120) - this.offContext.textBaseline = 'bottom' - this.offContext.fillText('Bottom', 55, 120) - this.offContext.textBaseline = 'middle' - this.offContext.fillText('Middle', 125, 120) - this.offContext.textBaseline = 'alphabetic' - this.offContext.fillText('Alphabetic', 195, 120) - this.offContext.textBaseline = 'hanging' - this.offContext.fillText('Hanging', 295, 120) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.strokeStyle = '#0000ff' + offContext.moveTo(0, 120) + offContext.lineTo(400, 120) + offContext.stroke() + + offContext.font = '20px sans-serif' + + offContext.textBaseline = 'top' + offContext.fillText('Top', 10, 120) + offContext.textBaseline = 'bottom' + offContext.fillText('Bottom', 55, 120) + offContext.textBaseline = 'middle' + offContext.fillText('Middle', 125, 120) + offContext.textBaseline = 'alphabetic' + offContext.fillText('Alphabetic', 195, 120) + offContext.textBaseline = 'hanging' + offContext.fillText('Hanging', 295, 120) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -403,7 +475,7 @@ struct TextBaseline { struct GlobalAlpha { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -412,12 +484,13 @@ struct GlobalAlpha { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(0, 0, 50, 50) - this.offContext.globalAlpha = 0.4 - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(50, 50, 50, 50) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(0, 0, 50, 50) + offContext.globalAlpha = 0.4 + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(50, 50, 50, 50) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -439,7 +512,7 @@ struct GlobalAlpha { struct LineDashOffset { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -448,11 +521,12 @@ struct LineDashOffset { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.arc(100, 75, 50, 0, 6.28) - this.offContext.setLineDash([10,20]) - this.offContext.lineDashOffset = 10.0 - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.arc(100, 75, 50, 0, 6.28) + offContext.setLineDash([10,20]) + offContext.lineDashOffset = 10.0 + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -488,7 +562,7 @@ struct LineDashOffset { struct GlobalCompositeOperation { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -497,17 +571,18 @@ struct GlobalCompositeOperation { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(20, 20, 50, 50) - this.offContext.globalCompositeOperation = 'source-over' - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(50, 50, 50, 50) - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(120, 20, 50, 50) - this.offContext.globalCompositeOperation = 'destination-over' - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(150, 50, 50, 50) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(20, 20, 50, 50) + offContext.globalCompositeOperation = 'source-over' + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(50, 50, 50, 50) + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(120, 20, 50, 50) + offContext.globalCompositeOperation = 'destination-over' + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(150, 50, 50, 50) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -529,7 +604,7 @@ struct GlobalCompositeOperation { struct ShadowBlur { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -538,11 +613,12 @@ struct ShadowBlur { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.shadowBlur = 30 - this.offContext.shadowColor = 'rgb(0,0,0)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(20, 20, 100, 80) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.shadowBlur = 30 + offContext.shadowColor = 'rgb(0,0,0)' + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(20, 20, 100, 80) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -564,7 +640,7 @@ struct ShadowBlur { struct ShadowColor { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -573,11 +649,12 @@ struct ShadowColor { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.shadowBlur = 30 - this.offContext.shadowColor = 'rgb(0,0,255)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(30, 30, 100, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.shadowBlur = 30 + offContext.shadowColor = 'rgb(0,0,255)' + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(30, 30, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -599,7 +676,7 @@ struct ShadowColor { struct ShadowOffsetX { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -608,12 +685,13 @@ struct ShadowOffsetX { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.shadowBlur = 10 - this.offContext.shadowOffsetX = 20 - this.offContext.shadowColor = 'rgb(0,0,0)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(20, 20, 100, 80) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.shadowBlur = 10 + offContext.shadowOffsetX = 20 + offContext.shadowColor = 'rgb(0,0,0)' + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(20, 20, 100, 80) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -635,7 +713,7 @@ struct ShadowOffsetX { struct ShadowOffsetY { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -644,12 +722,13 @@ struct ShadowOffsetY { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.shadowBlur = 10 - this.offContext.shadowOffsetY = 20 - this.offContext.shadowColor = 'rgb(0,0,0)' - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(30, 30, 100, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.shadowBlur = 10 + offContext.shadowOffsetY = 20 + offContext.shadowColor = 'rgb(0,0,0)' + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(30, 30, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -672,7 +751,7 @@ struct ImageSmoothingEnabled { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -681,9 +760,10 @@ struct ImageSmoothingEnabled { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.imageSmoothingEnabled = false - this.offContext.drawImage( this.img,0,0,400,200) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.imageSmoothingEnabled = false + offContext.drawImage(this.img,0,0,400,200) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -725,7 +805,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct FillRect { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -734,8 +814,9 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillRect(30,30,100,100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillRect(30,30,100,100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -774,7 +855,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct StrokeRect { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -783,8 +864,9 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.strokeRect(30, 30, 200, 150) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.strokeRect(30, 30, 200, 150) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -823,7 +905,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct ClearRect { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -832,10 +914,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(20,20,200,200) - this.offContext.clearRect(30,30,150,100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(20,20,200,200) + offContext.clearRect(30,30,150,100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -874,7 +957,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct FillText { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -883,9 +966,10 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.font = '30px sans-serif' - this.offContext.fillText("Hello World!", 20, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.font = '30px sans-serif' + offContext.fillText("Hello World!", 20, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -924,7 +1008,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct StrokeText { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -933,9 +1017,10 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.font = '55px sans-serif' - this.offContext.strokeText("Hello World!", 20, 60) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.font = '55px sans-serif' + offContext.strokeText("Hello World!", 20, 60) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -995,7 +1080,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct MeasureText { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1004,10 +1089,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.font = '50px sans-serif' - this.offContext.fillText("Hello World!", 20, 100) - this.offContext.fillText("width:" + this.context.measureText("Hello World!").width, 20, 200) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.font = '50px sans-serif' + offContext.fillText("Hello World!", 20, 100) + offContext.fillText("width:" + this.context.measureText("Hello World!").width, 20, 200) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1043,7 +1129,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Stroke { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1052,13 +1138,14 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.moveTo(25, 25) - this.offContext.lineTo(25, 105) - this.offContext.lineTo(75, 105) - this.offContext.lineTo(75, 25) - this.offContext.strokeStyle = 'rgb(0,0,255)' - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.moveTo(25, 25) + offContext.lineTo(25, 105) + offContext.lineTo(75, 105) + offContext.lineTo(75, 25) + offContext.strokeStyle = 'rgb(0,0,255)' + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1088,7 +1175,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct BeginPath { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1097,13 +1184,14 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.lineWidth = 6 - this.offContext.strokeStyle = '#0000ff' - this.offContext.moveTo(15, 80) - this.offContext.lineTo(280, 160) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.lineWidth = 6 + offContext.strokeStyle = '#0000ff' + offContext.moveTo(15, 80) + offContext.lineTo(280, 160) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1140,7 +1228,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct MoveTo { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1149,11 +1237,12 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(10, 10) - this.offContext.lineTo(280, 160) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.moveTo(10, 10) + offContext.lineTo(280, 160) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1190,7 +1279,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct LineTo { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1199,11 +1288,12 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(10, 10) - this.offContext.lineTo(280, 160) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.moveTo(10, 10) + offContext.lineTo(280, 160) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1233,7 +1323,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct ClosePath { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1242,13 +1332,14 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(30, 30) - this.offContext.lineTo(110, 30) - this.offContext.lineTo(70, 90) - this.offContext.closePath() - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.moveTo(30, 30) + offContext.lineTo(110, 30) + offContext.lineTo(70, 90) + offContext.closePath() + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1292,7 +1383,7 @@ Since API version 9, this API is supported in ArkTS widgets. private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1301,10 +1392,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - var pattern = this.offContext.createPattern(this.img, 'repeat') - this.offContext.fillStyle = pattern - this.offContext.fillRect(0, 0, 200, 200) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + var pattern = offContext.createPattern(this.img, 'repeat') + offContext.fillStyle = pattern + offContext.fillRect(0, 0, 200, 200) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1345,7 +1437,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct BezierCurveTo { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1354,11 +1446,12 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(10, 10) - this.offContext.bezierCurveTo(20, 100, 200, 100, 200, 20) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.moveTo(10, 10) + offContext.bezierCurveTo(20, 100, 200, 100, 200, 20) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1397,7 +1490,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct QuadraticCurveTo { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1406,11 +1499,12 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.moveTo(20, 20) - this.offContext.quadraticCurveTo(100, 100, 200, 20) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.moveTo(20, 20) + offContext.quadraticCurveTo(100, 100, 200, 20) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1451,7 +1545,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Arc { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1460,10 +1554,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.arc(100, 75, 50, 0, 6.28) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.arc(100, 75, 50, 0, 6.28) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1503,7 +1598,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct ArcTo { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1512,10 +1607,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.moveTo(100, 20) - this.offContext.arcTo(150, 20, 150, 70, 50) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.moveTo(100, 20) + offContext.arcTo(150, 20, 150, 70, 50) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1558,7 +1654,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct CanvasExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) @@ -1566,10 +1662,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.beginPath() - this.offContext.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI * 2) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.beginPath() + offContext.ellipse(200, 200, 50, 100, Math.PI * 0.25, Math.PI * 0.5, Math.PI * 2) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1608,7 +1705,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct CanvasExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1617,9 +1714,10 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1653,7 +1751,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Fill { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1662,9 +1760,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) - this.offContext.fill() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = '#ffffff' + offContext.rect(20, 20, 100, 100) // Create a 100*100 rectangle at (20, 20) + offContext.fill() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1700,7 +1800,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Fill { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1709,6 +1809,7 @@ struct Fill { .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ + var offContext = this.offCanvas.getContext("2d", this.settings) let region = new Path2D() region.moveTo(30, 90) region.lineTo(110, 20) @@ -1718,9 +1819,9 @@ struct Fill { region.lineTo(270, 90) region.closePath() // Fill path - this.offContext.fillStyle = '#00ff00' - this.offContext.fill(region, "evenodd") - var image = this.offContext.transferToImageBitmap() + offContext.fillStyle = '#00ff00' + offContext.fill(region, "evenodd") + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1757,7 +1858,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Clip { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1766,12 +1867,13 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.rect(0, 0, 100, 200) - this.offContext.stroke() - this.offContext.clip() - this.offContext.fillStyle = "rgb(255,0,0)" - this.offContext.fillRect(0, 0, 200, 200) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.rect(0, 0, 100, 200) + offContext.stroke() + offContext.clip() + offContext.fillStyle = "rgb(255,0,0)" + offContext.fillRect(0, 0, 200, 200) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1806,7 +1908,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Clip { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1815,6 +1917,7 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ + var offContext = this.offCanvas.getContext("2d", this.settings) let region = new Path2D() region.moveTo(30, 90) region.lineTo(110, 20) @@ -1823,10 +1926,10 @@ Since API version 9, this API is supported in ArkTS widgets. region.lineTo(190, 20) region.lineTo(270, 90) region.closePath() - this.offContext.clip(region,"evenodd") - this.offContext.fillStyle = "rgb(0,255,0)" - this.offContext.fillRect(0, 0, 600, 600) - var image = this.offContext.transferToImageBitmap() + offContext.clip(region,"evenodd") + offContext.fillStyle = "rgb(0,255,0)" + offContext.fillRect(0, 0, 600, 600) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1862,7 +1965,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct FilterDemoOff { private settings: RenderingContextSettings = new RenderingContextSettings(true); private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) private img:ImageBitmap = new ImageBitmap("common/images/example.jpg"); build() { @@ -1872,7 +1975,8 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - let offctx = this.offContext + var offContext = this.offCanvas.getContext("2d", this.settings) + let offctx = offContext let img = this.img offctx.drawImage(img, 0, 0, 100, 100); @@ -1904,7 +2008,7 @@ Since API version 9, this API is supported in ArkTS widgets. offctx.filter = 'blur(5px)'; offctx.drawImage(img, 0, 300, 100, 100); - var image = offctx.transferToImageBitmap() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -1917,20 +2021,6 @@ Since API version 9, this API is supported in ArkTS widgets. ![filterDemo](figures/filterDemo.jpeg) -### getTransform - -getTransform(): Matrix2D - -Obtains the current transformation matrix being applied to the context. This API is a void API. - -Since API version 9, this API is supported in ArkTS widgets. - -**Return value** - -| Type | Description | -| ---------------------------------------- | ----- | -| [Matrix2D](ts-components-canvas-matrix2d.md#Matrix2D) | Matrix object.| - ### resetTransform resetTransform(): void @@ -1956,7 +2046,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct DirectionDemoOff { private settings: RenderingContextSettings = new RenderingContextSettings(true); private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -1965,7 +2055,8 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - let offctx = this.offContext + var offContext = this.offCanvas.getContext("2d", this.settings) + let offctx = offContext offctx.font = '48px serif'; offctx.textAlign = 'start' offctx.fillText("Hi ltr!", 200, 50); @@ -2010,7 +2101,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Rotate { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2019,9 +2110,10 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.rotate(45 * Math.PI / 180) - this.offContext.fillRect(70, 20, 50, 50) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.rotate(45 * Math.PI / 180) + offContext.fillRect(70, 20, 50, 50) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2058,7 +2150,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Scale { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2067,11 +2159,12 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.lineWidth = 3 - this.offContext.strokeRect(30, 30, 50, 50) - this.offContext.scale(2, 2) // Scale to 200% - this.offContext.strokeRect(30, 30, 50, 50) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.lineWidth = 3 + offContext.strokeRect(30, 30, 50, 50) + offContext.scale(2, 2) // Scale to 200% + offContext.strokeRect(30, 30, 50, 50) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2119,7 +2212,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Transform { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2128,15 +2221,16 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillStyle = 'rgb(0,0,0)' - this.offContext.fillRect(0, 0, 100, 100) - this.offContext.transform(1, 0.5, -0.5, 1, 10, 10) - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(0, 0, 100, 100) - this.offContext.transform(1, 0.5, -0.5, 1, 10, 10) - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(0, 0, 100, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = 'rgb(0,0,0)' + offContext.fillRect(0, 0, 100, 100) + offContext.transform(1, 0.5, -0.5, 1, 10, 10) + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(0, 0, 100, 100) + offContext.transform(1, 0.5, -0.5, 1, 10, 10) + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(0, 0, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2177,7 +2271,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct SetTransform { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2186,12 +2280,13 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillStyle = 'rgb(255,0,0)' - this.offContext.fillRect(0, 0, 100, 100) - this.offContext.setTransform(1,0.5, -0.5, 1, 10, 10) - this.offContext.fillStyle = 'rgb(0,0,255)' - this.offContext.fillRect(0, 0, 100, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillStyle = 'rgb(255,0,0)' + offContext.fillRect(0, 0, 100, 100) + offContext.setTransform(1,0.5, -0.5, 1, 10, 10) + offContext.fillStyle = 'rgb(0,0,255)' + offContext.fillRect(0, 0, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2204,6 +2299,86 @@ Since API version 9, this API is supported in ArkTS widgets. ![en-us_image_0000001193872526](figures/en-us_image_0000001193872526.png) +### setTransform + +setTransform(transform?: Matrix2D): void + +Resets the current transformation and creates a new transformation matrix based on the specified **Matrix2D** object. + +Since API version 9, this API is supported in ArkTS widgets. + +**Parameters** + +| Name | Type | Mandatory | Default Value | Description | +| --------- | ---------------------------------------- | ---- | ---- | ----- | +| transform | [Matrix2D](ts-components-canvas-matrix2d.md#Matrix2D) | No | null | Matrix object. | + +### getTransform + +getTransform(): Matrix2D + +Obtains the current transformation matrix being applied to the context. + +Since API version 9, this API is supported in ArkTS widgets. + +**Return value** + +| Type | Description | +| ---------------------------------------- | ----- | +| [Matrix2D](ts-components-canvas-matrix2d.md#Matrix2D) | Matrix object.| + +**Example** + + ```ts + // xxx.ets + @Entry + @Component + struct TransFormDemo { + private settings: RenderingContextSettings = new RenderingContextSettings(true); + private context1: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); + private offcontext1: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 100, this.settings); + private context2: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); + private offcontext2: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 100, this.settings); + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('context1'); + Canvas(this.context1) + .width('230vp') + .height('120vp') + .backgroundColor('#ffff00') + .onReady(() =>{ + this.offcontext1.fillRect(50, 50, 50, 50); + this.offcontext1.setTransform(1.2, Math.PI/8, Math.PI/6, 0.5, 30, -25); + this.offcontext1.fillRect(50, 50, 50, 50); + var image = this.offcontext1.transferToImageBitmap(); + this.context1.transferFromImageBitmap(image); + }) + Text('context2'); + Canvas(this.context2) + .width('230vp') + .height('120vp') + .backgroundColor('#0ffff0') + .onReady(() =>{ + this.offcontext2.fillRect(50, 50, 50, 50); + let storedTransform = this.offcontext1.getTransform(); + console.log("Matrix [scaleX = " + storedTransform.scaleX + ", scaleY = " + storedTransform.scaleY + + ", rotateX = " + storedTransform.rotateX + ", rotateY = " + storedTransform.rotateY + + ", translateX = " + storedTransform.translateX + ", translateY = " + storedTransform.translateY + "]") + this.offcontext2.setTransform(storedTransform); + this.offcontext2.fillRect(50,50,50,50); + var image = this.offcontext2.transferToImageBitmap(); + this.context2.transferFromImageBitmap(image); + }) + } + .width('100%') + .height('100%') + } + } + ``` + + ![en-us_image_0000001219982726.png](figures/en-us_image_0000001219982726.png) + ### translate translate(x: number, y: number): void @@ -2228,7 +2403,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct Translate { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2237,10 +2412,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.fillRect(10, 10, 50, 50) - this.offContext.translate(70, 70) - this.offContext.fillRect(10, 10, 50, 50) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.fillRect(10, 10, 50, 50) + offContext.translate(70, 70) + offContext.fillRect(10, 10, 50, 50) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2290,7 +2466,7 @@ Since API version 9, this API is supported in ArkTS widgets, except that **Pixel private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) private img:ImageBitmap = new ImageBitmap("common/images/icon.jpg") - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) @@ -2298,8 +2474,9 @@ Since API version 9, this API is supported in ArkTS widgets, except that **Pixel .height('100%') .backgroundColor('#ffff00') .onReady(() => { - this.offContext.drawImage( this.img,0,0,400,200) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.drawImage( this.img,0,0,400,200) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2422,7 +2599,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct GetImageData { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) private img:ImageBitmap = new ImageBitmap("/common/images/1234.png") build() { @@ -2432,10 +2609,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.drawImage(this.img,0,0,130,130) - var imagedata = this.offContext.getImageData(50,50,130,130) - this.offContext.putImageData(imagedata,150,150) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.drawImage(this.img,0,0,130,130) + var imagedata = offContext.getImageData(50,50,130,130) + offContext.putImageData(imagedata,150,150) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2479,7 +2657,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct PutImageData { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) @@ -2487,15 +2665,16 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - var imageData = this.offContext.createImageData(100, 100) + var offContext = this.offCanvas.getContext("2d", this.settings) + var imageData = offContext.createImageData(100, 100) for (var i = 0; i < imageData.data.length; i += 4) { imageData.data[i + 0] = 255 imageData.data[i + 1] = 0 imageData.data[i + 2] = 255 imageData.data[i + 3] = 255 } - this.offContext.putImageData(imageData, 10, 10) - var image = this.offContext.transferToImageBitmap() + offContext.putImageData(imageData, 10, 10) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2529,7 +2708,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct SetLineDash { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2538,10 +2717,11 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.arc(100, 75, 50, 0, 6.28) - this.offContext.setLineDash([10,20]) - this.offContext.stroke() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.arc(100, 75, 50, 0, 6.28) + offContext.setLineDash([10,20]) + offContext.stroke() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2577,7 +2757,7 @@ Since API version 9, this API is supported in ArkTS widgets. @State message: string = 'Hello World' private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Row() { Column() { @@ -2586,7 +2766,8 @@ Since API version 9, this API is supported in ArkTS widgets. .fontWeight(FontWeight.Bold) .onClick(()=>{ console.error('before getlinedash clicked') - let res = this.offContext.getLineDash() + var offContext = this.offCanvas.getContext("2d", this.settings) + let res = offContext.getLineDash() console.error(JSON.stringify(res)) }) Canvas(this.context) @@ -2594,11 +2775,12 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() => { - this.offContext.arc(100, 75, 50, 0, 6.28) - this.offContext.setLineDash([10,20]) - this.offContext.stroke() - let res = this.offContext.getLineDash() - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.arc(100, 75, 50, 0, 6.28) + offContext.setLineDash([10,20]) + offContext.stroke() + let res = offContext.getLineDash() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2642,7 +2824,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct ToDataURL { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2651,7 +2833,8 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - var dataURL = this.offContext.toDataURL() + var offContext = this.offCanvas.getContext("2d", this.settings) + var dataURL = offContext.toDataURL() }) } .width('100%') @@ -2683,7 +2866,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct ImageSmoothingQualityDemoOff { private settings: RenderingContextSettings = new RenderingContextSettings(true); private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings); - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) private img:ImageBitmap = new ImageBitmap("common/images/example.jpg"); build() { @@ -2693,12 +2876,13 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - let offctx = this.offContext + var offContext = this.offCanvas.getContext("2d", this.settings) + let offctx = offContext offctx.imageSmoothingEnabled = true offctx.imageSmoothingQuality = 'high' offctx.drawImage(this.img, 0, 0, 400, 200) - var image = offctx.transferToImageBitmap() + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2732,7 +2916,7 @@ Creates an **ImageBitmap** object on the most recently rendered image of the **O struct PutImageData { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2741,15 +2925,16 @@ Creates an **ImageBitmap** object on the most recently rendered image of the **O .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - var imageData = this.offContext.createImageData(100, 100) + var offContext = this.offCanvas.getContext("2d", this.settings) + var imageData = offContext.createImageData(100, 100) for (var i = 0; i < imageData.data.length; i += 4) { imageData.data[i + 0] = 255 imageData.data[i + 1] = 0 imageData.data[i + 2] = 255 imageData.data[i + 3] = 255 } - this.offContext.putImageData(imageData, 10, 10) - var image = this.offContext.transferToImageBitmap() + offContext.putImageData(imageData, 10, 10) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2777,7 +2962,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct CanvasExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2786,12 +2971,13 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.save() // save the default state - this.offContext.fillStyle = "#00ff00" - this.offContext.fillRect(20, 20, 100, 100) - this.offContext.restore() // restore to the default state - this.offContext.fillRect(150, 75, 100, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.save() // save the default state + offContext.fillStyle = "#00ff00" + offContext.fillRect(20, 20, 100, 100) + offContext.restore() // restore to the default state + offContext.fillRect(150, 75, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2820,7 +3006,7 @@ Since API version 9, this API is supported in ArkTS widgets. struct CanvasExample { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2829,12 +3015,13 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - this.offContext.save() // save the default state - this.offContext.fillStyle = "#00ff00" - this.offContext.fillRect(20, 20, 100, 100) - this.offContext.restore() // restore to the default state - this.offContext.fillRect(150, 75, 100, 100) - var image = this.offContext.transferToImageBitmap() + var offContext = this.offCanvas.getContext("2d", this.settings) + offContext.save() // save the default state + offContext.fillStyle = "#00ff00" + offContext.fillRect(20, 20, 100, 100) + offContext.restore() // restore to the default state + offContext.fillRect(150, 75, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2872,8 +3059,8 @@ Since API version 9, this API is supported in ArkTS widgets. struct CreateLinearGradient { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) @@ -2881,13 +3068,14 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - var grad = this.offContext.createLinearGradient(50,0, 300,100) + var offContext = this.offCanvas.getContext("2d", this.settings) + var grad = offContext.createLinearGradient(50,0, 300,100) grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.5, '#ffffff') grad.addColorStop(1.0, '#00ff00') - this.offContext.fillStyle = grad - this.offContext.fillRect(0, 0, 400, 400) - var image = this.offContext.transferToImageBitmap() + offContext.fillStyle = grad + offContext.fillRect(0, 0, 400, 400) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2928,8 +3116,8 @@ Since API version 9, this API is supported in ArkTS widgets. struct CreateRadialGradient { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Canvas(this.context) @@ -2937,13 +3125,14 @@ Since API version 9, this API is supported in ArkTS widgets. .height('100%') .backgroundColor('#ffff00') .onReady(() =>{ - var grad = this.offContext.createRadialGradient(200,200,50, 200,200,200) + var offContext = this.offCanvas.getContext("2d", this.settings) + var grad = offContext.createRadialGradient(200,200,50, 200,200,200) grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.5, '#ffffff') grad.addColorStop(1.0, '#00ff00') - this.offContext.fillStyle = grad - this.offContext.fillRect(0, 0, 440, 440) - var image = this.offContext.transferToImageBitmap() + offContext.fillStyle = grad + offContext.fillRect(0, 0, 440, 440) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } @@ -2978,8 +3167,7 @@ Creates a conic gradient. struct OffscreenCanvasConicGradientPage { private settings: RenderingContextSettings = new RenderingContextSettings(true) private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings) - - private offContext: OffscreenCanvasRenderingContext2D = new OffscreenCanvasRenderingContext2D(600, 600, this.settings) + private offCanvas: OffscreenCanvas = new OffscreenCanvas(600, 600) build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { @@ -2988,13 +3176,14 @@ struct OffscreenCanvasConicGradientPage { .height('100%') .backgroundColor('#ffffff') .onReady(() =>{ - var grad = this.offContext.createConicGradient(0, 50, 80) + var offContext = this.offCanvas.getContext("2d", this.settings) + var grad = offContext.createConicGradient(0, 50, 80) grad.addColorStop(0.0, '#ff0000') grad.addColorStop(0.5, '#ffffff') grad.addColorStop(1.0, '#00ff00') - this.offContext.fillStyle = grad - this.offContext.fillRect(0, 30, 100, 100) - var image = this.offContext.transferToImageBitmap() + offContext.fillStyle = grad + offContext.fillRect(0, 30, 100, 100) + var image = this.offCanvas.transferToImageBitmap() this.context.transferFromImageBitmap(image) }) } diff --git a/en/application-dev/reference/arkui-ts/ts-page-transition-animation.md b/en/application-dev/reference/arkui-ts/ts-page-transition-animation.md index e0a3bb339e1db622d902737a7f3a1d4f61d2cf64..e43e8f0007c77fc55206ff51a2cc0ecaa7749549 100644 --- a/en/application-dev/reference/arkui-ts/ts-page-transition-animation.md +++ b/en/application-dev/reference/arkui-ts/ts-page-transition-animation.md @@ -10,8 +10,8 @@ You can customize the page entrance and exit animations in the **pageTransition* | Name | Parameter | Mandatory| Description | | ------------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| PageTransitionEnter | {
type?: RouteType,
duration?: number,
curve?: [Curve](ts-appendix-enums.md#curve) \| string,
delay?: number
} | No | Page entrance animation.
- **type**: route type for the page transition effect to take effect.
Default value: **RouteType.None**
- **duration**: animation duration.
Unit: ms
Default value: **1000**
- **curve**: animation curve. The value of the string type can be any of the following: "ease", "ease-in", "ease-out", "ease-in-out", "extreme-deceleration", "fast-out-linear-in", "fast-out-slow-in", "friction", "linear", "linear-out-slow-in", "rhythm", "sharp", "smooth".
Default value: **Curve.Linear**
- **delay**: animation delay.
Unit: ms
Default value: **0**
**NOTE**
If no match is found, the default page transition effect is used (which may vary according to the device). To disable the default page transition effect, set **duration** to **0**.| -| PageTransitionExit | {
type?: RouteType,
duration?: number,
curve?: [Curve](ts-appendix-enums.md#curve) \| string,
delay?: number
} | No | Page exit animation.
- **type**: route type for the page transition effect to take effect.
Default value: **RouteType.None**
- **duration**: animation duration.
Unit: ms
Default value: **1000**
- **curve**: animation curve. The value range of the string type is the same as that of **PageTransitionEnter**.
Default value: **Curve.Linear**
- **delay**: animation delay.
Unit: ms
Default value: **0**
**NOTE**
If no match is found, the default page transition effect is used (which may vary according to the device). To disable the default page transition effect, set **duration** to **0**.| +| PageTransitionEnter | {
type?: RouteType,
duration?: number,
curve?: [Curve](ts-appendix-enums.md#curve) \| string \| [ICurve](../apis/js-apis-curve.md#icurve)10+,
delay?: number
} | No | Page entrance animation.
- **type**: route type for the page transition effect to take effect.
Default value: **RouteType.None**
- **duration**: animation duration.
Unit: ms
Default value: **1000**
- **curve**: animation curve. The value of the string type can be any of the following: "ease", "ease-in", "ease-out", "ease-in-out", "extreme-deceleration", "fast-out-linear-in", "fast-out-slow-in", "friction", "linear", "linear-out-slow-in", "rhythm", "sharp", "smooth".
Default value: **Curve.Linear**
- **delay**: animation delay.
Unit: ms
Default value: **0**
**NOTE**
If no match is found, the default page transition effect is used (which may vary according to the device). To disable the default page transition effect, set **duration** to **0**.| +| PageTransitionExit | {
type?: RouteType,
duration?: number,
curve?: [Curve](ts-appendix-enums.md#curve) \| string \| [ICurve](../apis/js-apis-curve.md#icurve)10+,
delay?: number
} | No | Page exit animation.
- **type**: route type for the page transition effect to take effect.
Default value: **RouteType.None**
- **duration**: animation duration.
Unit: ms
Default value: **1000**
- **curve**: animation curve. The value range of the string type is the same as that of **PageTransitionEnter**.
Default value: **Curve.Linear**
- **delay**: animation delay.
Unit: ms
Default value: **0**
**NOTE**
If no match is found, the default page transition effect is used (which may vary according to the device). To disable the default page transition effect, set **duration** to **0**.| ## RouteType diff --git a/en/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md b/en/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md index c741d2973743543c25e430e7575c8162053780bf..d37a8923e07eb70eee30e748dd3002cc0edbc7c2 100644 --- a/en/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md +++ b/en/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md @@ -12,7 +12,7 @@ A shared element transition is a transition animation applied to a component tha | Name | Parameter | Description | | ---------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| sharedTransition | id: string,
{
duration?: number,
curve?: Curve \| string,
delay?: number,
motionPath?:
{
path: string,
form?: number,
to?: number,
rotatable?: boolean
},
zIndex?: number,
type?: [SharedTransitionEffectType](ts-appendix-enums.md#sharedtransitioneffecttype)
} | Transition of the shared element. If the same **id** value is configured for a component on the two pages, this component is considered as a shared element of the pages. If the **id** value is an empty string, no transition will be applied to the component.
- **id**: component ID.
- **duration**: animation duration.
Default value: **1000**
Unit: ms
Value range: [0, +∞)
The value **0** indicates that no animation is applied. A value less than 0 evaluates to the default value **1000**.
- **curve**: animation curve. The default curve is **Linear**. For details about the valid values, see [Curve](ts-animatorproperty.md).
- **delay**: animation delay.
Default value: **0**
Unit: ms
Value range: [0, +∞)
A value less than 0 evaluates to the value **0**.
- **motionPath**: motion path information. For details, see [Motion Path Animation](ts-motion-path-animation.md).
- **path**: path.
- **from**: start value.
- **to**: end value.
- **rotatable**: whether to rotate.
- **zIndex**: z-axis.
- **type**: animation type.| +| sharedTransition | id: string,
{
duration?: number,
curve?: [Curve](ts-appendix-enums.md#curve) \| string \| [ICurve](../apis/js-apis-curve.md#icurve)10+,
delay?: number,
motionPath?:
{
path: string,
form?: number,
to?: number,
rotatable?: boolean
},
zIndex?: number,
type?: [SharedTransitionEffectType](ts-appendix-enums.md#sharedtransitioneffecttype)
} | Transition of the shared element. If the same **id** value is configured for a component on the two pages, this component is considered as a shared element of the pages. If the **id** value is an empty string, no transition will be applied to the component.
- **id**: component ID.
- **duration**: animation duration.
Default value: **1000**
Unit: ms
Value range: [0, +∞)
The value **0** indicates that no animation is applied. A value less than 0 evaluates to the default value **1000**.
- **curve**: animation curve. The default curve is **Curve.Linear**.
- **delay**: animation delay.
Default value: **0**
Unit: ms
Value range: [0, +∞)
A value less than 0 evaluates to the value **0**.
- **motionPath**: motion path information. For details, see [Motion Path Animation](ts-motion-path-animation.md).
- **path**: path.
- **from**: start value.
- **to**: end value.
- **rotatable**: whether to rotate.
- **zIndex**: z-axis.
- **type**: animation type.| ## Example diff --git a/en/application-dev/ui/Readme-EN.md b/en/application-dev/ui/Readme-EN.md index 56e49bb81618bf453b1c8af065d1adc9dc5f1ef2..43c5072d1d1c6dba13d4507aa4663dcc066b0d01 100644 --- a/en/application-dev/ui/Readme-EN.md +++ b/en/application-dev/ui/Readme-EN.md @@ -40,14 +40,26 @@ - [Drawing Geometric Shapes (Shape)](arkts-geometric-shape-drawing.md) - [Drawing Custom Graphics on the Canvas (Canvas)](arkts-drawing-customization-on-canvas.md) - Using Animation - - [Animation Overview](arkts-animation-overview.md) - - Animation Within a Page - - [Layout Update Animation](arkts-layout-update-animation.md) - - [Transition Animation Within a Component](arkts-transition-animation-within-component.md) - - [Spring Curve Animation](arkts-spring-animation.md) - - Animation Between Pages - - [Zoom Animation](arkts-zoom-animation.md) - - [Page Transition Animation](arkts-page-transition-animation.md) + - [Animation Overview](arkts-animation.md) + - Attribute Animation + - [Attribute Animation Overview](arkts-attribute-animation-overview.md) + - [Attribute Animation APIs](arkts-attribute-animation-apis.md) + - [Custom Attribute Animation](arkts-custom-attribute-animation.md) + - Transition Animation + - [Transition Animation Overview](arkts-transition-overview.md) + - [Enter/Exit Transition](arkts-enter-exit-transition.md) + - [Navigation Transition](arkts-navigation-transition.md) + - [Modal Transition](arkts-modal-transition.md) + - [Shared Element Transition](arkts-shared-element-transition.md) + - [Component Animation](arkts-component-animation.md) + - Animation Curve + - [Traditional Curve](arkts-traditional-curve.md) + - [Spring Curve](arkts-spring-curve.md) + - [Animation Smoothing](arkts-animation-smoothing.md) + - Animation Effects + - [Blur Effect](arkts-blur-effect.md) + - [Shadow Effect](arkts-shadow-effect.md) + - [Color Effect](arkts-color-effect.md) - Using Interaction Events - [Interaction Event Overview](arkts-event-overview.md) - Universal Events diff --git a/en/application-dev/ui/arkts-animation-smoothing.md b/en/application-dev/ui/arkts-animation-smoothing.md new file mode 100644 index 0000000000000000000000000000000000000000..13f9275ebf6f3e5f804078a003064f45bfb67f2e --- /dev/null +++ b/en/application-dev/ui/arkts-animation-smoothing.md @@ -0,0 +1,179 @@ +# Animation Smoothing + + +When running animations, the UI is also interacting with users in real time. It must respond immediately to changes in user behavior. For example, if the user swipes up to exit in the midst of an application launch process, the UI should immediately transit from the startup animation to the exit animation, rather than finishing the startup animation before exiting. In the scenario where the animation triggered when the user lifts their fingers off the screen, the initial velocity of the animation must inherit the gesture speed, so as to avoid pauses caused by speed disconnection. For the preceding and similar scenarios, OpenHarmony provides efficient APIs for smoothing between animations and between animations and gestures. + + +## Smoothing Between Animations + +Assume that there is a running animation for an animatable attribute. If the end value of the attribute changes due to an operation on the UI, just change the attribute value in the **animateTo** closure or change the input parameter value of the **animation** API to create an animation. OpenHarmony then automatically connects the previous animation with the current animation – the created animation. + + +```ts +import curves from '@ohos.curves' + +// Step 1: Declare the related state variable. +@state scaleToggle: boolean = true; + +... +Column() { + Button() + // Step 2: Set the declared state variable to the related animatable attribute API. + .scale(this.scaleToggle ? 1 : 0.5) + // Step 3: Change the state variable value through the click event, which then changes the attribute value. + .onclick(() => { + this.scaleToggle = !this.scaleToggle; + }) + // Step 4: Enable the implicit animation. When the end value of the animation changes, the system automatically adds the smoothing animation. + .animation({ + curve: curves.springMotion() + }) +} +... +``` + +A complete example is as follows: By clicking **click**, you change the **scale** attribute of the red square. When you click **click** repeatedly, the end value of the **scale** attribute changes continuously, and the current animation smoothly moves towards the new end value of the **scale** attribute. + + +```ts +import curves from '@ohos.curves'; + +@Entry +@Component +struct AnimationToAnimationDemo { + @State isAnimation: boolean = false; + + build() { + Column() { + Text('ArkUI') + .fontWeight(FontWeight.Bold) + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0xf56c6c) + .width(100) + .height(100) + .scale({ x: this.isAnimation ? 2 : 1, y: this.isAnimation ? 2 : 1 }) + .animation({ curve: curves.springMotion(0.4, 0.8) }) + + Button('Click') + .margin({ top: 200 }) + .onClick(() => { + this.isAnimation = !this.isAnimation; + }) + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} +``` + +![en-us_image_0000001599971890](figures/en-us_image_0000001599971890.gif) + + + +## Smoothing Between Gestures and Animations + +In scenarios where gestures are used, an attribute change is generally triggered when the user places or moves their finger (or fingers) on the screen, and continues after the user lifts their finger (or fingers) off the screen until the end value of the attributes is reached. + +The initial velocity of the attribute change after the user lifts their finger (or fingers) should be consistent with the velocity of the attribute change at the moment before the user lifts their finger (or fingers). If the former is **0**, it feels like a running car stops suddenly, an unusual abrupt change not welcomed by users. + +In cases where smoothing between gestures and animations is required, for example, when scrolling a list, you can apply a responsive spring curve for the attribute animation running when the user places or moves their finger (or fingers) on the screen; and apply a spring curve for the attribute animation running after the user lifts their finger (or fingers) off the screen. For the animation that uses the [springMotion](../reference/apis/js-apis-curve.md#curvesspringmotion9) curve, the attribute animation running when the user places or moves their finger (or fingers) on the screen automatically inherits the previous velocity and starts from where the previous animation leaves off. + + +```ts +import curves from '@ohos.curves' + +// Step 1: Declare related state variables. +@state offsetX: number = 0; +@State offsetY: number = 0; +targetOffsetX: number = 100; +targetOffsetY: number = 100; +... +Column() + // Step 2: Set the declared state variables to the related animatable attribute APIs. + .translate({ x: this.offsetX, y: this.offsetY}) + .gesture( + PanGesture({}) + .onActionUpdate((event: GestureEvent) => { + // Step 3: Change the state variable value for the time when the user places or moves their finger (or fingers) on the screen and use reponsiveSpringMotion for movement toward the new value. + animateTo({ + curve: curves.responsiveSpringMotion() + }, () => { + this.offsetX = event.offsetX; + this.offsetY = event.offsetY; + }) + }) + .onActionEnd(() => { + // Step 4: Set the end value of the state variable for after the user lifts their finger (or fingers), and use springMotion for movement toward the new value. The springMotion animation inherits the previous velocity. + animateTo({ + curve: curves.SpringMotion() + }, () => { + this.offsetX = targetOffsetX; + this.offsetY = targetOffsetY; + }) + }) + ) +... +``` + +Below is the complete sample code and effect. + + +```ts +import curves from '@ohos.curves'; + +@Entry +@Component +struct SpringMotionDemo { + @State positionX: number = 100; + @State positionY: number = 100; + diameter: number = 50; + + build() { + Column() { + Row() { + Circle({ width: this.diameter, height: this.diameter }) + .fill(Color.Blue) + .position({ x: this.positionX, y: this.positionY }) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Move) { + // When the user places or moves their finger on the screen, use the responsiveSpringMotion curve. + animateTo({ curve: curves.responsiveSpringMotion() }, () => { + // Subtract the radius so that the center of the ball moves to where the finger is placed. + this.positionX = event.touches[0].screenX - this.diameter / 2; + this.positionY = event.touches[0].screenY - this.diameter / 2; + console.info(`move, animateTo x:${this.positionX}, y:${this.positionY}`); + }) + } else if (event.type === TouchType.Up) { + // After the user lifts their finger off the screen, use the springMotion curve. + animateTo({ curve: curves.springMotion() }, () => { + this.positionX = 100; + this.positionY = 100; + console.info(`touchUp, animateTo x:100, y:100`); + }) + } + }) + } + .width("100%").height("80%") + .clip(true) // If the ball moves beyond the parent component, it is invisible. + .backgroundColor(Color.Orange) + + Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Center }) { + Text("Drag the ball").fontSize(16) + } + .width("100%") + + Row() { + Text('Click position: [x: ' + Math.round(this.positionX) + ', y:' + Math.round(this.positionY) + ']').fontSize(16) + } + .padding(10) + .width("100%") + }.height('100%').width('100%') + } +} +``` + +![en-us_image_0000001647027001](figures/en-us_image_0000001647027001.gif) diff --git a/en/application-dev/ui/arkts-animation.md b/en/application-dev/ui/arkts-animation.md new file mode 100644 index 0000000000000000000000000000000000000000..3cc70c0a075a9c5bad787712be11d167b71abc48 --- /dev/null +++ b/en/application-dev/ui/arkts-animation.md @@ -0,0 +1,32 @@ +# Animation Overview + + +The UI contains various components (such as time and wallpaper) that users can see when interacting with their devices. Attributes are APIs used to control the behavior of components. For example, you can adjust the location of a component on the screen through the location attribute. + + +In general cases, if the value of an attribute is changed, the UI will be updated accordingly. Animation can add smooth transition effects when the UI is updated. Let's look at an example. When the user touches an application icon on the home screen, the application window opens and replaces the home screen as the primary display area. In this application launch process, if no animation is added, the related attributes change immediately, and the application window directly replaces the home screen, resulting in a sense of visual discontinuity. By adding animation, we enable attribute changes to take place over time, thereby creating an illusion of visual continuity. + + +ArkUI provides a wide range of animation APIs (such as attribute animation and transition animation), which you can leverage to cause attributes to gradually change from the start value to the end value based on the specified settings. Although the attribute values are not absolutely continuous during the change, but rather discrete to some extent, what you finally see is a continuous animation, since human eyes retain persistence of vision. A change of the UI is called an animation frame, which corresponds to a screen refresh. An important indicator that determines the animation smoothness is the frame rate (FPS), that is, the number of animation frames per second. The higher the frame rate, the smoother the animation. In ArkUI, animation parameters include animation duration, animation curve, and more. As the main factor of the animation, the animation curve determines the law of attribute value changes. For example, with a linear animation curve, the attribute changes from the start value to the end value at a constant speed over the given duration. If the attribute changes too fast or too slow, the visual experience may suffer. Therefore, animation parameters, especially animation curves, must be well designed and adjusted to be tailored to use cases. + + +Animation APIs drive attribute values to continuously transit from one state to another according to the rule determined by the animation parameters, and thereby generate a continuous visual effect on the UI. This walkthrough demonstrates the steps and precautions to follow, for creating a fascinating animation experience for users. It is organized as follows. + + +![en-us_image_0000001595763076](figures/en-us_image_0000001595763076.png) + + + +- Attribute animation: It is the most basic animation type. It drives attribute changes frame by frame based on animation parameters to create an animation on a frame-by-frame basis. + +- Transition animation: animation for transitioning when components appear and disappear. To maintain animation consistency, some animation curves have been built in and cannot be customized. + - Whenever possible, avoid ability redirection in the animation. An ability is a task in effect and is individually displayed on the recent tasks screen. Redirection between abilities is redirection between tasks. In the typical scenario of viewing large images in an application, if you call the gallery ability from the application to open large images, then the gallery ability will appear on the recent tasks screen. This is not recommended. A more recommended practice is as follows: Build a large image component in the application and invoke that component through modal transition. In this way, the entire animation can be completed in one ability. + - To implement navigation, use the **\** component, instead of the page routing mode. The page routing mode causes page separation, which is inconvenient for implementing linked transition effects. In addition, it does not allow for one-time development for multi-device deployment. + +- Component animation: Components provide default animations (such as the slide animation of the **\** component). Some of them even support custom animations. + +- Animation curve: You can use traditional and spring curves to control how the attribute values change, to create an engaging animation effect. + +- Animation connection: Make the transition between animations and between gestures and animations as natural as possible. + +- Advanced animation effect: You can up your animation game with advanced effects such as blur, shadow, color gradient, and the like. diff --git a/en/application-dev/ui/arkts-attribute-animation-apis.md b/en/application-dev/ui/arkts-attribute-animation-apis.md new file mode 100644 index 0000000000000000000000000000000000000000..67fdaaee8f62a4a63ca23b0119b637647cfd0aa1 --- /dev/null +++ b/en/application-dev/ui/arkts-attribute-animation-apis.md @@ -0,0 +1,181 @@ +# Attribute Animation APIs + + +ArkUI provides two types of APIs, namely, [animateTo](../reference/arkui-ts/ts-explicit-animation.md) and [animation](../reference/arkui-ts/ts-animatorproperty.md), to implement an attribute animation – a visual illusion of continuity created by driving component attributes to change over time based on animation parameters such as the animation curve. + + +| API| Scope| Principle| Description| +| -------- | -------- | -------- | -------- | +| animateTo | GUI changes caused by attribute changes in closures.
Transition for appearance and disappearance.| As a general function, animates the differences between the UIs before and after the state variable in the closure is changed.
This API can be called multiple times and can be nested.| Applicable when a single set of animation parameters is used to animate multiple attributes.
Applicable when animations need to be nested.| +| animation | GUI changes caused by attribute changes bound to components through attribute APIs.| Identifies the change of the animatable attributes of a component and automatically adds an animation.
As the API call sequence of the component is from bottom to top, this API applies only to the attributes above it.
In a component, you can set individual **animation** for attributes based on the call sequence.| Applicable when different sets of animation parameters are used to animate different attributes.| + + +## Using animateTo + + +``` +animateTo(value: AnimateParam, event: () => void): void +``` + +Among the parameters of [animateTo](../reference/arkui-ts/ts-explicit-animation.md), **value** indicates the [animation parameters](../reference/arkui-ts/ts-explicit-animation.md#animateparam) (including duration and [curve](../reference/apis/js-apis-curve.md#curve); **event** indicates the closure of the animation. Attribute animations generated by variable changes within the closure follow the same animation parameters. + + +```ts +import curves from '@ohos.curves' + +@Entry +@Component +struct AnimateToDemo { + @State animate: boolean = false; + // Step 1: Declare related state variables. + @State rotateValue: number = 0; // Rotation angle of component 1. + @State translateY: number = 0; // Offset of component 2 + @State opacityValue: number = 1; // Opacity of component 2. + + //Step 2: Set the declared state variables to the related animatable attribute APIs. + build() { + Column() { + // Component 1 + Column() { + Text('ArkUI') + .fontWeight(FontWeight.Bold) + .fontSize(20) + .fontColor(Color.White) + } + .justifyContent(FlexAlign.Center) + .width(150) + .height(150) + .borderRadius(10) + .rotate({ angle: this.rotateValue }) + .backgroundColor(0xf56c6c) + + // Component 2 + Column() { + Text('ArkUI') + .fontWeight(FontWeight.Bold) + .fontSize(20) + .fontColor(Color.White) + } + .justifyContent(FlexAlign.Center) + .width(150) + .height(150) + .backgroundColor(0x67C23A) + .borderRadius(10) + .opacity(this.opacityValue) + .translate({ y: this.translateY }) + + Button('Click') + .margin({ top: 120 }) + .onClick(() => { + this.animate = !this.animate; + // Step 3: Enable the implicit animation. + animateTo({ curve: curves.springMotion() }, () => { + // Step 4: Change the state variables in the closure to update the UI. + // You can write any logic that can change the UI, such as array adding and visibility control. The system detects the differences between the new UI and the previous UI and adds animations for the differences. + // The rotate attribute of component 1 is changed. Therefore, a rotate animation is added to component 1. + this.rotateValue = this.animate ? 90 : 0; + // The scale attribute of component 2 is changed. Therefore, a scale animation is added to component 2. + this.opacityValue = this.animate ? 0.6 : 1; + // The offset attribute of component 2 is changed. Therefore, an offset animation is added to component 2. + this.translateY = this.animate ? 100 : 0; + }) + }) + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} +``` + +![en-us_image_0000001599958466](figures/en-us_image_0000001599958466.gif) + + +## Using animation + +Compared with the **animateTo** API, the [animation](../reference/arkui-ts/ts-animatorproperty.md) API does not need to use a closure. Just add it to the end of the target animatable attribute. Then the API automatically adds an attribute animation as long as it detects that the bound attribute is changed. + + +```ts +import curves from '@ohos.curves'; + +@Entry +@Component +struct AnimationDemo { + @State animate: boolean = false; + // Step 1: Declare related state variables. + @State rotateValue: number = 0; // Rotation angle of component 1. + @State translateY: number = 0; // Offset of component 2 + @State color: Color = Color.White; // Font color of component 2. + @State opacityValue: number = 1; // Opacity of the parent component. + + //Step 2: Set the declared state variables to the related animatable attribute APIs. + build() { + Column() { + Column() { + // Component 1 + Text('ArkUI') + .fontWeight(FontWeight.Bold) + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0xf56c6c) + .rotate({ angle: this.rotateValue }) + // Step 3: Enable the implicit animation. As the API call sequence of the component is from bottom to top, the API takes effect on the rotate attribute. + .animation({ curve: curves.springMotion(0.3, 1.0) }) + .width(150) + .height(150) + + // Component 2 + Text('ArkUI') + .fontWeight(FontWeight.Bold) + .fontSize(20) + .fontColor(this.color) + // Step 3: Enable the implicit animation. As the API call sequence of the component is from bottom to top, the API takes effect on the fontColor attribute. + .animation({ curve: curves.springMotion(0.6, 1.2) }) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0x67C23A) + .width(150) + .height(150) + .translate({ y: this.translateY }) + // Step 3: Enable the implicit animation. As the API call sequence of the component is from bottom to top, the API takes effect on the translate attribute. + .animation({ curve: curves.springMotion(0.3, 0.6) }) + } + .justifyContent(FlexAlign.Center) + .opacity(this.opacityValue) + // The animation API takes effect on the opacity attribute. This results in an opacity change of the parent component , which in turn results in an opacity change of its child components. Therefore, animations are added to the opacity attributes of and its child components. + .animation({ curve: curves.springMotion() }) + + // Step 4: Change the state variable to update the UI. The system detects the differences between the new UI and the previous UI and adds animations for the differences. + Button('Click') + .margin({ top: 120 }) + .onClick(() => { + this.animate = !this.animate; + // The rotate attribute of component 1 is changed. Therefore, a rotate animation is added to component 1. + this.rotateValue = this.animate ? 90 : 0; + // The translate attribute of component 2 is changed. Therefore, a translate animation is added to component 2. + this.translateY = this.animate ? 100 : 0; + // The fontColor attribute of component 2 is changed. Therefore, a fontColor animation is added to component 2. + this.color = this.animate ? Color.Black : Color.White; + // The opacity attribute of the parent component is changed, which results in an opacity change of its child components. Therefore, opacity animations are added to and its child components. + this.opacityValue = this.animate ? 0.6 : 1; + }) + + } + .width('100%') + .height('100%') + .justifyContent(FlexAlign.Center) + } +} +``` + +![en-us_image_0000001649279705](figures/en-us_image_0000001649279705.gif) + +> **NOTE** +> - When an animation is applied to the position or size change of a component, as layout measurement is involved, performance overheads are high. To reduce performance overheads, use the [scale](../reference/arkui-ts/ts-universal-attributes-transformation.md) instead, whose value change does not involve layout measurement. This practice is applicable where the component location and size change continuously, for example, where the component size changes as a response to gestures. +> +> - Attribute animations should be applied to the components that are always present. For the components that may appear or disappear, use the [transition animation](arkts-transition-overview.md). +> +> - Avoid using callbacks invoked when an animation ends. Implicit animations are applied to states that have occurred. You do not need to process the end logic. If such callbacks are needed, be sure to handle the data management of continuous operations correctly. diff --git a/en/application-dev/ui/arkts-attribute-animation-overview.md b/en/application-dev/ui/arkts-attribute-animation-overview.md new file mode 100644 index 0000000000000000000000000000000000000000..4cecd48e27d21ddf7b70e07f65761ea8f1e54ab8 --- /dev/null +++ b/en/application-dev/ui/arkts-attribute-animation-overview.md @@ -0,0 +1,41 @@ +# Attribute Animation Overview + + +An attribute API (attribute for short) defines a multitude of attributes, such as size, layout, and location, for controlling behavior of the owning component. Changes to some attributes (such as location) on the UI will cause UI re-render. You can animate the value change of an attribute from the start point to the end point. Attributes can be classified as animatable or non-animatable, depending on whether an animation can be applied to their value changes. Specifically, an animatable attribute meets the following requirements: + + +1. Its value changes can cause UI re-render. For example, the [enabled](../reference/arkui-ts/ts-universal-attributes-enable.md) attribute is used to control whether a component can respond to events such as clicks and touches. However, as its value change does not cause UI re-render, it does not qualify as an animatable attribute. + +2. An animation can be applied to the transition between value changes. For example, the [focusable](../reference/arkui-ts/ts-universal-attributes-focus.md) attribute determines whether the current component can obtain focus. If the value of this attribute changes, the component should immediately switch to the end state to respond to user behavior, and no animation is appropriate here. Therefore, the attribute does not qualify as an animatable attribute. + +**Attribute classification:** + +- Animatable attributes: + + - Built-in animatable attributes + + | Category | Example | + | -------- | ---------------------------------------------- | + | Layout| Position, size, padding, margin, alignment, and weight.| + | Affine transformation| Translation, rotation, scaling, and anchor. | + | Background | Background color and blur. | + | Content | Font size, font color, image alignment, and blur. | + | Foreground | Foreground color. | + | Overlay | Overlay. | + | Appearance | Opacity, rounded corner, border, and shadow. | + | ... | ... | + + - Custom animatable attributes: animatable attributes abstracted through the custom attribute animation mechanism. + +- Non-animatable attributes: **zIndex** and **focusable**, among others. + + +Generally, an animatable attribute accepts only continuous parameters, which allows for using interpolation to fill in gaps between data points, so as to create a visual illusion of continuity. That said, whether the parameter type of an attribute can be interpolated is not a key factor that determines whether an animation can be applied to the attribute. For example, with regard to the [direction](../reference/arkui-ts/ts-universal-attributes-location.md) attribute, which sets the horizontal layout of an element, as it is animatable, ArkUI allows you to apply an animation to the transition between its value changes, though its parameter type is enum. + + +Animatable attributes include both built-in and custom attributes. + + +- Built-in animatable attributes: system-provided component attributes for changing the UI, for example, position, zoom, and blur attributes. + +- [Custom animatable attributes](../quick-start/arkts-animatable-extend.md): attributes made animatable with the use of the [@AnimatableExtend](../quick-start/arkts-animatable-extend.md) decorator. You can abstract animatable attributes from the custom drawing content to control the drawing content of each frame, for example, customizing the volume icon. By defining custom animatable attributes, you can apply animations to some attributes that otherwise do not support animations in ArkUI. diff --git a/en/application-dev/ui/arkts-blur-effect.md b/en/application-dev/ui/arkts-blur-effect.md new file mode 100644 index 0000000000000000000000000000000000000000..b24a084637db286fc2a040d90fa5f2bc83d262e6 --- /dev/null +++ b/en/application-dev/ui/arkts-blur-effect.md @@ -0,0 +1,622 @@ +# Blur Effect + +Animation effects can add detail to your animations and create a sense of realism. For example, blur and shadow effects can lend a 3D look to objects and deliver a more engaging animation experience. ArkUI provides a diverse array of efficient APIs for you to develop exquisite and personalized effects. This topic covers the common blur, shadow, and color effects. + + +Blur effects add a sense of depth and allow for distinction of hierarchical relationship between elements. + + +| API | Description | +| ---------------------------------------- | ---------------------- | +| [backdropBlur](../reference/arkui-ts/ts-universal-attributes-image-effect.md) | Applies a background blur effect to the component. The input parameter is the blur radius.| +| [blur](../reference/arkui-ts/ts-universal-attributes-image-effect.md) | Applies a foreground blur effect to the component. The input parameter is the blur radius.| +| [backgroundBlurStyle](../reference/arkui-ts/ts-universal-attributes-background.md) | Applies a background blur effect to the component. The input parameter is the blur style.| +| [foregroundBlurStyle](../reference/arkui-ts/ts-universal-attributes-foreground-blur-style.md) | Applies a foreground blur effect to the component. The input parameter is the blur style.| + + +## Applying Background Blur with backdropBlur + + +```ts +@Entry +@Component +struct BlurEffectsExample { + build() { + Column({ space: 10 }) { + Text('backdropblur') + .width('90%') + .height('90%') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .backdropBlur(10) // Apply background blur. + .backgroundImage($r('app.media.share')) + .backgroundImageSize({ width: 400, height: 300 }) + } + .width('100%') + .height('50%') + .margin({ top: 20 }) + } +} +``` + + + +![en-us_image_0000001599812870](figures/en-us_image_0000001599812870.png) + + +## Applying Foreground Blur with blur + + +```ts +@Entry +@Component +struct Index { + @State radius: number = 0; + @State text: string = ''; + @State y: string = 'Finger not on the screen'; + + aboutToAppear() { + this.text = "Press a finger on the screen and slide up and down\n" + "Current finger position on the y-axis: " + this.y + + "\n" + "Blur radius:" + this.radius; + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { + Text(this.text) + .height(200) + .fontSize(20) + .fontWeight(FontWeight.Bold) + .fontFamily("cursive") + .fontStyle(FontStyle.Italic) + Image($r("app.media.wall")) + .blur(this.radius) // Apply foreground blur. + .height('100%') + .width("100%") + .objectFit(ImageFit.Cover) + }.height('100%') + .width("100%") + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Move) { + this.y = parseInt(event.touches[0].y.toString()).toString(); + this.radius = parseInt(this.y) / 10; // Modify the blur radius based on the sliding distance. + } + if (event.type === TouchType.Up) { + this.radius = 0; + this.y = 'Finger off the screen'; + } + this.text = "Press a finger on the screen and slide up and down\n" + "Current finger position on the y-axis: " + this.y + + "\n" + "Blur radius:" + this.radius; + }) + } +} +``` + + + +![en-us_image_0000001599813588](figures/en-us_image_0000001599813588.gif) + + +## Applying Background Blur with backgroundBlurStyle + + +```ts +@Entry +@Component +struct BackDropBlurStyleDemo { + build() { + Grid() { + GridItem() { + Column() { + Column() { + Text ('Original') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + + Text ('Original') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('Thin') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + // BlurStyle.Thin: Thin blur is applied. + // ThemeColorMode.LIGHT: The light color mode is used. + // AdaptiveColor.DEFAULT: Adaptive color mode is not used. The default color is used as the mask color. + // scale: blurredness of the background material. The default value is 1. + .backgroundBlurStyle(BlurStyle.Thin, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('Thin') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('Regular') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .backgroundBlurStyle(BlurStyle.Regular, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('Regular') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('Thick') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .backgroundBlurStyle(BlurStyle.Thick, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('Thick') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_THIN') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .backgroundBlurStyle(BlurStyle.BACKGROUND_THIN, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_THIN') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_REGULAR') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .backgroundBlurStyle(BlurStyle.BACKGROUND_REGULAR, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_REGULAR') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_THICK') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .backgroundBlurStyle(BlurStyle.BACKGROUND_THICK, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_THICK') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_ULTRA_THICK') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_ULTRA_THICK') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + } + .columnsTemplate('1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr') + .width('100%') + .height('100%') + .margin({ top: 40 }) + } +} +``` + + + +![en-us_image_0000001649455517](figures/en-us_image_0000001649455517.png) + + + +## Applying Foreground Blur with foregroundBlurStyle + + +```ts +@Entry +@Component +struct ForegroundBlurStyleDemo { + build() { + Grid() { + GridItem() { + Column() { + Column() { + Text ('Original') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + + Text ('Original') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('Thin') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + // BlurStyle.Thin: Thin blur is applied. + // ThemeColorMode.LIGHT: The light color mode is used. + // AdaptiveColor.DEFAULT: Adaptive color mode is not used. The default color is used as the mask color. + // scale: blurredness of the background material. The default value is 1. + .foregroundBlurStyle(BlurStyle.Thin, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('Thin') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('Regular') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .foregroundBlurStyle(BlurStyle.Regular, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('Regular') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('Thick') + .fontSize(20) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .foregroundBlurStyle(BlurStyle.Thick, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('Thick') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_THIN') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .foregroundBlurStyle(BlurStyle.BACKGROUND_THIN, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_THIN') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_REGULAR') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .foregroundBlurStyle(BlurStyle.BACKGROUND_REGULAR, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_REGULAR') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_THICK') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .foregroundBlurStyle(BlurStyle.BACKGROUND_THICK, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_THICK') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + + GridItem() { + Column() { + Column() { + Text('BACKGROUND_ULTRA_THICK') + .fontSize(12) + .fontColor(Color.White) + .textAlign(TextAlign.Center) + .width('100%') + .height('100%') + } + .height(100) + .aspectRatio(1) + .borderRadius(10) + .backgroundImage($r('app.media.share')) + .foregroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK, { + colorMode: ThemeColorMode.LIGHT, + adaptiveColor: AdaptiveColor.DEFAULT, + scale: 0.1 + }) + + Text('BACKGROUND_ULTRA_THICK') + .fontSize(12) + .fontColor(Color.Black) + } + .height('100%') + .justifyContent(FlexAlign.Start) + } + .width(200) + .height(200) + } + .columnsTemplate('1fr 1fr') + .rowsTemplate('1fr 1fr 1fr 1fr') + .width('100%') + .height('100%') + .margin({ top: 40 }) + } +} +``` + + + +![en-us_image_0000001599658168](figures/en-us_image_0000001599658168.png) diff --git a/en/application-dev/ui/arkts-color-effect.md b/en/application-dev/ui/arkts-color-effect.md new file mode 100644 index 0000000000000000000000000000000000000000..d873a248880a8d8f4f549557c419a989206a91ca --- /dev/null +++ b/en/application-dev/ui/arkts-color-effect.md @@ -0,0 +1,329 @@ +# Color Effect + + +## APIs + +You can use the color gradient APIs to apply a background color gradient effect to a component. + +| API| Description| +| -------- | -------- | +| [linearGradient](../reference/arkui-ts/ts-universal-attributes-gradient-color.md) | Applies a linear gradient to the component.| +| [sweepGradient](../reference/arkui-ts/ts-universal-attributes-gradient-color.md) | Applies a sweep gradient effect to the component.| +| [radialGradient](../reference/arkui-ts/ts-universal-attributes-gradient-color.md) | Applies a radial gradient effect to the component.| + + +## Applying Linear Gradient Effect + + +```ts +@Entry +@Component +struct LinearGradientDemo { + build() { + Grid() { + GridItem() { + Column() { + Text('angle: 180') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .linearGradient({ + // A positive value indicates a clockwise rotation from the origin, (0, 0). The default value of the linear gradient start angle is 180°. + colors: [ + [0xf56c6c, 0.0], // Color and weight of color stop 1, corresponding to the start position of the component in the 180° direction. + [0xffffff, 1.0], // Color and weight of color stop 2, corresponding to the end position of the component in the 180° direction. + ] + }) + } + + GridItem() { + Column() { + Text('angle: 45') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .linearGradient({ + angle: 45, // Set the linear gradient start angle to 45°. + colors: [ + [0xf56c6c, 0.0], + [0xffffff, 1.0], + ] + }) + } + + GridItem() { + Column() { + Text('repeat: true') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .linearGradient({ + repeating: true, // Repeat the gradients of the area from 0 to 0.3 in the area from 0.3 to 1.0. + colors: [ + [0xf56c6c, 0.0], + [0xE6A23C, .3], + ] + }) + } + + GridItem() { + Column() { + Text('repeat: fasle') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .linearGradient({ + colors: [ + [0xf56c6c, 0.0], // As repeating is not specified, the default value false is used. In this case, only the area from 0 to 0.3 in the component have the color gradient effect. + [0xE6A23C, .3], + ] + }) + } + } + .columnsGap(10) + .rowsGap(10) + .columnsTemplate('1fr 1fr') + .rowsTemplate('1fr 1fr 1fr') + .width('100%') + .height('100%') + } +} +``` + +![en-us_image_0000001641176829](figures/en-us_image_0000001641176829.png) + + +## Applying Sweep Gradient Effect + + +```ts +@Entry +@Component +struct SweepGradientDemo { + build() { + Grid() { + GridItem() { + Column() { + Text('center: 50') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .sweepGradient({ + center: [50, 50], // Center point of the sweep gradient. + start: 0, // Start point of the sweep gradient. + end: 360, // End point of the sweep gradient. + repeating: true, // The gradients are repeated. + colors: [ + // Based on the center point, start point, and end point settings, + // the color changes from color stop 1 to color stop 2 in the area within angles from 0 to 0.125; + // the color changes from color stop 2 to color stop 3 in the area within angles from 0.125 to 0.25; + // the color gradients of the area within angles from 0 to 0.25 are repeated in the area within angles from 0.25 to 1. + [0xf56c6c, 0], // Color and weight of color stop 1. The corresponding angle is 0° (0 x 360°), and the corner is the center point. + [0xffffff, 0.125], // Color and weight of color stop 2. + [0x409EFF, 0.25] // Color and weight of color stop 3. + ] + }) + } + + GridItem() { + Column() { + Text('center: 0') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .sweepGradient({ + center: [0, 0], // Center point of the sweep gradient, which is the coordinate of the upper left corner of the component in this example. + start: 0, + end: 360, + repeating: true, + colors: [ + // In the current component, the sweep gradient center is the upper left corner of the component. Therefore, the angle range from color stop 1 to color stop 3 can cover the entire component. + [0xf56c6c, 0], // Color and weight of color stop 1. The corresponding angle is 0° (0 x 360°) + [0xffffff, 0.125], // Color and weight of color stop 2. The corresponding angle is 45° (0.125 x 360°). + [0x409EFF, 0.25] // Color and weight of color stop 3. The corresponding angle is 90° (0.25 x 360°). + ] + }) + } + + GridItem() { + Column() { + Text('repeat: true') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .sweepGradient({ + center: [50, 50], + start: 0, + end: 360, + repeating: true, + colors: [ + [0xf56c6c, 0], + [0xffffff, 0.125], + [0x409EFF, 0.25] + ] + }) + } + + GridItem() { + Column() { + Text('repeat: false') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .sweepGradient({ + center: [50, 50], + start: 0, + end: 360, + repeating: false, // The color gradient effect is generated only within the coverage of the color stop angles. + colors: [ + [0xf56c6c, 0], + [0xffffff, 0.125], + [0x409EFF, 0.25] + ] + }) + } + } + .columnsGap(10) + .rowsGap(10) + .columnsTemplate('1fr 1fr') + .rowsTemplate('1fr 1fr 1fr') + .width('100%') + .height(437) + } +} +``` + +![en-us_image_0000001641177073](figures/en-us_image_0000001641177073.png) + + +## Applying Radial Gradient Effect + + +```ts +@Entry +@Component +struct radialGradientDemo { + build() { + Grid() { + GridItem() { + Column() { + Text('center: 50') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .radialGradient({ + center: [50, 50], // Center point of the radial gradient. + radius: 100, // Radius of the radial gradient. + repeating: true, // The gradients are repeated outside the specified range to fill the entire component. + colors: [ + // With [50, 50] as the center point, the gradient changes from color stop 1 to color stop 2 within the range of radius 0 to 12.5; + // the gradient changes from color stop 2 to color stop 3 within the range of radius 12.5 to 25; + // the gradients in the range of radius 0 to 25 are repeated to fill the entire component. + [0xf56c6c, 0], // Color and weight of color stop 1. The corresponding radius is 0 (0 x 100). + [0xffffff, 0.125], // Color and weight of color stop 2. The corresponding radius is 12.5 (0.125 x 100). + [0x409EFF, 0.25] // Color and weight of color stop 3. The corresponding radius is 25 (0.25 x 100). + ] + }) + } + + GridItem() { + Column() { + Text('center: 0') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .radialGradient({ + center: [0, 0], // Center point of the radial gradient, which is the coordinate of the upper left corner of the component in this example. + radius: 100, + repeating: true, + colors: [ + [0xf56c6c, 0], + [0xffffff, 0.125], + [0x409EFF, 0.25] + ] + }) + } + + GridItem() { + Column() { + Text('repeat: true') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .radialGradient({ + center: [50, 50], + radius: 100, + repeating: true, + colors: [ + [0xf56c6c, 0], + [0xffffff, 0.125], + [0x409EFF, 0.25] + ] + }) + } + + GridItem() { + Column() { + Text('repeat: false') + .fontSize(15) + } + .width(100) + .height(100) + .justifyContent(FlexAlign.Center) + .borderRadius(10) + .radialGradient({ + center: [50, 50], + radius: 100, + repeating: false, // The gradients are not repeated. + colors: [ + [0xf56c6c, 0], + [0xffffff, 0.125], + [0x409EFF, 0.25] + ] + }) + } + } + .columnsGap(10) + .rowsGap(10) + .columnsTemplate('1fr 1fr') + .rowsTemplate('1fr 1fr 1fr') + .width('100%') + .height('100%') + } +} +``` + +![en-us_image_0000001592904050](figures/en-us_image_0000001592904050.png) diff --git a/en/application-dev/ui/arkts-component-animation.md b/en/application-dev/ui/arkts-component-animation.md new file mode 100644 index 0000000000000000000000000000000000000000..bcb623ffb0f46a863a9f0d23db67f54dc4eb4963 --- /dev/null +++ b/en/application-dev/ui/arkts-component-animation.md @@ -0,0 +1,352 @@ +# Component Animation + + +In addition to universal attribute animation and transition animation APIs, ArkUI provides default animation effects for certain components, for example, the swipe effect for the [\](../reference/arkui-ts/ts-container-list.md) component and the click effect of the [\