未验证 提交 892ab369 编写于 作者: O openharmony_ci 提交者: Gitee

!20517 翻译完成 19417+19378+20069:modify changlog

Merge pull request !20517 from ester.zhou/TR-19417
# ArkUI Subsystem ChangeLog # ArkUI Subsystem Changelog
## cl.arkui.1 Restrictions on Data Type Declarations of State Variables ## cl.arkui.1 Restrictions on Data Type Declarations of State Variables
1. The data types of state variables decorated by state decorators must be explicitly declared. They cannot be declared as **any** or **Date**. 1. The data types of state variables decorated by state decorators must be explicitly declared. They cannot be declared as **any**.
Example: Example:
...@@ -13,34 +13,13 @@ ...@@ -13,34 +13,13 @@
struct DatePickerExample { struct DatePickerExample {
// Incorrect: @State isLunar: any = false // Incorrect: @State isLunar: any = false
@State isLunar: boolean = false @State isLunar: boolean = false
// Incorrect: @State selectedDate: Date = new Date('2021-08-08')
private selectedDate: Date = new Date('2021-08-08')
build() { build() {
Column() { ...
Button('Switch Calendar')
.margin({ top: 30 })
.onClick(() => {
this.isLunar = !this.isLunar
})
DatePicker({
start: new Date('1970-1-1'),
end: new Date('2100-1-1'),
selected: this.selectedDate
})
.lunar(this.isLunar)
.onChange((value: DatePickerResult) => {
this.selectedDate.setFullYear(value.year, value.month, value.day)
console.info('select current date is: ' + JSON.stringify(value))
})
}.width('100%')
} }
} }
``` ```
![datePicker](../../../application-dev/reference/arkui-ts/figures/datePicker.gif)
2. The data type declaration of the **@State**, **@Provide**, **@Link**, or **@Consume** decorated state variables can consist of only one of the primitive data types or reference data types. 2. The data type declaration of the **@State**, **@Provide**, **@Link**, or **@Consume** decorated state variables can consist of only one of the primitive data types or reference data types.
The **Length**, **ResourceStr**, and **ResourceColor** types are combinations of primitive data types or reference data types. Therefore, they cannot be used by the aforementioned types of state variables. The **Length**, **ResourceStr**, and **ResourceColor** types are combinations of primitive data types or reference data types. Therefore, they cannot be used by the aforementioned types of state variables.
...@@ -76,17 +55,14 @@ ...@@ -76,17 +55,14 @@
**Change Impacts** **Change Impacts**
1. If the data type of a state variable decorated by a state decorator is declared as **any**, a build error will occur. 1. If the data type of a state variable decorated by a state decorator is declared as **any**, a build error message will be displayed.
```ts ```ts
// ArkTS:ERROR Please define an explicit type, not any. // ArkTS:WARN Please define an explicit type, not any.
@State isLunar: any = false @State isLunar: any = false
``` ```
2. If the data type of a state variable decorated by a state decorator is declared as **Date**, a build error will occur. 3. If the data type of a **@State**, **@Provide**, **@Link**, and or **@Consume** decorated state variable is Length, **ResourceStr**, or **ResourceColor**,
```ts a build error will occur.
// ArkTS:ERROR The @State property 'selectedDate' cannot be a 'Date' object.
@State selectedDate: Date = new Date('2021-08-08')
```
3. If the data type of a **@State**, **@Provide**, **@Link**, and or **@Consume** decorated state variable is Length, **ResourceStr**, or **ResourceColor**, a build error will occur.
```ts ```ts
/* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type, /* ArkTS:ERROR The state variable type here is 'ResourceStr', it contains both a simple type and an object type,
which are not allowed to be defined for state variable of a struct.*/ which are not allowed to be defined for state variable of a struct.*/
...@@ -100,7 +76,6 @@ N/A ...@@ -100,7 +76,6 @@ N/A
**Adaptation Guide** **Adaptation Guide**
1. Explicitly declare the data type for state variables decorated by state decorators. 1. Explicitly declare the data type for state variables decorated by state decorators.
2. If a state variable decorated by a state decorator uses the **Date** object, change it to a regular variable – a variable not decorated by any decorator.
3. 3.
Adapt the **@State**, **@Provide**, **@Link**, and **@Consume** decorated variables based on the following code snippet so that they do not use the **Length(string|number|Resource)**, **ResourceStr(string|Resource)**, and **ResourceColor(string|number|Color|Resource)** types: Adapt the **@State**, **@Provide**, **@Link**, and **@Consume** decorated variables based on the following code snippet so that they do not use the **Length(string|number|Resource)**, **ResourceStr(string|Resource)**, and **ResourceColor(string|number|Color|Resource)** types:
```ts ```ts
...@@ -115,24 +90,24 @@ N/A ...@@ -115,24 +90,24 @@ N/A
Comply with the following rules when using constructors to initialize member variables: Comply with the following rules when using constructors to initialize member variables:
| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **regular** | **@State** | **@Link** | **@Prop** | **@Provide** | **@Consume** | **@ObjectLink** | | **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **regular** | **@State** | **@Link** | **@Prop** | **@Provide** | **@Consume** | **@ObjectLink** |
|---------------------------------|----------------------------|------------|-----------|-----------|--------------|--------------|------------------| | -------------------------- | ----------- | ---------- | --------- | --------- | ------------ | ------------ | --------------- |
| **regular** | Supported | Supported | Supported | Supported | Not supported | Not supported | Supported | | **regular** | Supported | Supported | Supported | Supported | Not supported | Not supported | Supported |
| **@State** | Supported | Supported | Supported | Supported | Supported | Supported | Supported | | **@State** | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
| **@Link** | Not supported | Supported (1) | Supported (1) | Supported (1) | Supported (1) | Supported (1) | Supported (1) | | **@Link** | Not supported | Supported (1) | Supported (1) | Supported (1) | Supported (1) | Supported (1) | Supported (1) |
| **@Prop** | Supported | Supported | Supported | Supported | Supported | Supported | Supported | | **@Prop** | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
| **@Provide** | Supported | Supported | Supported | Supported | Supported | Supported | Supported | | **@Provide** | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
| **@Consume** | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | | **@Consume** | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported |
| **@ObjectLink** | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | | **@ObjectLink** | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported | Not supported |
| **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **@StorageLink** | **@StorageProp** | **@LocalStorageLink** | **@LocalStorageProp** | | **From the Variable in the Parent Component (Right) to the Variable in the Child Component (Below)**| **@StorageLink** | **@StorageProp** | **@LocalStorageLink** | **@LocalStorageProp** |
|------------------|------------------|------------------|-----------------------|------------------------| | -------------------------- | ---------------- | ---------------- | --------------------- | --------------------- |
| **regular** | Supported | Not supported | Not supported | Not supported | | **regular** | Supported | Not supported | Not supported | Not supported |
| **@State** | Supported | Supported | Supported | Supported | | **@State** | Supported | Supported | Supported | Supported |
| **@Link** | Supported (1) | Supported (1) | Supported (1) | Supported (1) | | **@Link** | Supported (1) | Supported (1) | Supported (1) | Supported (1) |
| **@Prop** | Supported | Supported | Supported | Supported | | **@Prop** | Supported | Supported | Supported | Supported |
| **@Provide** | Supported | Supported | Supported | Supported | | **@Provide** | Supported | Supported | Supported | Supported |
| **@Consume** | Not supported | Not supported | Not supported | Not supported | | **@Consume** | Not supported | Not supported | Not supported | Not supported |
| **@ObjectLink** | Not supported | Not supported | Not supported | Not supported | | **@ObjectLink** | Not supported | Not supported | Not supported | Not supported |
> **NOTE** > **NOTE**
> >
...@@ -144,7 +119,7 @@ Comply with the following rules when using constructors to initialize member var ...@@ -144,7 +119,7 @@ Comply with the following rules when using constructors to initialize member var
**Change Impacts** **Change Impacts**
1. Variables decorated by **@LocalStorageLink** and **@LocalStorageProp** cannot be initialized from the parent component. 1. **@LocalStorageLink** and **@LocalStorageProp** variables cannot be initialized from the parent component. Otherwise, a build error message will be displayed.
```ts ```ts
@Entry @Entry
@Component @Component
...@@ -152,10 +127,10 @@ Comply with the following rules when using constructors to initialize member var ...@@ -152,10 +127,10 @@ Comply with the following rules when using constructors to initialize member var
build() { build() {
Column() { Column() {
Child({ Child({
/* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot /* ArkTS:WARN Property 'simpleVarName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */ initialize here (forbidden to specify). */
simpleVarName: 1, simpleVarName: 1,
/* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot /* ArkTS:WARN Property 'objectName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */ initialize here (forbidden to specify). */
objectName: new ClassA("x") objectName: new ClassA("x")
}) })
...@@ -210,11 +185,11 @@ Comply with the following rules when using constructors to initialize member var ...@@ -210,11 +185,11 @@ Comply with the following rules when using constructors to initialize member var
N/A N/A
**Adaptation Guide** **Adaptation Guide**
1. When building a child component, do not perform the build on the variables decorated by **@LocalStorageLink** and **@LocalStorageProp** in the child component. 1. When building a child component, do not assign values to the variables decorated by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
To change these variables from the parent component, use the API provided by the **LocalStorage** (such as the **set** API) to assign values to them. To change these variables from the parent component, use the API provided by the **LocalStorage** (such as the **set** API) to assign values to them.
2. For details about how to use **@ObjectLink**, see [@Observed and @ObjectLink](../../../application-dev/quick-start/arkts-observed-and-objectlink.md). 2. For details about how to use **@ObjectLink**, see [\@Observed and \@ObjectLink Decorators: Observing Attribute Changes in Nested Class Objects](../../../application-dev/quick-start/arkts-observed-and-objectlink.md).
## cl.arkui.3 Change of the onScrollBegin Event of the \<List> and \<Scroll> Components ## cl.arkui.3 Change of the onScrollBegin Event of the \<List> and \<Scroll> Components
...@@ -226,13 +201,13 @@ The **onScrollBegin** event is deprecated and must be replaced with the **onScro ...@@ -226,13 +201,13 @@ The **onScrollBegin** event is deprecated and must be replaced with the **onScro
**Key API/Component Changes** **Key API/Component Changes**
| Old Event | New Event | | Old Event | New Event |
|------------------ | ------------------- | | ---------------------------------------- | ---------------------------------------- |
| onScrollBegin(event: (dx: number, dy: number) => { dxRemain: number, dyRemain: number }) | onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number }) | | onScrollBegin(event: (dx: number, dy: number) => { dxRemain: number, dyRemain: number }) | onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number }) |
For details about the **onScrollFrameBegin** event, see the following: For details about the **onScrollFrameBegin** event, see the following:
- [Scroll](../../../application-dev/reference/arkui-ts/ts-container-scroll.md#events) - [Scroll Events](../../../application-dev/reference/arkui-ts/ts-container-scroll.md#events)
- [List](../../../application-dev/reference/arkui-ts/ts-container-list.md#events) - [List Events](../../../application-dev/reference/arkui-ts/ts-container-list.md#events)
**Adaptation Guide** **Adaptation Guide**
......
# ArkUI Subsystem Changelog
## cl.arkui.1 Restrictions on Data Type Declarations of State Variables
The data types of state variables decorated by state decorators must be explicitly declared. They cannot be declared as **any**.
**Example**
```ts
// xxx.ets
@Entry
@Component
struct DatePickerExample {
// Incorrect: @State isLunar: any = false
@State isLunar: boolean = false
build() {
...
}
}
```
**Change Impacts**
If the data type of a state variable decorated by a state decorator is declared as **any**, a WARN-level (previously ERROR-level) build error will occur.
```ts
// ArkTS:ERROR Please define an explicit type, not any.
@State isLunar: any = false
```
**Key API/Component Changes**
N/A
**Adaptation Guide**
Explicitly declare the data type for state variables decorated by state decorators.
## cl.arkui.2 Initialization Rules and Restrictions of Custom Components' Member Variables
**@LocalStorageLink** and **@LocalStorageProp** variables cannot be initialized from the parent component.
**Example**
```ts
let NextID: number = 0;
@Observed
class ClassA {
public id: number;
public c: number;
constructor(c: number) {
this.id = NextID++;
this.c = c;
}
}
@Entry
@Component
struct LocalStorageComponent {
build() {
Column() {
Child({
/* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */
simpleVarName: 1,
/* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot
initialize here (forbidden to specify). */
objectName: new ClassA(1)
})
}
}
}
@Component
struct Child {
@LocalStorageLink("storageSimpleProp") simpleVarName: number = 0;
@LocalStorageProp("storageObjectProp") objectName: ClassA = new ClassA(1);
build() {
}
}
```
**Change Impacts**
If **@LocalStorageLink** and **@LocalStorageProp** variables are initialized from the parent component, a WARN-level (previously ERROR-level) build error will occur.
**Key API/Component Changes**
N/A
**Adaptation Guide**
When building a child component, do not assign values to the variables by **@LocalStorageLink** and **@LocalStorageProp** in the child component.
To change these variables from the parent component, use the API provided by the **LocalStorage** (such as the **set** API) to assign values to them.
# ArkUI Subsystem Changelog
## cl.arkui.1 Change in the Priority of alignContent and align Attributes for \<Stack>
Changed the priority of **alignContent** and **align** as follows:
API version 9 and earlier: The universal attribute **align** prevails.
API version 10 and later: The last set attribute prevails.
When two attributes provide the same functions, the last set attribute takes effect. This rule applies to **alignContent** and **align**, both of which set the alignment mode when used for the **\<Stack>** component.
**Example**
```ts
// xxx.ets
@Entry
@Component
struct StackExample {
build() {
Stack({alignContent:Alignment.Start}){
Text("Stack's child").backgroundColor(Color.Brown).height("100").width(100)
}
.width(300).height(300)
.backgroundColor(Color.Pink)
.align(Alignment.Center)
.alignContent(Alignment.TopEnd)
}
}
```
API version 9 and earlier: Child components are arranged based on the universal attribute **align**.
![stack](figures/api9.png)
API version 10 and later: Child components are arranged based on the **alignContent** attribute, which is set at a later time than **align**.
![stack](figures/api10_and_later.png)
**Change Impact**
When both **alignContent** and **align** attributes are set, the last set attribute prevails.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册