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

Update docs (22077)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 7f5c1996
...@@ -70,8 +70,6 @@ To fully understand the preceding example, a knowledge of the following concepts ...@@ -70,8 +70,6 @@ To fully understand the preceding example, a knowledge of the following concepts
- [Universal Style of a Custom Component](#universal-style-of-a-custom-component) - [Universal Style of a Custom Component](#universal-style-of-a-custom-component)
- [Custom Attribute Methods](#custom-attribute-methods)
## Basic Structure of a Custom Component ## Basic Structure of a Custom Component
...@@ -106,6 +104,8 @@ To fully understand the preceding example, a knowledge of the following concepts ...@@ -106,6 +104,8 @@ To fully understand the preceding example, a knowledge of the following concepts
> **NOTE** > **NOTE**
> >
> Since API version 9, this decorator is supported in ArkTS widgets. > Since API version 9, this decorator is supported in ArkTS widgets.
>
> Since API version 10, the \@Entry decorator accepts an optional parameter of type [LocalStorage](arkts-localstorage.md) or type [EntryOptions](#entryoptions10).
```ts ```ts
@Entry @Entry
...@@ -114,6 +114,23 @@ To fully understand the preceding example, a knowledge of the following concepts ...@@ -114,6 +114,23 @@ To fully understand the preceding example, a knowledge of the following concepts
} }
``` ```
### EntryOptions<sup>10+</sup>
Describes the named route options.
| Name | Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| routeName | string | No| Name of the target named route.|
| storage | [LocalStorage](arkts-localstorage.md) | No| Storage of page-level UI state.|
```ts
@Entry({ routeName : 'myPage' })
@Component
struct MyComponent {
}
```
- \@Recycle: A custom component decorated with \@Recycle can be reused. - \@Recycle: A custom component decorated with \@Recycle can be reused.
> **NOTE** > **NOTE**
...@@ -328,68 +345,4 @@ struct MyComponent { ...@@ -328,68 +345,4 @@ struct MyComponent {
> >
> When ArkUI sets styles for custom components, an invisible container component is set for **MyComponent2**. These styles are set on the container component instead of the **\<Button>** component of **MyComponent2**. As seen from the rendering result, the red background color is not directly applied to the button. Instead, it is applied to the container component that is invisible to users where the button is located. > When ArkUI sets styles for custom components, an invisible container component is set for **MyComponent2**. These styles are set on the container component instead of the **\<Button>** component of **MyComponent2**. As seen from the rendering result, the red background color is not directly applied to the button. Instead, it is applied to the container component that is invisible to users where the button is located.
## Custom Attribute Methods
Custom components do not support custom attribute methods. You can use the Controller capability to implement custom APIs.
```ts
// Custom controller
export class MyComponentController {
item: MyComponent = null;
setItem(item: MyComponent) {
this.item = item;
}
changeText(value: string) {
this.item.value = value;
}
}
// Custom component
@Component
export default struct MyComponent {
public controller: MyComponentController = null;
@State value: string = 'Hello World';
build() {
Column() {
Text(this.value)
.fontSize(50)
}
}
aboutToAppear() {
if (this.controller)
this.controller.setItem (this); // Link to the controller.
}
}
// Processing logic
@Entry
@Component
struct StyleExample {
controller = new MyComponentController();
build() {
Column() {
MyComponent({ controller: this.controller })
}
.onClick(() => {
this.controller.changeText('Text');
})
}
}
```
In the preceding example:
1. The **aboutToAppear** method of the **MyComponent** child component passes the current **this** pointer to the **item** member variable of **MyComponentController**.
2. The **StyleExample** parent component holds a **Controller** instance and with which calls the **changeText** API of **Controller**. That is, the value of the state variable **value** of **MyComponent** is changed through the **this** pointer of the **MyComponent** child component held by the controller.
Through the encapsulation of the controller, **MyComponent** exposes the **changeText** API. All instances that hold the controller can call the **changeText** API to change the value of the **MyComponent** state variable **value**.
<!--no_check--> <!--no_check-->
...@@ -2,7 +2,17 @@ ...@@ -2,7 +2,17 @@
A Harmony Archive (HAR) is a static shared package that can contain code, C++ libraries, resources, and configuration files. It enables modules and projects to share code related to ArkUI components, resources, and more. Unlike a Harmony Ability Package (HAP), a HAR cannot be independently installed on a device. Instead, it can be referenced only as the dependency of an application module. A Harmony Archive (HAR) is a static shared package that can contain code, C++ libraries, resources, and configuration files. It enables modules and projects to share code related to ArkUI components, resources, and more. Unlike a Harmony Ability Package (HAP), a HAR cannot be independently installed on a device. Instead, it can be referenced only as the dependency of an application module.
## Creating a HAR Module ## Creating a HAR Module
You can [create a HAR module in DevEco Studio](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/creating_har_api9-0000001518082393-V3#section143510369612). To better protect your source code, enable obfuscation for the HAR module so that DevEco Studio compiles, obfuscates, and compresses code during HAR building. To enable obfuscation, open the **build-profile.json5** file of the HAR module and set **artifactType** to **obfuscation** as follows: You can [create a HAR module in DevEco Studio](https://developer.harmonyos.com/cn/docs/documentation/doc-guides-V3/creating_har_api9-0000001518082393-V3#section143510369612).
To better protect your source code, enable obfuscation for the HAR module so that DevEco Studio compiles, obfuscates, and compresses code during HAR building.
> **NOTE**
>
> Obfuscation is only available for ArkTS projects in the stage model.
### Obfuscation in API Version 9
In API version 9, obfuscation is disabled by default, and can be enabled by setting **artifactType** to **obfuscation** in the **build-profile.json5** file of the HAR module. The configuration is as follows:
```json ```json
{ {
...@@ -16,9 +26,43 @@ The value options of **artifactType** are as follows, with the default value bei ...@@ -16,9 +26,43 @@ The value options of **artifactType** are as follows, with the default value bei
- **original**: Code is not obfuscated. - **original**: Code is not obfuscated.
- **obfuscation**: Code is obfuscated using Uglify. - **obfuscation**: Code is obfuscated using Uglify.
> **NOTE** ### Obfuscation in API Version 10
>
> Obfuscation is available only in the stage model. Therefore, if **artifactType** is set to **obfuscation**, **apiType** must be set to **stageMode**. In API version 10, obfuscation is enabled by default, and can be set through the **enable** field under **ruleOptions** in the **build-profile.json5** file of the HAR module. The configuration is as follows:
```json
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
},
"consumerFiles": [
"./consumer-rules.txt"
]
}
}
},
],
"targets": [
{
"name": "default"
}
]
}
```
### Adaptation Guide
The **artifactType** field is forward compatible, and the original function is not affected. Yet, it is deprecated since API version 10, and you are advised to use the substitute as soon as possible.
## Precautions for HAR Development ## Precautions for HAR Development
- The HAR does not support the declaration of **abilities** and **extensionAbilities** in its configuration file. - The HAR does not support the declaration of **abilities** and **extensionAbilities** in its configuration file.
...@@ -95,7 +139,7 @@ To start with, [configure dependency](https://developer.harmonyos.com/cn/docs/do ...@@ -95,7 +139,7 @@ To start with, [configure dependency](https://developer.harmonyos.com/cn/docs/do
### Reference ArkUI Components in the HAR ### Reference ArkUI Components in the HAR
After configuring the dependency on the HAR, you can reference ArkUI components exported from the HAR by using **import**. The sample code is as follows: After configuring the dependency on the HAR, you can reference ArkUI components exported from the HAR by using **import**. The code snippet is as follows:
```js ```js
// entry/src/main/ets/pages/index.ets // entry/src/main/ets/pages/index.ets
import { MainPage } from "@ohos/library" import { MainPage } from "@ohos/library"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册