diff --git a/en/application-dev/database/database-mdds-guidelines.md b/en/application-dev/database/database-mdds-guidelines.md index dd1594215a10d1c93c9825444253484ed8956e05..e6995db8bf2eed90111952d8104bb458b2dafe51 100644 --- a/en/application-dev/database/database-mdds-guidelines.md +++ b/en/application-dev/database/database-mdds-guidelines.md @@ -6,6 +6,7 @@ The Distributed Data Service (DDS) implements synchronization of application dat ## Available APIs + For details about the APIs related to distributed data, see [Distributed Data Management](../reference/apis/js-apis-distributed-data.md). @@ -13,13 +14,13 @@ For details about the APIs related to distributed data, see [Distributed Data Ma | API | Description | | ------------------------------------------------------------ | ----------------------------------------------- | -| createKVManager(config:KVManagerConfig,callback:AsyncCallback<KVManager>):void
createKVManager(config:KVManagerConfig):Promise<KVManager> | Creates a **KVManager** object for database management.| -| getKVStore<TextendsKVStore>(storeId:string,options:Options,callback:AsyncCallback<T>):void
getKVStore<TextendsKVStore>(storeId:string,options:Options):Promise<T> | Obtains a KV store with the specified **Options** and **storeId**.| -| put(key:string,value:Uint8Array\|string\|number\|boolean,callback:AsyncCallback<void>):void
put(key:string,value:Uint8Array\|string\|number\|boolean):Promise<void> | Inserts and updates data. | -| delete(key:string,callback:AsyncCallback<void>):void
delete(key:string):Promise<void> | Deletes data. | -| get(key:string,callback:AsyncCallback<Uint8Array\|string\|boolean\|number>):void
get(key:string):Promise<Uint8Array\|string\|boolean\|number> | Queries data. | -| on(event:'dataChange',type:SubscribeType,observer:Callback<ChangeNotification>):void
on(event:'syncComplete',syncCallback:Callback<Array<[string,number]>>):void | Subscribes to data changes in the KV store. | -| sync(deviceIdList:string[],mode:SyncMode,allowedDelayMs?:number):void | Triggers database synchronization in manual mode. | +| createKVManager(config: KVManagerConfig, callback: AsyncCallback<KVManager>): void
createKVManager(config: KVManagerConfig): Promise<KVManager> | Creates a **KVManager** object for database management.| +| getKVStore<TextendsKVStore>(storeId: string, options: Options, callback: AsyncCallback<T>): void
getKVStore<TextendsKVStore>(storeId: string, options: Options): Promise<T> | Obtains a KV store with the specified **Options** and **storeId**.| +| put(key: string, value: Uint8Array\|string\|number\|boolean, callback: AsyncCallback<void>): void
put(key: string, value: Uint8Array\|string\|number\|boolean): Promise<void> | Inserts and updates data. | +| delete(key: string, callback: AsyncCallback<void>): void
delete(key: string): Promise<void> | Deletes data. | +| get(key: string, callback: AsyncCallback<Uint8Array\|string\|boolean\|number>): void
get(key: string): Promise<Uint8Array\|string\|boolean\|number> | Queries data. | +| on(event: 'dataChange', type: SubscribeType, observer: Callback<ChangeNotification>): void
on(event: 'syncComplete', syncCallback: Callback<Array<[string,number]>>): void | Subscribes to data changes in the KV store. | +| sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void | Triggers database synchronization in manual mode. | @@ -29,19 +30,50 @@ For details about the APIs related to distributed data, see [Distributed Data Ma The following uses a single KV store as an example to describe the development procedure. 1. Import the distributed data module. + ```js import distributedData from '@ohos.data.distributedData'; ``` +2. Apply for the required permission if data synchronization is required. -2. Create a **KvManager** instance based on the specified **KvManagerConfig** object. - - (1) Create a **KvManagerConfig** object based on the application context. + You need to configure the request permission in the **config.json** file. The sample code is as follows: + + ```json + { + "module": { + "reqPermissions": [ + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ] + } + } + ``` + This permission must also be granted by the user when the application is started for the first time. The sample code is as follows: + + ```js + import featureAbility from '@ohos.ability.featureAbility'; + + function grantPermission() { + console.info('grantPermission'); + let context = featureAbility.getContext(); + context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) { + console.info(`result.requestCode=${result.requestCode}`) + + }) + console.info('end grantPermission'); + } + + grantPermission(); + ``` + +3. Create a **KvManager** instance based on the specified **KvManagerConfig** object. + + 1. Create a **kvManagerConfig** object based on the application context. + 2. Create a **kvManager** instance. - (2) Create a **KvManager** instance. - The sample code is as follows: - - ``` + ```js let kvManager; try { const kvManagerConfig = { @@ -63,13 +95,11 @@ The following uses a single KV store as an example to describe the development p console.log("An unexpected error occurred. Error:" + e); } ``` - - -3. Create and obtain a single KV store. - (1) Declare the ID of the single KV store to create. +4. Create and obtain a single KV store. - (2) Create a single KV store. You are advised to disable automatic synchronization (**autoSync:false**) and call **sync** when a synchronization is required. + 1. Declare the ID of the single KV store to create. + 2. Create a single KV store. You are advised to disable automatic synchronization (`autoSync:false`) and call `sync` when a synchronization is required. The sample code is as follows: ```js @@ -99,8 +129,9 @@ The following uses a single KV store as an example to describe the development p > **NOTE** > > For data synchronization between networked devices, you are advised to open the distributed KV store during application startup to obtain the database handle. With this database handle (`kvStore` in this example), you can perform operations, such as inserting data into the KV store, without creating the KV store repeatedly during the lifecycle of the handle. + +5. Subscribe to changes in the distributed data. -4. Subscribe to changes in the distributed data.
The following is the sample code for subscribing to the data changes of a single KV store: ```js kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_ALL, function (data) { @@ -108,11 +139,10 @@ The following uses a single KV store as an example to describe the development p }); ``` -5. Write data to the single KV store. +6. Write data to the single KV store. - (1) Construct the key and value to be written into the single KV store. - - (2) Write key-value pairs into the single KV store. + 1. Construct the `Key` and `Value` to be written into the single KV store. + 2. Write key-value pairs into the single KV store. The following is the sample code for writing key-value pairs of the string type into the single KV store: @@ -132,11 +162,10 @@ The following uses a single KV store as an example to describe the development p } ``` -6. Query data in the single KV store. - - (1) Construct the key to be queried from the single KV store. +7. Query data in the single KV store. - (2) Query data from the single KV store. + 1. Construct the `Key` to be queried from the single KV store. + 2. Query data from the single KV store. The following is the sample code for querying data of the string type from the single KV store: ```js @@ -158,7 +187,8 @@ The following uses a single KV store as an example to describe the development p } ``` -7. Synchronize data to other devices.
+8. Synchronize data to other devices. + Select the devices in the same network and the synchronization mode to synchronize data. > **NOTE** diff --git a/en/application-dev/database/database-mdds-overview.md b/en/application-dev/database/database-mdds-overview.md index 26efa7491805e871017db3593f5fa50d947717f5..cfe264a4f7eb06cd51cb834bc3e38ee27e649a14 100644 --- a/en/application-dev/database/database-mdds-overview.md +++ b/en/application-dev/database/database-mdds-overview.md @@ -1,105 +1,103 @@ # Distributed Data Service Overview -The distributed data service (DDS) implements distributed database collaboration across devices for applications. +The distributed data service (DDS) implements distributed database collaboration across devices for applications. Applications save data to distributed databases by calling the DDS APIs. The DDS isolates data of different applications based on a triplet of account, application, and database to ensure secure data access. The DDS synchronizes application data between trusted devices to provide users with consistent data access experience on different devices. You do not need to care about the implementation of the database locking mechanism. + ## Basic Concepts -- **KV data model** +### KV Data Model - The key-value \(KV\) data model allows data to be organized, indexed, and stored in key-value pairs. +The key-value (KV) data model allows data to be organized, indexed, and stored in KV pairs. - The KV data model is suitable for storing service data that is not related. It provides better read and write performance than the SQL database. The KV data model is widely used in distributed scenarios because it handles database version compatibility issues and data synchronization conflicts easily. The distributed database is based on the KV data model and provides KV-based access interfaces. +The KV data model is suitable for storing service data that is not related. It provides better read and write performance than the SQL database. The KV data model is widely used in distributed scenarios because it handles database version compatibility issues and data synchronization conflicts easily. The distributed database is based on the KV data model and provides KV-based access interfaces. -- **Distributed database transactions** +### Distributed Database Transaction - Distributed database transactions include local transactions \(same as the transactions of traditional databases\) and synchronization transactions. Synchronization transactions allow data to be synchronized between devices by local transaction. Synchronization of a local transaction modification either succeeds or fails on all the devices. +Distributed database transactions include local transactions (same as the transactions of traditional databases) and synchronization transactions. Synchronization transactions allow data to be synchronized between devices by local transaction. Synchronization of a local transaction modification either succeeds or fails on all the devices. -- **Distributed database consistency** +### Distributed Database Consistency - In a distributed scenario, cross-device collaboration demands consistent data between the devices in the same network. The data consistency can be classified into the following types: +In a distributed scenario, cross-device collaboration demands consistent data between the devices in the same network. The data consistency can be classified into the following types: - - **Strong consistency**: When data is inserted, deleted, or modified on a device, other devices in the same network will obtain the latest data immediately. - - **Weak consistency**: When data is added, deleted, or modified on a device, other devices in the same network may or may not obtain the latest data. The data on these devices may be inconsistent after a certain period of time. - - **Eventual consistency**: When data is added, deleted, or modified on a device, other devices in the same network may not obtain the latest data immediately. However, data on these devices will become consistent after a certain period of time. +- **Strong consistency**: When data is inserted, deleted, or modified on a device, other devices in the same network will obtain the latest data immediately. +- **Weak consistency**: When data is added, deleted, or modified on a device, other devices in the same network may or may not obtain the latest data. The data on these devices may be inconsistent after a certain period of time. +- **Eventual consistency**: When data is added, deleted, or modified on a device, other devices in the same network may not obtain the latest data immediately. However, data on these devices will become consistent after a certain period of time. - Strong consistency has high requirements on distributed data management and may be used in distributed server deployment. The DDS supports only the eventual consistency because mobile devices are not always online and the network has no center. +Strong consistency has high requirements on distributed data management and may be used in distributed server deployment. The DDS supports only the eventual consistency because mobile devices are not always online and the network has no center. -- **Distributed database synchronization** +### Distributed Database Synchronization - After discovering and authenticating a device, the underlying communication component notifies the upper-layer application \(including the DDS\) that the device goes online. The DDS then establishes an encrypted transmission channel to synchronize data between the two devices. +After discovering and authenticating a device, the underlying communication component notifies the upper-layer application (including the DDS) that the device goes online. The DDS then establishes an encrypted transmission channel to synchronize data between the two devices. - The DDS provides the following synchronization modes: +The DDS provides the following synchronization modes: - - **Manual synchronization**: Applications call **sync** to trigger a synchronization. The list of devices to be synchronized and the synchronization mode must be specified. The synchronization mode can be **PULL\_ONLY** \(pulling remote data to the local end\), **PUSH\_ONLY** \(pushing local data to the remote end\), or **PUSH\_PULL** \(pushing local data to the remote end and pulling remote data to the local end\). The internal interface supports condition-based synchronization. The data that meets the conditions can be synchronized to the remote end. - - **Automatic synchronization**: includes full synchronization and condition-based subscription synchronization. In full synchronization, the distributed database automatically pushes local data to the remote end and pulls remote data to the local end when a device goes online or application data is updated. Applications do not need to call **sync**. The internal interface supports condition-based subscription synchronization. The data that meets the subscription conditions on the remote end is automatically synchronized to the local end. +- **Manual synchronization**: Applications call **sync()** to trigger a synchronization. The list of devices to be synchronized and the synchronization mode must be specified. The synchronization mode can be **PULL_ONLY** (pulling remote data to the local end), **PUSH_ONLY** (pushing local data to the remote end), or **PUSH_PULL** (pushing local data to the remote end and pulling remote data to the local end). The internal interface supports condition-based synchronization. The data that meets the conditions can be synchronized to the remote end. +- **Automatic synchronization**: includes full synchronization and condition-based subscription synchronization. In full synchronization, the distributed database automatically pushes local data to the remote end and pulls remote data to the local end when a device goes online or application data is updated. Applications do not need to call **sync()**. The internal interface supports condition-based subscription synchronization. The data that meets the subscription conditions on the remote end is automatically synchronized to the local end. -- **Single KV store** +### Single KV Store - Data is saved locally in the unit of a single KV entry. Only one entry is saved for each key. Data can be modified only locally and synchronized to remote devices in sequence based on the update time. +Data is saved locally in the unit of a single KV entry. Only one entry is saved for each key. Data can be modified only locally and synchronized to remote devices in sequence based on the update time. -- **Device KV store** +### Device KV Store - The device KV store is based on the single KV store. The local device ID is added to the key when KV data is stored in the device KV store. Data can be isolated, managed, and queried by device. However, the data synchronized from remote devices cannot be modified locally. +The device KV store is based on the single KV store. The local device ID is added to the key when KV data is stored in the device KV store. Data can be isolated, managed, and queried by device. However, the data synchronized from remote devices cannot be modified locally. -- **Conflict resolution** +### Conflict Resolution - A data conflict occurs when multiple devices modify the same data and commit the modification to the database. The last write wins \(LWW\) is the default conflict resolution policy used for data conflicts. Based on the commit timestamps, the data with a later timestamp is used. Currently, customized conflict resolution policies are not supported. +A data conflict occurs when multiple devices modify the same data and commit the modification to the database. The last write wins (LWW) is the default conflict resolution policy used for data conflicts. Based on the commit timestamps, the data with a later timestamp is used. Currently, customized conflict resolution policies are not supported. -- **Schema-based database management and data query based on predicates** +### Schema-based Database Management and Predicate-based Data Query - A schema is specified when you create or open a single KV store. Based on the schema, the database detects the value format of key-value pairs and checks the value structure. Based on the fields in the values, the database implements index creation and predicate-based query. +A schema is specified when you create or open a single KV store. Based on the schema, the database detects the value format of KV pairs and checks the value structure. Based on the fields in the values, the database implements index creation and predicate-based query. -- **Distributed database backup** +### Distributed Database Backup - The DDS provides the database backup capability. You can set **backup** to **true** to enable daily backup. If a distributed database is damaged, the DDS deletes the database and restores the most recent data from the backup database. If no backup database is available, the DDS creates one. The DDS can also back up encrypted databases. +The DDS provides the database backup capability. You can set **backup** to **true** to enable daily backup. If a distributed database is damaged, the DDS deletes the database and restores the most recent data from the backup database. If no backup database is available, the DDS creates one. The DDS can also back up encrypted databases. ## Working Principles -The DDS supports distributed management of application database data in the OpenHarmony system. Data can be synchronized between multiple devices with the same account, delivering a consistent user experience across devices. The DDS consists of the following: +The DDS supports distributed management of application database data in the OpenHarmony system. Data can be synchronized between multiple devices with the same account, delivering a consistent user experience across devices. -- **APIs** +The DDS consists of the following: - The DDS provides APIs to create databases, access data, and subscribe to data. The APIs support the KV data model and common data types. They are highly compatible and easy to use, and can be released. +- **APIs**
The DDS provides APIs to create databases, access data, and subscribe to data. The APIs support the KV data model and common data types. They are highly compatible and easy to use, and can be released. -- **Service component** +- **Service component**
The service component implements management of metadata, permissions, encryption, backup and restore, and multiple users, and completes initialization of the storage component, synchronization component, and communication adaptation layer of the distributed database. - The service component implements management of metadata, permissions, encryption, backup and restore, and multiple users, and completes initialization of the storage component, synchronization component, and communication adaptation layer of the distributed database. +- **Storage component**
The storage component implements data access, data reduction, transactions, snapshots, database encryption, data combination, and conflict resolution. -- **Storage component** +- **Synchronization component**
The synchronization component interacts with the storage component and the communication adaptation layer to maintain data consistency between online devices. It synchronizes data generated on the local device to other devices and merges data from other devices into the local device. - The storage component implements data access, data reduction, transactions, snapshots, database encryption, data combination, and conflict resolution. +- **Communication adaptation layer**
The communication adaptation layer calls APIs of the underlying public communication layer to create and connect to communication channels, receive device online and offline messages, update metadata of the connected and disconnected devices, send device online and offline messages to the synchronization component. The synchronization component updates the list of connected devices, and calls the APIs of the communication adaption layer to encapsulate data and send the data to the connected devices. -- **Synchronization component** +Applications call the DDS APIs to create, access, and subscribe to distributed databases. The APIs store data to the storage component based on the capabilities provided by the service component. The storage component interacts with the synchronization component to synchronize data. The synchronization component uses the communication adaptation layer to synchronize data to remote devices, which update the data in the storage component and provide the data for applications through service APIs. - The synchronization component interacts with the storage component and the communication adaptation layer to maintain data consistency between online devices. It synchronizes data generated on the local device to other devices and merges data from other devices into the local device. -- **Communication adaptation layer** +**Figure 1** How DDS works - The communication adaptation layer calls APIs of the underlying public communication layer to create and connect to communication channels, receive device online and offline messages, update metadata of the connected and disconnected devices, send device online and offline messages to the synchronization component. The synchronization component updates the list of connected devices, and calls the APIs of the communication adaption layer to encapsulate data and send the data to the connected devices. +![](figures/en-us_image_0000001183386164.png) -Applications call the DDS APIs to create, access, and subscribe to distributed databases. The APIs store data to the storage component based on the capabilities provided by the service component. The storage component interacts with the synchronization component to synchronize data. The synchronization component uses the communication adaptation layer to synchronize data to remote devices, which update the data in the storage component and provide the data for applications through service APIs. -**Figure 1** How DDS works +## Constraints +- The DDS supports the KV data model only. It does not support foreign keys or triggers of the relational database. -![](figures/en-us_image_0000001183386164.png) +- The KV data model specifications supported by the DDS are as follows: -## Constraints + - For each record in a device KV store, the key must be less than or equal to 896 bytes and the value be less than 4 MB. + - For each record in a single KV store, the key must be less than or equal to 1 KB and the value be less than 4 MB. + - An application can open a maximum of 16 KV stores simultaneously. + +- The data that needs to be synchronized between devices should be stored in distributed databases rather than local databases. -- The DDS supports the KV data model only. It does not support foreign keys or triggers of the relational database. -- The KV data model specifications supported by the DDS are as follows: - - For each record in a device KV store, the key must be less than or equal to 896 bytes and the value be less than 4 MB. - - For each record in a single KV store, the key must be less than or equal to 1 KB and the value be less than 4 MB. - - An application can open a maximum of 16 KV stores simultaneously. +- The DDS does not support customized conflict resolution policies. -- The data that needs to be synchronized between devices should be stored in distributed databases rather than local databases. -- The DDS does not support customized conflict resolution policies. -- The maximum number of access requests to the KvStore API is 1000 per second and 10000 per minute. The maximum number of access requests to the KvManager API is 50 per second and 500 per minute. -- Blocking operations, such as modifying UI components, are not allowed in the distributed database event callback. +- The maximum number of access requests to the KvStore API is 1000 per second and 10000 per minute. The maximum number of access requests to the KvManager API is 50 per second and 500 per minute. +- Blocking operations, such as modifying UI components, are not allowed in the distributed database event callback. diff --git a/en/application-dev/database/database-relational-guidelines.md b/en/application-dev/database/database-relational-guidelines.md index 688835122445f6800d83a76fa0633b0be64f385c..7d4ded2757229593c6220a51f92d5b972c3b5a13 100644 --- a/en/application-dev/database/database-relational-guidelines.md +++ b/en/application-dev/database/database-relational-guidelines.md @@ -16,8 +16,8 @@ The table below describes the APIs available for creating and deleting an RDB st | API| Description| | -------- | -------- | -|getRdbStore(config:StoreConfig,version:number):Promise<RdbStore> | Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
- **config**: configuration of the RDB store.
- **version**: version of the RDB store.| -| deleteRdbStore(name:string):Promise<void> | Deletes an RDB store. This API uses a promise to return the result.
- **name**: name of the RDB store to delete.| +|getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> | Obtains an RDB store. This API uses a promise to return the result. You can set parameters for the RDB store based on service requirements and call APIs to perform data operations.
- **config**: configuration of the RDB store.
- **version**: version of the RDB store.| +| deleteRdbStore(name: string): Promise<void> | Deletes an RDB store. This API uses a promise to return the result.
- **name**: name of the RDB store to delete.| ### Managing Data in an RDB Store @@ -31,7 +31,7 @@ The **RDB** module provides APIs for inserting, deleting, updating, and querying | Class| API| Description| | -------- | -------- | -------- | - | RdbStore | insert(name:string,values:ValuesBucket):Promise<number> | Inserts a row of data into a table. This API uses a promise to return the result.
If the operation is successful, the row ID will be returned; otherwise, **-1** will be returned.
- **name**: name of the target table.
- **values**: data to be inserted into the table.| + | RdbStore | insert(name: string, values: ValuesBucket): Promise<number> | Inserts a row of data into a table. This API uses a promise to return the result.
If the operation is successful, the row ID will be returned; otherwise, **-1** will be returned.
- **name**: name of the target table.
- **values**: data to be inserted into the table.| - **Updating Data** @@ -41,7 +41,7 @@ The **RDB** module provides APIs for inserting, deleting, updating, and querying | Class| API| Description| | -------- | -------- | -------- | - | RdbStore | update(values:ValuesBucket,rdbPredicates:RdbPredicates):Promise\ | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.
Return value: number of rows updated.
- **values**: data to update, which is stored in **ValuesBucket**.
- **rdbPredicates**: conditions for updating data.| + | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise\ | Updates data based on the specified **RdbPredicates** object. This API uses a promise to return the result.
Return value: number of rows updated.
- **values**: data to update, which is stored in **ValuesBucket**.
- **rdbPredicates**: conditions for updating data.| - **Deleting Data** @@ -51,7 +51,7 @@ The **RDB** module provides APIs for inserting, deleting, updating, and querying | Class| API| Description| | -------- | -------- | -------- | - | RdbStore | delete(rdbPredicates:RdbPredicates):Promise\ | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.
Return value: number of rows updated.
- **rdbPredicates**: conditions for deleting data.| + | RdbStore | delete(rdbPredicates: RdbPredicates): Promise\ | Deletes data from the RDB store based on the specified **RdbPredicates** object. This API uses a promise to return the result.
Return value: number of rows updated.
- **rdbPredicates**: conditions for deleting data.| - **Querying data** @@ -64,8 +64,8 @@ The **RDB** module provides APIs for inserting, deleting, updating, and querying | Class| API| Description| | -------- | -------- | -------- | - | RdbStore | query(rdbPredicates:RdbPredicates,columns:Array):Promise<ResultSet> | Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
- **rdbPredicates**: conditions for querying data.
- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.| - | RdbStore | querySql(sql:string,bindArgs?:Array<ValueType>):Promise<ResultSet> | Queries data using the specified SQL statement. This API uses a promise to return the result.
- **sql**: SQL statement.
- **bindArgs**: arguments in the SQL statement.| + | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet> | Queries data from the RDB store based on specified conditions. This API uses a promise to return the result.
- **rdbPredicates**: conditions for querying data.
- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.| + | RdbStore | querySql(sql: string, bindArgs?: Array<ValueType>): Promise<ResultSet> | Queries data using the specified SQL statement. This API uses a promise to return the result.
- **sql**: SQL statement.
- **bindArgs**: arguments in the SQL statement.| ### Using Predicates @@ -77,11 +77,11 @@ The table below lists common predicates. For more information about predicates, | Class| API| Description| | -------- | -------- | -------- | -| RdbPredicates | equalTo(field:string,value:ValueType):RdbPredicates | Sets an **RdbPredicates** object to match the field with data type **ValueType** and value equal to the specified value.
- **field**: column name in the database table.
- **value**: value to match the **RdbPredicates**.
- **RdbPredicates**: **RdbPredicates** object created.| -| RdbPredicates | notEqualTo(field:string,value:ValueType):RdbPredicates | Sets an **RdbPredicates** object to match the field with data type **ValueType** and value not equal to the specified value.
- **field**: column name in the database table.
- **value**: value to match the **RdbPredicates**.
- **RdbPredicates**: **RdbPredicates** object created.| -| RdbPredicates | or():RdbPredicates | Adds the OR condition to the **RdbPredicates** object.
- **RdbPredicates**: **RdbPredicates** with the OR condition.| -| RdbPredicates | and():RdbPredicates | Adds the AND condition to the **RdbPredicates** object.
- **RdbPredicates**: **RdbPredicates** with the AND condition.| -| RdbPredicates | contains(field:string,value:string):RdbPredicats | Sets an **RdbPredicates** object to match a string that contains the specified value.
- **field**: column name in the database table.
- **value**: value to match the **RdbPredicates**.
- **RdbPredicates**: **RdbPredicates** object created.| +| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | Sets an **RdbPredicates** object to match the field with data type **ValueType** and value equal to the specified value.
- **field**: column name in the database table.
- **value**: value to match the **RdbPredicates**.
- **RdbPredicates**: **RdbPredicates** object created.| +| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | Sets an **RdbPredicates** object to match the field with data type **ValueType** and value not equal to the specified value.
- **field**: column name in the database table.
- **value**: value to match the **RdbPredicates**.
- **RdbPredicates**: **RdbPredicates** object created.| +| RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates** object.
- **RdbPredicates**: **RdbPredicates** with the OR condition.| +| RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates** object.
- **RdbPredicates**: **RdbPredicates** with the AND condition.| +| RdbPredicates | contains(field: string, value: string): RdbPredicats | Sets an **RdbPredicates** object to match a string that contains the specified value.
- **field**: column name in the database table.
- **value**: value to match the **RdbPredicates**.
- **RdbPredicates**: **RdbPredicates** object created.| ### Using the Result Set @@ -97,12 +97,12 @@ For details about how to use result set APIs, see [Result Set](../reference/apis | Class| API| Description| | -------- | -------- | -------- | -| ResultSet | goToFirstRow():boolean | Moves to the first row of the result set.| -| ResultSet | getString(columnIndex:number):string | Obtains the value in the form of a string based on the specified column and current row.| -| ResultSet | getBlob(columnIndex:number):Uint8Array | Obtains the value in the form of a byte array based on the specified column and the current row.| -| ResultSet | getDouble(columnIndex:number):number | Obtains the value in the form of double based on the specified column and current row.| -| ResultSet | getLong(columnIndex:number):number | Obtains the value in the form of a long integer based on the specified column and current row. | -| ResultSet | close():void | Closes the result set.| +| ResultSet | goToFirstRow(): boolean | Moves to the first row of the result set.| +| ResultSet | getString(columnIndex:number): string | Obtains the value in the form of a string based on the specified column and current row.| +| ResultSet | getBlob(columnIndex:number): Uint8Array | Obtains the value in the form of a byte array based on the specified column and the current row.| +| ResultSet | getDouble(columnIndex:number): number | Obtains the value in the form of double based on the specified column and current row.| +| ResultSet | getLong(columnIndex:number): number | Obtains the value in the form of a long integer based on the specified column and current row. | +| ResultSet | close(): void | Closes the result set.| @@ -148,7 +148,7 @@ You can obtain the distributed table name for a remote device based on the local | Class| API| Description| | -------- | -------- | -------- | -| RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback>): void;| Unregisters the observer of the specified type for the RDB store. This API uses a callback to return the result.
- **type**: subscription type. **SUBSCRIBE_TYPE_REMOTE** means to subscribe to remote data changes.
- **observer**: observer to unregister.| +| RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback>): void;| Unregisters the observer of the specified type for the RDB store. This method uses a callback to return the result.
- **type**: subscription type. **SUBSCRIBE_TYPE_REMOTE** means to subscribe to remote data changes.
- **observer**: observer to unregister.| ## How to Develop diff --git a/en/application-dev/database/database-storage-guidelines.md b/en/application-dev/database/database-storage-guidelines.md index 6d5ed225c67dc43d7024fd0e609e8f5eb18c38ea..891797826db611ede738dd6ffeb105eba691a1f9 100644 --- a/en/application-dev/database/database-storage-guidelines.md +++ b/en/application-dev/database/database-storage-guidelines.md @@ -90,9 +90,9 @@ Use the following APIs to delete a **Storage** instance or data file. context.getFilesDir().then((filePath) => { path = filePath; console.info("======================>getFilesDirPromsie====================>"); + + let promise = dataStorage.getStorage(path + '/mystore'); }); - - let promise = dataStorage.getStorage(path + '/mystore'); ``` @@ -118,18 +118,19 @@ Use the following APIs to delete a **Storage** instance or data file. Use the **get\(\)** method of the **Storage** class to read data. - ```js - promise.then((storage) => { - let getPromise = storage.get('startup', 'default'); - getPromise.then((value) => { - console.info("The value of startup is " + value); - }).catch((err) => { - console.info("Failed to get the value of startup with err: " + err); - }) - }).catch((err) => { - console.info("Failed to get the storage."); - }) - ``` + ```js + promise.then((storage) => { + let getPromise = storage.get('startup', 'default') + getPromise.then((value) => { + console.info("The value of startup is " + value); + }).catch((err) => { + console.info("Failed to get the value of startup with err: " + err); + }) + }).catch((err) => { + console.info("Failed to get the storage.") + + }) + ``` 5. Store data persistently. @@ -144,32 +145,32 @@ Use the following APIs to delete a **Storage** instance or data file. Specify **StorageObserver** as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and the **flush\(\)** method is executed, **StorageObserver** will be invoked. Unregister the **StorageObserver** when it is no longer required. - ```js - promise.then((storage) => { - var observer = function (key) { - console.info("The key of " + key + " changed."); - } - storage.on('change', observer); - storage.putSync('startup', 'auto'); // Modify data in the Storage instance. - storage.flushSync(); // Trigger the StorageObserver callback. + ```js + promise.then((storage) => { + var observer = function (key) { + console.info("The key of " + key + " changed."); + } + storage.on('change', observer) + storage.putSync('startup', 'auto'); // Modify data in the Storage instance. + storage.flushSync(); // Trigger the StorageObserver callback. - storage.off('change', observer); // Unsubscribe from the data changes. - }).catch((err) => { - console.info("Failed to get the storage."); - }) - ``` + storage.off('change', observer); // Unsubscribe from the data changes. + }).catch((err) => { + console.info("Failed to get the storage."); + }) + ``` 7. Delete the specified file. Use the **deleteStorage** method to delete the **Storage** singleton of the specified file from the memory, and delete the specified file, its backup file, and damaged files. After the specified files are deleted, the application cannot use that instance to perform any data operation. Otherwise, data inconsistency will occur. The deleted data and files cannot be restored. - ```js - let promise = dataStorage.deleteStorage(path + '/mystore'); - promise.then(() => { - console.info("Succeeded in deleting the storage."); - }).catch((err) => { - console.info("Failed to deleted the storage with err: " + err); - }) - ``` - + ```js + let promise = dataStorage.deleteStorage(path + '/mystore'); + promise.then(() => { + console.info("Succeeded in deleting the storage."); + }).catch((err) => { + console.info("Failed to delete the storage with err: " + err); + + }) + ``` diff --git a/en/application-dev/device/sensor-guidelines.md b/en/application-dev/device/sensor-guidelines.md index dcfffc55a6400f21c9180ee3306af16ae8713119..50ebd3428f89eba4f968dd98e5fe2edee91bee34 100644 --- a/en/application-dev/device/sensor-guidelines.md +++ b/en/application-dev/device/sensor-guidelines.md @@ -26,58 +26,30 @@ | -------- | -------- | -------- | | ohos.sensor | sensor.on(sensorType, callback:AsyncCallback<Response>): void | Subscribes to data changes of a type of sensor.| | ohos.sensor | sensor.once(sensorType, callback:AsyncCallback<Response>): void | Subscribes to only one data change of a type of sensor.| -| ohos.sensor | sensor.off(sensorType, callback:AsyncCallback<void>): void | Unsubscribes from sensor data changes.| +| ohos.sensor | sensor.off(sensorType, callback?:AsyncCallback<void>): void | Unsubscribes from sensor data changes.| ## How to Develop -1. To obtain data from a type of sensor, configure the requested permissions in the **config.json** file. - - ``` - "reqPermissions":[ - { - "name":"ohos.permission.ACCELEROMETER", - "reason":"", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - { - "name":"ohos.permission.GYROSCOPE", - "reason":"", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - { - "name":"ohos.permission.ACTIVITY_MOTION", - "reason":"ACTIVITY_MOTION_TEST", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - { - "name":"ohos.permission.READ_HEALTH_DATA", - "reason":"HEALTH_DATA_TEST", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - ] - ``` +1. Before obtaining data from a type of sensor, check whether the required permission has been configured.
+ The system provides the following sensor-related permissions: + - ohos.permission.ACCELEROMETER + + - ohos.permission.GYROSCOPE + + - ohos.permission.ACTIVITY_MOTION + + - ohos.permission.READ_HEALTH_DATA + + For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md). 2. Subscribe to data changes of a type of sensor. ``` - import sensor from "@ohos.sensor" - sensor.on(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data){ - console.info("Subscription succeeded. data = "+ data); // The call is successful, and the obtained sensor data is printed. - } - ); + import sensor from "@ohos.sensor"; + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data){ + console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. + }); ``` The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**. @@ -87,11 +59,8 @@ 3. Unsubscribe from sensor data changes. ``` - import sensor from "@ohos.sensor" - sensor.off(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function() { - console.info("Succeeded in unsubscribing from acceleration sensor data."); // The unsubscription is successful, and the result is printed. - } - ); + import sensor from "@ohos.sensor"; + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); ``` The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**. @@ -101,11 +70,10 @@ 4. Subscribe to only one data change of a type of sensor. ``` - import sensor from "@ohos.sensor" - sensor.once(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data) { - console.info("Data obtained successfully. data=" + data); // The call is successful, and the obtained sensor data is printed. - } - ); + import sensor from "@ohos.sensor"; + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data) { + console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. + }); ``` The following figure shows the successful call result when **SensorType** is **SENSOR_TYPE_ID_ACCELEROMETER**. @@ -115,11 +83,12 @@ If the API fails to be called, you are advised to use the **try/catch** statement to capture error information that may occur in the code. Example: ``` + import sensor from "@ohos.sensor"; try { - sensor.once(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data) { - console.info("Data obtained successfully. data=" + data); // The call is successful, and the obtained sensor data is printed. + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data) { + console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z); // Data is obtained. }); } catch (error) { - console.error(error); + console.error("Failed to get sensor data"); } - ``` + ``` \ No newline at end of file diff --git a/en/application-dev/device/sensor-overview.md b/en/application-dev/device/sensor-overview.md index 671cc29ade0a832dc835ab4c03529ef9c9771280..adfa2440c20108a5efe6753e9dc1be8fb350ebcf 100644 --- a/en/application-dev/device/sensor-overview.md +++ b/en/application-dev/device/sensor-overview.md @@ -6,29 +6,29 @@ Sensors in OpenHarmony are an abstraction of underlying sensor hardware. Your ap A sensor is a device to detect events or changes in an environment and send messages about the events or changes to another device (for example, a CPU). Generally, a sensor is composed of sensitive components and conversion components. Sensors are the cornerstone of the IoT. A unified sensor management framework is required to achieve data sensing at a low latency and low power consumption, thereby keeping up with requirements of "1+8+N" products or business in the Seamless AI Life Strategy. The sensor list is as follows: -| Type | Name | Description | Usage | -| --------------------------------------- | ------------------ | ------------------------------------------------------------ | ---------------------------------------- | -| SENSOR_TYPE_ACCELEROMETER | Acceleration sensor | Measures the acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Detecting the motion status | -| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | Uncalibrated acceleration sensor| Measures the uncalibrated acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Measuring the acceleration bias estimation | -| SENSOR_TYPE_LINEAR_ACCELERATION | Linear acceleration sensor | Measures the linear acceleration (excluding the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Detecting the linear acceleration in each axis | -| SENSOR_TYPE_GRAVITY | Gravity sensor | Measures the gravity acceleration applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Measuring the gravity | -| SENSOR_TYPE_GYROSCOPE | Gyroscope sensor | Measures the rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s.| Measuring the rotation angular velocity | -| SENSOR_TYPE_GYROSCOPE_UNCALIBRATED | Uncalibrated gyroscope sensor| Measures the uncalibrated rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s.| Measuring the bias estimation of the rotation angular velocity | -| SENSOR_TYPE_SIGNIFICANT_MOTION | Significant motion sensor | Checks whether a device has a significant motion on three physical axes (X, Y, and Z). The value **0** means that the device does not have a significant motion, and **1** means the opposite.| Detecting significant motions of a device | -| SENSOR_TYPE_PEDOMETER_DETECTION | Pedometer detection sensor | Detects whether a user takes a step. The value can be **0** (the user does not take a step) or **1** (the user takes a step).| Detecting whether a user takes a step | -| SENSOR_TYPE_PEDOMETER | Pedometer sensor | Records the number of steps a user has walked. | Providing the number of steps a user has walked | -| SENSOR_TYPE_AMBIENT_TEMPERATURE | Ambient temperature sensor | Measures the ambient temperature, in the unit of degree Celsius (°C). | Measuring the ambient temperature | -| SENSOR_TYPE_MAGNETIC_FIELD | Magnetic field sensor | Measures the magnetic field on three physical axes (X, Y, and Z), in the unit of μT.| Creating a compass | -| SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED | Uncalibrated magnetic field sensor | Measures the uncalibrated magnetic field on three physical axes (X, Y, and Z), in the unit of μT.| Measuring the magnetic field bias estimation | -| SENSOR_TYPE_HUMIDITY | Humidity sensor | Measures the ambient relative humidity, in a percentage (%). | Monitoring the dew point, absolute humidity, and relative humidity | -| SENSOR_TYPE_BAROMETER | Barometer sensor | Measures the barometric pressure, in the unit of hPa or mbar. | Measuring the barometric pressure | -| SENSOR_TYPE_ORIENTATION | Orientation sensor | Measures the rotation angles of a device on three physical axes (X, Y, and Z), in the unit of rad.| Providing the three orientation angles of the screen | -| SENSOR_TYPE_ROTATION_VECTOR | Rotation vector sensor | Measures the rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor, magnetic field sensor, and gyroscope sensor.| Detecting the orientation of a device in the East, North, Up (ENU) Cartesian coordinate system | -| SENSOR_TYPE_PROXIMITY | Proximity sensor | Measures the distance between a visible object and the device screen. | Measuring the distance between a person and the device during a call | -| SENSOR_TYPE_AMBIENT_LIGHT | Ambient light sensor | Measures the ambient light intensity of a device, in the unit of lux. | Automatically adjusting the screen brightness and checking whether the screen is covered on the top| -| SENSOR_TYPE_HEART_RATE | Heart rate sensor | Measures the heart rate of a user. | Providing users' heart rate data | -| SENSOR_TYPE_WEAR_DETECTION | Wear detection sensor | Checks whether a user is wearing a wearable device. | Detecting wearables | -| SENSOR_TYPE_HALL | Hall effect sensor | Detects a magnetic field around a device. | Smart cover mode of the device | +| Type | Name | Description | Usage | +| --------------------------------------- | --------- | ---------------------------------------- | -------------------- | +| SENSOR_TYPE_ACCELEROMETER | Acceleration sensor | Measures the acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Detecting the motion status | +| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | Uncalibrated acceleration sensor| Measures the uncalibrated acceleration (including the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Measuring the acceleration bias estimation | +| SENSOR_TYPE_LINEAR_ACCELERATION | Linear acceleration sensor | Measures the linear acceleration (excluding the gravity acceleration) applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Detecting the linear acceleration in each axis | +| SENSOR_TYPE_GRAVITY | Gravity sensor | Measures the gravity acceleration applied to a device on three physical axes (X, Y, and Z), in the unit of m/s2.| Measuring the gravity | +| SENSOR_TYPE_GYROSCOPE | Gyroscope sensor | Measures the rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s.| Measuring the rotation angular velocity | +| SENSOR_TYPE_GYROSCOPE_UNCALIBRATED | Uncalibrated gyroscope sensor| Measures the uncalibrated rotation angular velocity of a device on three physical axes (X, Y, and Z), in the unit of rad/s.| Measuring the bias estimation of the rotation angular velocity | +| SENSOR_TYPE_SIGNIFICANT_MOTION | Significant motion sensor | Checks whether a device has a significant motion on three physical axes (X, Y, and Z). The value **0** means that the device does not have a significant motion, and **1** means the opposite.| Detecting significant motions of a device | +| SENSOR_TYPE_PEDOMETER_DETECTION | Pedometer detection sensor | Detects whether a user takes a step. The value can be **0** (the user does not take a step) or **1** (the user takes a step).| Detecting whether a user takes a step | +| SENSOR_TYPE_PEDOMETER | Pedometer sensor | Records the number of steps a user has walked. | Providing the number of steps a user has walked | +| SENSOR_TYPE_AMBIENT_TEMPERATURE | Ambient temperature sensor | Measures the ambient temperature, in the unit of degree Celsius (°C). | Measuring the ambient temperature | +| SENSOR_TYPE_MAGNETIC_FIELD | Magnetic field sensor | Measures the magnetic field on three physical axes (X, Y, and Z), in the unit of μT.| Creating a compass | +| SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED | Uncalibrated magnetic field sensor | Measures the uncalibrated magnetic field on three physical axes (X, Y, and Z), in the unit of μT.| Measuring the magnetic field bias estimation | +| SENSOR_TYPE_HUMIDITY | Humidity sensor | Measures the ambient relative humidity, in a percentage (%). | Monitoring the dew point, absolute humidity, and relative humidity | +| SENSOR_TYPE_BAROMETER | Barometer sensor | Measures the barometric pressure, in the unit of hPa or mbar.| Measuring the barometric pressure | +| SENSOR_TYPE_ORIENTATION | Orientation sensor | Measures the rotation angles of a device on three physical axes (X, Y, and Z), in the unit of rad. | Providing the three orientation angles of the screen | +| SENSOR_TYPE_ROTATION_VECTOR | Rotation vector sensor | Measures the rotation vector of a device. It is a composite sensor that generates data from the acceleration sensor, magnetic field sensor, and gyroscope sensor. | Detecting the orientation of a device in the East, North, Up (ENU) Cartesian coordinate system | +| SENSOR_TYPE_PROXIMITY | Proximity sensor | Measures the distance between a visible object and the device screen. | Measuring the distance between a person and the device during a call | +| SENSOR_TYPE_AMBIENT_LIGHT | Ambient light sensor | Measures the ambient light intensity of a device, in the unit of lux. | Automatically adjusting the screen brightness and checking whether the screen is covered on the top| +| SENSOR_TYPE_HEART_RATE | Heart rate sensor | Measures the heart rate of a user. | Providing users' heart rate data | +| SENSOR_TYPE_WEAR_DETECTION | Wear detection sensor | Checks whether a user is wearing a wearable device. | Detecting wearables | +| SENSOR_TYPE_HALL | Hall effect sensor | Detects a magnetic field around a device. | Smart cover mode of the device | ## Working Principles @@ -52,15 +52,12 @@ The following modules work cooperatively to implement OpenHarmony sensors: Senso 1. To obtain data of the following sensors, you must claim the required permissions. - Table 7 Sensor data permissions - - | Sensor | Permission | Sensitivity | Permission Description | - | ------------------------- | -------------------------------- | ------------ | ----------------------- | - | Acceleration sensor, uncalibrated acceleration sensor, and linear acceleration sensor| ohos.permission.ACCELEROMETER | system_grant | Allows an application to subscribe to data of these acceleration-related sensors in the motion category.| - | Gyroscope sensor and uncalibrated gyroscope sensor | ohos.permission.GYROSCOPE | system_grant | Allows an application to subscribe to data of the gyroscope-related sensors in the motion category.| - | Pedometer sensor | ohos.permission.ACTIVITY_MOTION | user_grant | Allows an application to subscribe to the motion status. | - | Heart rate sensor | ohos.permission.READ_HEALTH_DATA | user_grant | Allows an application to read health data. | - - +| Sensor | Permission | Sensitivity | Permission Description | +| ------------------------- | -------------------------------- | ------------ | ----------------------- | +| Acceleration sensor, uncalibrated acceleration sensor, and linear acceleration sensor| ohos.permission.ACCELEROMETER | system_grant | Allows an application to subscribe to data of these acceleration-related sensors in the motion category.| +| Gyroscope sensor and uncalibrated gyroscope sensor | ohos.permission.GYROSCOPE | system_grant | Allows an application to subscribe to data of the gyroscope-related sensors in the motion category.| +| Pedometer sensor | ohos.permission.ACTIVITY_MOTION | user_grant | Allows an application to subscribe to the motion status. | +| Heart rate sensor | ohos.permission.READ_HEALTH_DATA | user_grant | Allows an application to read health data. | 2. The APIs for subscribing to and unsubscribing from sensor data work in pairs. If you do not need sensor data, call the unsubscription API to stop sensor data reporting. + \ No newline at end of file diff --git a/en/application-dev/device/usb-guidelines.md b/en/application-dev/device/usb-guidelines.md index e026109ca3d34b44f69d2ae4752425febbd2116c..5631ab358ca73ff99d3107b6c51966ab83cdeb3d 100644 --- a/en/application-dev/device/usb-guidelines.md +++ b/en/application-dev/device/usb-guidelines.md @@ -21,16 +21,16 @@ The following table lists the USB APIs currently available. For details, see the | setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. | | setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. | | claimInterface(pipe: USBDevicePipe, iface: USBInterface, force?: boolean): number | Claims a USB interface. | -| bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise\ | Performs bulk transfer. | +| bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout?: number): Promise\ | Performs bulk transfer. | | closePipe(pipe: USBDevicePipe): number | Closes a USB device pipe. | -| releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number | Releases a USB interface. | +| releaseInterface(pipe: USBDevicePipe, iface: USBInterface): number | Releases a USB interface. | | getFileDescriptor(pipe: USBDevicePipe): number | Obtains the file descriptor. | | getRawDescriptor(pipe: USBDevicePipe): Uint8Array | Obtains the raw USB descriptor. | -| controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise\ | Performs control transfer. | +| controlTransfer(pipe: USBDevicePipe, contrlparam: USBControlParams, timeout?: number): Promise\ | Performs control transfer. | ## How to Develop -You can set a USB device as a host to connect to a device for data transfer. The development procedure is as follows: +You can set a USB device as the USB host to connect to other USB devices for data transfer. The development procedure is as follows: 1. Obtain the USB device list. diff --git a/en/application-dev/device/vibrator-guidelines.md b/en/application-dev/device/vibrator-guidelines.md index 9731fa6cec8da388719b61cf7cf7b0e542f87ca4..0dfc8344e5bb27a7ab6b6cd11943595c9f7855a6 100644 --- a/en/application-dev/device/vibrator-guidelines.md +++ b/en/application-dev/device/vibrator-guidelines.md @@ -10,77 +10,42 @@ For details about the APIs, see [Vibrator](../reference/apis/js-apis-vibrator.md ## Available APIs -| Module| API| Description| -| -------- | -------- | -------- | -| ohos.vibrator | vibrate(duration: number): Promise<void> | Triggers vibration with the specified duration. This API uses a promise to return the result.| -| ohos.vibrator | vibrate(duration: number, callback?: AsyncCallback<void>): void | Triggers vibration with the specified duration. This API uses a callback to return the result.| -| ohos.vibrator | vibrate(effectId: EffectId): Promise<void> | Triggers vibration with the specified effect. This API uses a promise to return the result.| +| Module | API | Description | +| ------------- | ---------------------------------------- | ------------------------------- | +| ohos.vibrator | vibrate(duration: number): Promise<void> | Triggers vibration with the specified duration. This API uses a promise to return the result. | +| ohos.vibrator | vibrate(duration: number, callback?: AsyncCallback<void>): void | Triggers vibration with the specified duration. This API uses a callback to return the result. | +| ohos.vibrator | vibrate(effectId: EffectId): Promise<void> | Triggers vibration with the specified effect. This API uses a promise to return the result. | | ohos.vibrator | vibrate(effectId: EffectId, callback?: AsyncCallback<void>): void | Triggers vibration with the specified effect. This API uses a callback to return the result.| -| ohos.vibrator | stop(stopMode: VibratorStopMode): Promise<void> | Stops vibration. This API uses a promise to return the result.| -| ohos.vibrator | stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void | Stops vibration. This API uses a callback to return the result.| +| ohos.vibrator | stop(stopMode: VibratorStopMode): Promise<void>| Stops vibration. This API uses a promise to return the result. | +| ohos.vibrator | stop(stopMode: VibratorStopMode, callback?: AsyncCallback<void>): void | Stops vibration. This API uses a callback to return the result. | ## How to Develop -1. Declare the permissions required for controlling vibrators on the hardware device in the `config.json` file. - - ``` - "reqPermissions": [ - { - "name": "ohos.permission.ACCELEROMETER", - "reason": "", - "usedScene": { - "ability": [ - ".MainAbility" - ], - "when": "inuse" - } - }, - { - "name": "ohos.permission.VIBRATE", - "reason": "", - "usedScene": { - "ability": [ - ".MainAbility" - ], - "when": "inuse" - } - }, - { - "name": "ohos.permission.ACTIVITY_MOTION", - "reason": "", - "usedScene": { - "ability": [ - ".MainAbility" - ], - "when": "inuse" - } - }, - ] - ``` +1. Before using the vibrator on a device, you must declare the **ohos.permission.VIBRATE** permission. For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md). 2. Trigger the device to vibrate. - + ``` import vibrator from "@ohos.vibrator" - vibrator.vibrate(1000).then((error)=>{ - if (error){ // The call fails, and error.code and error.message are printed. - Console.log("Promise return failed.error.code"+error.code+"error.message"+error.message); - }else{ // The call is successful, and the device starts to vibrate. - Console.log("Promise returned to indicate a successful vibration.") - }; + vibrator.vibrate(1000).then((error) => { + if (error) { // The call fails, and error.code and error.message are printed. + console.log("Promise return failed.error.code " + error.code + "error.message " + error.message); + } else { // The call is successful, and the device starts to vibrate. + console.log("Promise returned to indicate a successful vibration.") + } }) ``` 3. Stop the vibration. - + ``` import vibrator from "@ohos.vibrator" - vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then((error)=>{ - if(error){ // The call fails, and error.code and error.message are printed. - Console.log("Promise return failed.error.code"+error.code+"error.message"+error.message); - }else{ // The call is successful, and the device stops vibrating. - Console.log("Promise returned to indicate a successful stop."); - }; + vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then((error) => { + if (error) { // The call fails, and error.code and error.message are printed. + console.log("Promise return failed.error.code " + error.code + "error.message " + error.message); + } else { // The call is successful, and the device stops vibrating. + console.log("Promise returned to indicate successful."); + } }) ``` diff --git a/en/application-dev/device/vibrator-overview.md b/en/application-dev/device/vibrator-overview.md index 05e9b06d5c906c7e0ad46a6dc7e7f65400b6bc20..045419585fb852efb033cc87a085a1d2a80a9488 100644 --- a/en/application-dev/device/vibrator-overview.md +++ b/en/application-dev/device/vibrator-overview.md @@ -10,7 +10,7 @@ The vibrator is a Misc device that consists of four modules: Vibrator API, Vibra **Figure 1** Vibrator in Misc devices -![en-us_image_0000001180249428.png](figures/en-us_image_0000001180249428.png) +![0752d302-aeb9-481a-bb8f-e5524eb61eeb](figures/0752d302-aeb9-481a-bb8f-e5524eb61eeb.png) - Vibrator API: provides basic vibrator APIs, including the APIs for obtaining the vibrator list, querying the vibrator by effect, and triggering and stopping vibration. @@ -23,4 +23,7 @@ The vibrator is a Misc device that consists of four modules: Vibrator API, Vibra ## Constraints -When using a vibrator, you must declare the **ohos.permission.VIBRATE** permission before you can control the vibration effect. The authorization mode of this permission is **system_grant**. +When using a vibrator, you must declare the **ohos.permission.VIBRATE** permission before you can control the vibration effect. + + + diff --git a/en/application-dev/quick-start/package-structure.md b/en/application-dev/quick-start/package-structure.md index 07a151684093b7d0b85745b7211b53a7283bac2b..52b415cad96549e9cfff4c7c4e7676cbd830f112 100644 --- a/en/application-dev/quick-start/package-structure.md +++ b/en/application-dev/quick-start/package-structure.md @@ -2,19 +2,19 @@ # Application Package Structure Configuration File -In an application development project, you need to declare the package structure of the application in the **config.json** file. +When developing an application, you must declare the package structure of the application in the **config.json** file. ## Internal Structure of the config.json File -The **config.json** file consists of three mandatory tags, namely, **app**, **deviceConfig**, and **module**. See Table 1 for details. +The **config.json** file consists of three mandatory tags, namely, **app**, **deviceConfig**, and **module**. For details, see Table 1. Table 1 Internal structure of the config.json file | Tag | Description | Data Type| Initial Value Allowed| | ------------ | ------------------------------------------------------------ | -------- | ---------- | -| app | Global configuration of an application. Different HAP files of the same application must use the same **app** configuration. For details, see [Internal Structure of the app Tag](#internal-structure-of-the-app-tag).| Object | No | -| deviceConfig | Application configuration applied to a specific type of device. For details, see [Internal Structure of the deviceconfig Tag](#internal-structure-of-the-deviceconfig-tag).| Object | No | -| module | Configuration of a HAP file. The **module** configuration is valid only for the current HAP file. For details, see [Internal Structure of the module Tag](#internal-structure-of-the-module-tag).| Object | No | +| app | Global configuration of the application. Different HAP files of the same application must use the same **app** configuration. For details, see [Internal Structure of the app Tag](#internal-structure-of-the-app-tag).| Object | No | +| deviceConfig | Application configuration applied to a specific type of device. For details, see [Internal Structure of the deviceconfig Tag](#internal-structure-of-the-deviceconfig-tag).| Object | No | +| module | Configuration of a HAP file. It is valid only for the current HAP file. For details, see [Internal Structure of the module Tag](#internal-structure-of-the-module-tag).| Object | No | Example of the **config.json** file: @@ -86,12 +86,12 @@ The **app** tag contains the global configuration information of the application Table 2 Internal structure of the app tag -| Attribute | Description | Data Type| Initial Value Allowed | -| ---------- | ------------------------------------------------------------ | -------- | ------------------ | -| bundleName | Bundle name of the application. It uniquely identifies the application. The bundle name can contain only letters, digits, underscores (_), and periods (.). It must start with a letter. The value is a string with 7 to 127 bytes of a reverse domain name, for example, **com.example.myapplication**. It is recommended that the first level be the domain suffix "com" and the second level be the vendor/individual name. More levels are also accepted.| String | No | -| vendor | Description of the application vendor. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| -| version | Version information of the application. For details, see Table 3. | Object | No | -| apiVersion | OpenHarmony API version on which the application depends. For details, see Table 4. | Object | Yes (initial value: left empty)| +| Attribute | Description | Data Type| Initial Value Allowed | +| ----------------- | ------------------------------------------------------------ | -------- | --------------------------- | +| bundleName | Bundle name, which uniquely identifies an application. The bundle name can contain only letters, digits, underscores (_), and periods (.). It must start with a letter. The value is a string with 7 to 127 bytes of a reverse domain name, for example, **com.example.myapplication**. It is recommended that the first level be the domain suffix "com" and the second level be the vendor/individual name. More levels are also accepted.| String | No | +| vendor | Description of the application vendor. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty) | +| version | Version of the application. For details, see Table 3. | Object | No | +| apiVersion | OpenHarmony API version on which the application depends. For details, see Table 4. | Object | Yes (initial value: left empty) | Table 3 Internal structure of version @@ -99,7 +99,7 @@ Table 3 Internal structure of version | ------------------------ | ------------------------------------------------------------ | -------- | -------------------------- | | name | Application version number visible to users. The value can be customized and cannot exceed 127 bytes. The customization rules are as follows:
API 5 and earlier versions: A three-segment version number is recommended, for example, A.B.C (also compatible with A.B). In the version number, A, B, and C are integers ranging from 0 to 999. Other formats are not supported.
A indicates the major version number.
B indicates the minor version number.
C indicates the patch version number.
API 6 and later versions: A four-segment version number is recommended, for example, A.B.C.D. In the version number, A, B, and C are integers ranging from 0 to 99, and D is an integer ranging from 0 to 999.
A indicates the major version number.
B indicates the minor version number.
C indicates the feature version number.
D indicates the patch version number.| Number | No | | code | Application version number used only for application management by OpenHarmony. This version number is not visible to users of the application. The value rules are as follows:
API 5 and earlier versions: It is a non-negative integer less than 32 bits in binary mode, converted from the value of version.name as follows: The conversion rules are as follows:
Value of **code** = A * 1,000,000 + B * 1,000 + C. For example, if the value of **version.name** is 2.2.1, the value of **code** is 2002001.
API 6 and later versions: The value of **code** is not associated with the value of **version.name** and can be customized. The value is a non-negative integer ranging from 2 to 31. Note that the value must be updated each time the application version is updated. The value for a later version must be greater than that for an earlier version.| Number | No | -| minCompatibleVersionCode | Minimum compatible version of the application. It is used to check whether the application is compatible with the version on other devices in the cross-device scenario.
The value rules are the same as those of **version.code**.| Number | No (initial value: **code** attribute value)| +| minCompatibleVersionCode | Earliest version compatible with the application. It is used in the cross-device scenario to check whether the application is compatible with a specific version on other devices.
The value rules are the same as those of **version.code**.| Number | No (initial value: **code** attribute value)| Table 4 Internal structure of apiVersion @@ -133,13 +133,13 @@ The **deviceConfig** tag contains the application configuration information on t Table 5 Internal structure of the deviceConfig tag -| Attribute | Description | Data Type| Initial Value Allowed | -| ------------ | ----------------------------------------------- | -------- | ------------------ | -| default | Application configuration applied to all types of devices. See Table 6. | Object | No | -| tablet | Application configuration specific to tablets. See Table 6. | Object | Yes (initial value: left empty)| -| tv | Application configuration specific to smart TVs. See Table 6. | Object | Yes (initial value: left empty)| -| car | Application configuration specific to head units. See Table 6. | Object | Yes (initial value: left empty)| -| wearable | Application configuration specific to wearables. See Table 6. | Object | Yes (initial value: left empty)| +| Attribute| Description | Data Type| Initial Value Allowed | +| -------- | ----------------------------------------- | -------- | ------------------ | +| default | Application configuration applied to all types of devices. For details, see Table 6.| Object | No | +| tablet | Application configuration specific to tablets. For details, see Table 6. | Object | Yes (initial value: left empty)| +| tv | Application configuration specific to smart TVs. For details, see Table 6. | Object | Yes (initial value: left empty)| +| car | Application configuration specific to head units. For details, see Table 6. | Object | Yes (initial value: left empty)| +| wearable | Application configuration specific to wearables. For details, see Table 6.| Object | Yes (initial value: left empty)| For details about the internal structures of device attributes, see Table 6. @@ -147,12 +147,12 @@ Table 6 Internal structure of device attributes | Attribute | Description | Data Type| Initial Value Allowed | | ------------------ | ------------------------------------------------------------ | -------- | ----------------------- | -| process | Name of the process running the application or ability. If the **process** attribute is configured in the **deviceConfig** tag, all abilities of the application run in this process. You can set the **process** attribute for a specific ability in the **abilities** attribute, so that the ability can run in the particular process. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. The value can contain a maximum of 31 characters.| String | Yes | +| process | Process running the application or ability. If the **process** attribute is configured in the **deviceConfig** tag, all abilities of the application run in this process. You can set the **process** attribute for a specific ability in the **abilities** attribute, so that the ability can run in the particular process. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. The value can contain a maximum of 31 characters.| String | Yes | | supportBackup | Whether the application supports backup and restoration. The value **false** means that the application does not support backup or restoration.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| Boolean | Yes (initial value: **false**)| | compressNativeLibs | Whether the **libs** libraries are packaged in the HAP file after being compressed. The value **false** means that the **libs** libraries are stored without being compressed and will be directly loaded during the installation of the HAP file.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| Boolean | Yes (initial value: **true**) | | directLaunch | Whether the application can be started when the device is locked. The value **true** means that the application can be started when the device is locked. Devices running OpenHarmony do not support this attribute.| Boolean | Yes (initial value: **false**)| -| ark | Maple configuration. See Table 7. | Object | Yes (initial value: left empty) | -| network | Network security configuration. You can customize the network security settings of the application in the security statement of the configuration file without modifying the application code. See Table 9.| Object | Yes (initial value: left empty) | +| ark | Maple configuration. For details, see Table 7. | Object | Yes (initial value: left empty) | +| network | Network security configuration. You can customize the network security settings of the application in the security statement of the configuration file without modifying the application code. For details, see Table 9.| Object | Yes (initial value: left empty) | Table 7 Internal structure of the ark attribute @@ -179,9 +179,9 @@ Table 10 Internal structure of the securityConfig attribute | Attribute | Sub-attribute | Description | Data Type| Initial Value Allowed | | -------------- | ------------------ | ------------------------------------------------------------ | -------- | ---------------- | -| domainSettings | - | Security settings of the custom network domain. This attribute allows nested domains. To be more specific, the **domainSettings** object of a large domain can be nested with the **domainSettings** objects of small network domains.| Object| Yes (initial value: left empty)| -| | cleartextPermitted | Whether plaintext traffic can be transmitted in the custom network domain. If both **cleartextTraffic** and **security** are declared, whether plaintext traffic can be transmitted in the custom network domain is determined by the **cleartextPermitted** attribute.
**true**: Plaintext traffic can be transmitted.
**false**: Plaintext traffic cannot be transmitted.| Boolean| No | -| | domains | Domain name configuration. This attribute consists of the **subdomains** and **name** sub-attributes.
**subdomains** (boolean): specifies whether the domain name contains subdomains. If this sub-attribute is set to **true**, the domain naming convention applies to all related domains and subdomains (including the lower-level domains of the subdomains). Otherwise, the convention applies only to exact matches.
**name** (string): indicates the domain name.| Object array| No | +| domainSettings | - | Security settings of the custom network domain. This attribute allows nested domains. That is, the **domainSettings** object of a network domain can be nested with the **domainSettings** objects of smaller network domains.| Object| Yes (initial value: left empty)| +| | cleartextPermitted | Whether plaintext traffic can be transmitted in the custom network domain. If both **cleartextTraffic** and **security** are declared, whether plaintext traffic can be transmitted in the custom network domain is determined by the **cleartextPermitted** attribute.
**true**: Plaintext traffic can be transmitted.
**false**: Plaintext traffic cannot be transmitted.| Boolean| No | +| | domains | Domain name. This attribute consists of two sub-attributes: **subdomains** and **name**.
**subdomains** (boolean): specifies whether the domain name contains subdomains. If this sub-attribute is set to **true**, the domain naming convention applies to all related domains and subdomains (including the lower-level domains of the subdomains). Otherwise, the convention applies only to exact matches.
**name** (string): indicates the domain name.| Object array| No | Example of the deviceConfig tag structure: @@ -214,33 +214,33 @@ The **module** tag contains the configuration information of the HAP file. For d Table 11 Internal structure of the module tag -| Attribute | Description | Data Type | Initial Value Allowed | -| --------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ | -| mainAbility | Ability displayed on the Service Center icon. When the resident process is started, the **mainAbility** is started.| String | No if any ability using the Page template exists | -| package | Structure name of the HAP file, which must be unique in the application. The value is a string with a maximum of 127 bytes, in the reverse domain name notation. It is recommended that the value be the same as the project directory of the HAP file. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | No | -| name | Class name of the HAP file. The value is in the reverse domain name notation. The prefix must be the same as the package name specified by the **package** label at the same level. The value can also start with a period (.). The value is a string with a maximum of 255 bytes.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | No | -| description | Description of the HAP file. The value is a string with a maximum of 255 bytes. If the value exceeds the limit or needs to support multiple languages, you can use a resource index to the description. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: left empty) | -| supportedModes | Mode supported by the application. Currently, only the **drive** mode is defined. This attribute applies only to head units.| String array| Yes (initial value: left empty) | -| deviceType | Type of device on which the abilities can run. The device types predefined in the system include **tablet**, **tv**, **car**, and **wearable**.| String array| No | -| distro | Distribution description of the current HAP file. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. For details, see Table 12.| Object | No | -| metaData | Metadata of the HAP file. For details, see Table 13. | Object | Yes (initial value: left empty) | -| abilities | All abilities in the current module. The value is an array of objects, each of which represents a shortcut object. For details, see Table 17.| Object array | Yes (initial value: left empty) | -| js | A set of JS modules developed using the ArkUI framework. Each element in the set represents the information about a JS module. For details, see Table 22.| Object array | Yes (initial value: left empty) | -| shortcuts | Shortcut information of the application. The value is an array of objects, each of which represents a shortcut object. For details, see Table 25.| Object array | Yes (initial value: left empty) | -| reqPermissions | Permissions that the application applies for from the system before its running. For details, see Table 21. | Object array | Yes (initial value: left empty) | -| colorMode | Color mode of the application.
**dark**: Resources applicable for the dark mode are selected.
**light**: Resources applicable for the light mode are selected.
**auto**: Resources are selected based on the color mode of the system.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. | String | Yes (initial value: **auto**) | -| distroFilter | Application distribution rules.
AppGallery uses these rules to distribute HAP files to the matching devices. Distribution rules cover three factors: API version, screen shape, and screen resolution. AppGallery distributes a HAP file to the device whose on the mapping between **deviceType** and these three factors. For details, see Table 29. | Object | Yes (initial value: left empty)
Set this attribute when an application has multiple entry modules. | -| reqCapabilities | Device capabilities required for running the application. | String array| Yes (initial value: left empty) | -| commonEvents | Static broadcast. For details, see Table 35. | Object array | Yes (initial value: left empty) | -| allowClassMap | Metadata of the HAP file. The value can be **true** or **false**. If the value is **true**, the HAP file uses the Java object proxy mechanism provided by the OpenHarmony framework. | Boolean | No (initial value: **false**) | -| entryTheme | Keyword of an OpenHarmony internal theme. Set it to the resource index of the name.| String | Yes (initial value: left empty) | +| Attribute | Description | Data Type | Initial Value Allowed | +| ----------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ | +| mainAbility | Ability displayed on the Service Center icon. When the resident process is started, the **mainAbility** is started.| String | No if any ability using the Page template exists | +| package | Package name of the HAP file, which must be unique in the application. The value is a string with a maximum of 127 bytes, in the reverse domain name notation. It is recommended that the value be the same as the project directory of the HAP file. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. | String | No | +| name | Class name of the HAP file. The value is in the reverse domain name notation, with the prefix same as the package name specified by **package** at the same level. It can also start with a period (.). The value is a string with a maximum of 255 bytes.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | No | +| description | Description of the HAP file. The value is a string with a maximum of 255 bytes. If the value exceeds the limit or needs to support multiple languages, you can use a resource index to the description. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: left empty) | +| supportedModes | Mode supported by the application. Currently, only the **drive** mode is defined. This attribute applies only to head units.| String array| Yes (initial value: left empty) | +| deviceType | Type of device on which the ability can run. The device types predefined in the system include **tablet**, **tv**, **car**, and **wearable**.| String array| No | +| distro | Distribution description of the HAP file. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. For details, see Table 12.| Object | No | +| metaData | Metadata of the HAP file. For details, see Table 13. | Object | Yes (initial value: left empty) | +| abilities | All abilities in the current module. The value is an array of objects, each of which represents a shortcut object. For details, see Table 17.| Object array | Yes (initial value: left empty) | +| js | A set of JS modules developed using ArkUI. Each element in the set represents the information about a JS module. For details, see Table 22.| Object array | Yes (initial value: left empty) | +| shortcuts | Shortcuts of the application. The value is an array of objects, each of which represents a shortcut object. For details, see Table 25.| Object array | Yes (initial value: left empty) | +| reqPermissions | Permissions that the application requests from the system when it is running. For details, see Table 21. | Object array | Yes (initial value: left empty) | +| colorMode | Color mode of the application.
**dark**: Resources applicable for the dark mode are selected.
**light**: Resources applicable for the light mode are selected.
**auto**: Resources are selected based on the color mode of the system.
This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: **auto**) | +| distroFilter | Distribution rules of the application.
AppGallery uses these rules to distribute HAP files to the matching devices. Distribution rules cover three factors: API version, screen shape, and screen resolution. AppGallery distributes a HAP file to the device whose on the mapping between **deviceType** and these three factors. For details, see Table 29.| Object | Yes (initial value: left empty) Set this attribute when an application has multiple entry modules.| +| reqCapabilities | Device capabilities required for running the application. | String array| Yes (initial value: left empty) | +| commonEvents | Static broadcast. For details, see Table 35. | Object array | Yes (initial value: left empty) | +| allowClassMap | Metadata of the HAP file. The value can be **true** or **false**. If the value is **true**, the HAP file uses the Java object proxy mechanism provided by the OpenHarmony framework. | Boolean | No (initial value: **false**) | +| entryTheme | Keyword of an OpenHarmony internal theme. Set it to the resource index of the name. | String | Yes (initial value: left empty) | Example of the **module** tag structure: ```json "module": { "mainAbility": "MainAbility", - "package": "com.example.myapplication.rntry", + "package": "com.example.myapplication.entry", "name": ".MyOHOSAbilityPackage", "description": "$string:description_application", "supportModes": [ @@ -273,9 +273,9 @@ Table 12 Internal structure of the distro attribute | Attribute | Description | Data Type| Initial Value Allowed| | ---------------- | ------------------------------------------------------------ | -------- | ---------- | -| moduleName | Name of the current HAP file. The maximum length is 31 characters. | String | No | -| moduleType | Type of the current HAP file. The value can be **entry** or **feature**. For the HAR type, set this attribute to **har**.| String | No | -| installationFree | Whether the HAP file supports the installation-free feature.
**true**: The HAP file supports the installation-free feature and meets installation-free constraints.
**false**: The HAP file does not support the installation-free feature.
Pay attention to the following:
When **entry.hap** is set to **true**, all **feature.hap** fields related to **entry.hap **must be **true**.
When **entry.hap** is set to **false**, **feature.hap** related to **entry.hap** can be set to **true** or **false** based on service requirements.| Boolean | No | +| moduleName | Name of the HAP file. The maximum length is 31 characters. | String | No | +| moduleType | Type of the HAP file. The value can be **entry** or **feature**. For the HAR type, set this attribute to **har**.| String | No | +| installationFree | Whether the HAP file supports the installation-free feature.
**true**: The HAP file supports the installation-free feature and meets installation-free constraints.
**false**: The HAP file does not support the installation-free feature.
Pay attention to the following:
When **entry.hap** is set to **true**, all **feature.hap** fields related to **entry.hap **must be **true**.
When **entry.hap** is set to **false**, **feature.hap** related to **entry.hap** can be set to **true** or **false** based on service requirements.| Boolean | No | Example of the **distro** attribute structure: @@ -299,9 +299,9 @@ Table 14 Internal structure of the parameters attribute | Attribute | Description | Data Type| Initial Value Allowed | | ----------- | ------------------------------------------------------------ | -------- | ------------------ | -| description | Description of the parameter. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.| String | Yes (initial value: left empty)| -| name | Name of the parameter. The value can contain a maximum of 255 characters. | String | Yes (initial value: left empty)| -| type | Type of the parameter, for example, **Integer**. | String | No | +| description | Description of the parameter passed for calling the ability. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.| String | Yes (initial value: left empty)| +| name | Name of the parameter passed for calling the ability. The value can contain a maximum of 255 characters. | String | Yes (initial value: left empty)| +| type | Type of the parameter passed for calling the ability, for example, **Integer**. | String | No | Table 15 Internal structure of the results attribute @@ -309,15 +309,15 @@ Table 15 Internal structure of the results attribute | ----------- | ------------------------------------------------------------ | -------- | -------------------- | | description | Description of the return value. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.| String | Yes (initial value: left empty)| | name | Name of the return value. The value can contain a maximum of 255 characters. | String | Yes (initial value: left empty)| -| type | Type of the return value, for example, **Integer**. | String | No | +| type | Type of the return value, for example, **Integer**. | String | No | Table 16 Internal structure of the customizeData attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ---------------------------------------------------------- | -------- | -------------------- | -| name | Key of a data element. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| -| value | Value of a data element. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| -| extra | Custom format of the data element. The value is an index to the resource that identifies the data.| String | Yes (initial value: left empty)| +| name | Key of the data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| +| value | Value of the data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| +| extra | Custom format of the data item. The value is an index to the resource that identifies the data.| String | Yes (initial value: left empty)| Example of the **metaData** attribute structure: @@ -346,19 +346,19 @@ Table 17 Internal structure of the abilities attribute | Attribute | Description | Data Type | Initial Value Allowed | | ---------------- | ------------------------------------------------------------ | ---------- | -------------------------------------------------------- | | process | Name of the process running the application or ability. If the **process** attribute is configured in the **deviceConfig** tag, all abilities of the application run in this process. You can set the **process** attribute for a specific ability in the **abilities** attribute, so that the ability can run in the particular process. If this attribute is set to the name of the process running other applications, all these applications can run in the same process, provided they have the same unified user ID and the same signature. Devices running OpenHarmony do not support this attribute.| String | Yes (initial value: left empty) | -| name | Name of the ability. The value is a reverse domain name, in the format of "*Bundle name*.*Class name*", for example, **"com.example.myapplication.MainAbility"**. Alternatively, the value can start with a period (.) followed by the class name, for example, **".MainAbility"**.
The ability name must be unique in an application. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.
Note: When you use DevEco Studio to create a project, the configuration of the first ability is generated by default, including the **MainAbility.java** file and the class name **MainAbility** defaulted in the **name** string for the **abilities** attribute in **config.json**. The value of this attribute can be customized if you use other IDE tools. The value can contain a maximum of 127 characters.| String | No | +| name | Ability name. The value can be a reverse domain name, in the format of "*Bundle name*.*Class name*", for example, **"com.example.myapplication.MainAbility"**. Alternatively, the value can start with a period (.) followed by the class name, for example, **".MainAbility"**.
The ability name must be unique in an application. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.
Note: If you use DevEco Studio to create the project, an ability named **MainAbility** will be created together with the default configuration in the **config.json** file. The value of this attribute can be customized if you use other IDEs. The value can contain a maximum of 127 characters.| String | No | | description | Description of the ability. The value can be a string or a resource index to descriptions in multiple languages. The value can contain a maximum of 255 characters.| String | Yes (initial value: left empty) | | icon | Index to the ability icon file. Example value: **$media:ability_icon**. In the **skills** attribute of the ability, if the **actions** value contains **action.system.home** and the **entities** value contains **entity.system.home**, the icon of the ability is also used as the icon of the application. If multiple abilities address this condition, the icon of the first candidate ability is used as the application icon.
Note: The **icon** and **label** values of an application are visible to users. Ensure that at least one of them is different from any existing icons or labels.| String | Yes (initial value: left empty) | | label | Ability name visible to users. The value can be a name string or a resource index to names in multiple languages. In the **skills** attribute of the ability, if the **actions** value contains **action.system.home** and the **entities** value contains **entity.system.home**, the label of the ability is also used as the label of the application. If multiple abilities address this condition, the label of the first candidate ability is used as the application label.
Note: The **icon** and **label** values of an application are visible to users. Ensure that at least one of them is different from any existing icons or labels. The value can be a reference to a string defined in a resource file or a string enclosed in brackets ({}). The value can contain a maximum of 255 characters.| String | Yes (initial value: left empty) | | uri | Uniform Resource Identifier (URI) of the ability. The value can contain a maximum of 255 characters. | String | Yes (No for abilities using the Data template) | -| launchType | Startup type of the ability. The value can be **standard** or **singleton**.
**standard**: Multiple **Ability** instances can be created during startup. Most abilities can use this type.
**singleton**: Only a single **Ability** instance can be created across all task stacks during startup. For example, a globally unique incoming call screen uses the singleton startup type. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: **"singleton"**) | +| launchType | Launch type of the ability. Available values are as follows:
**"standard"**: Multiple **Ability** instances can be created during startup. Most abilities can use this type.
**"singleton"**: Only a single **Ability** instance can be created across all task stacks during startup. For example, a globally unique incoming call screen uses the singleton startup type. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. | String | Yes (initial value: **"singleton"**) | | visible | Whether the ability can be called by other applications.
**true**: The ability can be called by other applications.
**false**: The ability cannot be called by other applications.| Boolean | Yes (initial value: **false**) | -| permissions | Permissions required for abilities of another application to call the current ability, generally in the format of a reverse domain name. The value can be either the permissions predefined in the OS or your custom permissions.| String array| Yes (initial value: left empty) | +| permissions | Permissions required for abilities of another application to call the current ability. The value is an array of permission names predefined by the system, generally in the format of a reverse domain name the reverse domain name format (a maximum of 255 bytes).| String array| Yes (initial value: left empty) | | skills | Types of the **want** that can be accepted by the ability. | Object array | Yes (initial value: left empty) | | deviceCapability | Device capabilities required to run the ability.| String array| Yes (initial value: left empty) | | metaData | Metadata. For details, see Table 13. | Object | Yes (initial value: left empty) | -| type | Type of the ability. Available values are as follows:
**page**: FA developed using the Page template to provide the capability of interacting with users.
**service**: PA developed using the Service template to provide the capability of running tasks in the background.
**data**: PA developed using the Data template to provide unified data access for external systems.
**CA**: ability that can be started by other applications as a window.| String | No | -| orientation | Display orientation of the ability. This attribute applies only to the ability using the Page template. Available values are as follows:
unspecified: indicates that the system automatically determines the display orientation of the ability.
**landscape**: indicates the landscape orientation.
**portrait**: indicates the portrait orientation.
**followRecent**: indicates that the orientation follows the most recent application in the stack.| String | Yes (initial value: **"unspecified"**) | +| type | Ability type. Available values are as follows:
**"page"**: FA developed using the Page template to provide the capability of interacting with users.
**"service"**: PA developed using the Service template to provide the capability of running tasks in the background.
**"data"**: PA developed using the Data template to provide unified data access for external systems.
**"CA"**: ability that can be started by other applications as a window. | String | No | +| orientation | Display orientation of the ability. This attribute applies only to the ability using the Page template. Available values are as follows:
**"unspecified"**: indicates that the system automatically determines the display orientation of the ability.
**"landscape"**: indicates the landscape orientation.
**"portrait"**: indicates the portrait orientation.
**"followRecent"**: indicates that the orientation follows the most recent application in the stack. | String | Yes (initial value: **"unspecified"**) | | backgroundModes | Background service type of the ability. You can assign multiple background service types to a specific ability. This attribute applies only to the ability using the Service template. Available values are as follows:
**dataTransfer**: service for downloading, backing up, sharing, or transferring data from the network or peer devices
**audioPlayback**: audio playback service
**audioRecording**: audio recording service
**pictureInPicture**: picture in picture (PiP) and small-window video playback services
**voip**: voice/video call and VoIP services
**location**: location and navigation services
**bluetoothInteraction**: Bluetooth scanning, connection, and transmission services
**wifiInteraction**: WLAN scanning, connection, and transmission services
**screenFetch**: screen recording and screenshot services
**multiDeviceConnection**: multi-device interconnection service| String array| Yes (initial value: left empty) | | grantPermission | Whether permissions can be granted for any data in the ability. | Boolean | Yes (initial value: left empty) | | readPermission | Permission required for reading data in the ability. This attribute applies only to the ability using the Data template. The value is a string with a maximum of 255 bytes. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: left empty) | @@ -366,15 +366,13 @@ Table 17 Internal structure of the abilities attribute | configChanges | System configurations that the ability concerns. Upon any changes on the concerned configurations, the **onConfigurationUpdated** callback will be invoked to notify the ability. Available values are as follows:
**mcc**: indicates that the mobile country code (MCC) of the IMSI is changed. Typical scenario: A SIM card is detected, and the MCC is updated.
**mnc**: indicates that the mobile network code (MNC) of the IMSI is changed. Typical scenario: A SIM card is detected, and the MNC is updated.
**locale**: indicates that the locale is changed. Typical scenario: The user has selected a new language for the text display of the device.
**layout**: indicates that the screen layout is changed. Typical scenario: Currently, different display forms are all in the active state.
**fontSize**: indicates that font size is changed. Typical scenario: A new global font size is set.
**orientation**: indicates that the screen orientation is changed. Typical scenario: The user rotates the device.
**density**: indicates that the display density is changed. Typical scenario: The user may specify different display ratios, or different display forms are active at the same time.
**size**: indicates that the size of the display window is changed.
**smallestSize**: indicates that the length of the shorter side of the display window is changed.
**colorMode**: indicates that the color mode is changed.| String array| Yes (initial value: left empty) | | mission | Task stack of the ability. This attribute applies only to the ability using the Page template. By default, all abilities in an application belong to the same task stack. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: bundle name of the application) | | targetAbility | Target ability that this ability alias points to. This attribute applies only to the ability using the Page template. If the **targetAbility** attribute is set, only **name**, **icon**, **label**, **visible**, **permissions**, and **skills** take effect in the current ability (ability alias). Other attributes use the values of the **targetAbility** attribute. The target ability must belong to the same application as the alias and must be declared in **config.json** ahead of the alias. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| String | Yes (initial value: left empty, indicating that the current ability is not an alias)| -| multiUserShared | Whether the ability supports data sharing among multiple users. This attribute applies only to the ability using the Data template. If this attribute is set to **true**, only one copy of data is stored for multiple users. Note that this attribute will invalidate the **visible** attribute. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| Boolean | Yes (initial value: **false**) | -| supportPipMode | Whether the ability allows the user to enter the Picture in Picture (PiP) mode. The PiP mode enables the user to watch a video in a small window that hovers on top of a full screen window (main window). This attribute applies only to the ability using the Page template. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| Boolean | Yes (initial value: **false**) | -| formsEnabled | Whether the ability can provide forms. This attribute applies only to the ability using the Page template.
**true**: This ability can provide forms.
**false**: This ability cannot provide forms.| Boolean | Yes (initial value: **false**) | -| forms | Details about the forms used by the ability. This attribute is valid only when **formsEnabled** is set to **true**. For details, see Table 27.| Object array | Yes (initial value: left empty) | -| srcLanguage | Programming language used to develop the ability. | String | The value can be **java**, **js**, or **ets**. | -| srcPath | Path of the JS code and components corresponding to the ability. | String | Yes (initial value: left empty) | +| multiUserShared | Whether the ability supports data sharing among multiple users. This attribute applies only to the ability using the Data template. If this attribute is set to **true**, only one copy of data is stored for multiple users. Note that this attribute will invalidate the **visible** attribute. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| Boolean| Yes (initial value: **false**) | +| supportPipMode | Whether the ability allows the user to enter the Picture in Picture (PiP) mode. The PiP mode enables the user to watch a video in a small window that hovers on top of a full screen window (main window). This attribute applies only to the ability using the Page template. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types.| Boolean| Yes (initial value: **false**) | +| formsEnabled | Whether the ability can provide forms. This attribute applies only to the ability using the Page template.
**true**: This ability can provide forms.
**false**: This ability cannot provide forms.| Boolean| Yes (initial value: **false**) | +| forms | Information about the forms used by the ability. This attribute is valid only when **formsEnabled** is set to **true**. For details, see Table 27.| Object array | Yes (initial value: left empty) | +| srcLanguage | Programming language used to develop the ability. The value can be **"js"** or **"ets"**. | String | Yes | +| srcPath | Path of the JS component code corresponding to the ability. | String | Yes (initial value: left empty) | | uriPermission | Application data that the ability can access. This attribute consists of the **mode** and **path** sub-attributes. This attribute is valid only for the capability of the type provider. Devices running OpenHarmony do not support this attribute. For details, see Table 18.| Object | Yes (initial value: left empty) | -| startWindowIcon | Index to the icon file of the ability startup page. Example value: **$media:icon**. | String | Yes (initial value: left empty) | -| startWindowBackground | Index to the background color resource file of the ability startup page. Example value: **$color:red**. | String | Yes (initial value: left empty) | Table 18 Internal structure of the uriPermission attribute @@ -413,9 +411,7 @@ Example of the **abilities** attribute structure: "fontSize", "orientation" ], - "type": "page", - "startWindowIcon": "$media:icon", - "startWindowBackground": "$color:red" + "type": "page" }, { "name": ".PlayService", @@ -455,20 +451,20 @@ Table 19 Internal structure of the skills attribute | Attribute| Description | Data Type | Initial Value Allowed | | -------- | ------------------------------------------------------------ | ---------- | -------------------- | | actions | Actions of the **want** that can be accepted by the ability. Generally, the value is an **action** value predefined in the system.| String array| Yes (initial value: left empty)| -| entities | Entities of the **want** that can be accepted by the ability, such as video and Home application.| String array| Yes (initial value: left empty)| +| entities | Entities of the **want** that can be accepted by the ability, such as video and home applications.| String array| Yes (initial value: left empty)| | uris | URIs of the **want** that can be accepted by the ability. For details, see Table 20.| Object array | Yes (initial value: left empty)| Table 20 Internal structure of the uris attribute | Attribute | Description | Data Type| Initial Value Allowed | | ------------- | -------------------------- | -------- | -------------------- | -| scheme | Scheme in the URI. | String | No | -| host | Host in the URI. | String | Yes (initial value: left empty)| -| port | Port number in the URI. | String | Yes (initial value: left empty)| -| pathStartWith | **pathStartWith** value in the URI.| String | String | -| path | Path in the URI. | String | Yes (initial value: left empty)| -| pathRegx | **pathRegx** value in the URI. | String | Yes (initial value: left empty)| -| type | Type of the URI. | String | Yes (initial value: left empty)| +| scheme | Scheme of the URI. | String | No | +| host | Host value of the URI. | String | Yes (initial value: left empty)| +| port | Port number of the URI. | String | Yes (initial value: left empty)| +| pathStartWith | **pathStartWith** value of the URI.| String | Yes (initial value: left empty)| +| path | **path** value of the URI. | String | Yes (initial value: left empty)| +| pathRegx | **pathRegx** value of the URI. | String | Yes (initial value: left empty)| +| type | **type** value of the URI. | String | Yes (initial value: left empty)| Example of the **skills** attribute structure: @@ -496,35 +492,35 @@ Example of the **skills** attribute structure: Table 21 reqPermissions -| Attribute | Description | **Type**| **Value Range** | **Default Value** | **Restrictions** | -| --------- | ------------------------------------------------------------ | -------- | ----------------------------------------------------------- | ---------------------- | ------------------------------------------------------------ | -| name | Permission name, which is mandatory. | String | Custom | None | Parsing will fail if this field is not set. | -| reason | Reason for applying for the permission, which is mandatory only when applying for the **user_grant** permission.| String | The displayed text cannot exceed 256 bytes. | Empty | If the requested permission is **user_grant**, this attribute is required for the application to be released to AppGallery. Multi-language adaptation is required.| -| usedScene | Application scenario and timing for using the permission, which is mandatory when the requested permission is **user_grant**. This attribute consists of the **ability** and **when** sub-attributes. Multiple abilities can be configured.| Object | **ability**: ability name; **when**: **inuse** or **always**| **ability**: left empty; **when**: **inuse**| If the requested permission is **user_grant**, the **ability** sub-attribute is mandatory and **when** is optional. | +| Attribute | Description | Data Type| Initial Value Allowed | +| ---------- | ------------------------------------------------------------ | -------- | ------------------ | +| name | Name of the permission to request.| String| No| +| reason | Reason for requesting the permission. The value cannot exceed 256 bytes. Multi-language adaptation is required.| String| No if the requested permission is **user_grant** (if it is left empty, application release will be rejected)| +| usedScene | Application scenario and timing for using the permission. This attribute consists of the **ability** and **when** sub-attributes. **ability**: ability name. Multiple ability names can be configured. **when**: time for using the permission. The options are **inuse** and **always**.| Object| **ability**: mandatory for the **user_grant** permission and can be left empty in other cases
**when**: initial value allowed (initial value: **inuse**)| Table 22 Internal structure of the js attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | ------------------------ | -| name | Name of a JavaScript component. The default value is **default**. | String | No | -| pages | Route information about all pages in the JavaScript component, including the page path and page name. The value is an array, in which each element represents a page. The first element in the array represents the home page of the JavaScript FA.| Array | No | +| name | Name of the JS component. The default value is **default**. | String | No | +| pages | Route information about all pages in the JS component, including the page path and page name. The value is an array, in which each element represents a page. The first element in the array represents the home page of the JavaScript FA.| Array | No | | window | Window-related configurations. This attribute applies only to the default, tablet, smart TV, head unit, and wearable device types. For details, see Table 23.| Object | Yes | -| type | Type of the JavaScript component. Available values are as follows:
**normal**: indicates that the JavaScript component is an application instance.
**form**: indicates that the JavaScript component is a widget instance.| String | Yes (initial value: **normal**)| -| mode | Development mode of the JavaScript component. For details, see Table 24. | Object | Yes (initial value: left empty) | +| type | Type of the JS component. Available values are as follows:
**normal**: indicates that the JavaScript component is an application instance.
**form**: indicates that the JavaScript component is a widget instance.| String | Yes (initial value: **normal**)| +| mode | Development mode of the JS component. For details, see Table 24. | Object | Yes (initial value: left empty) | Table 23 Internal structure of the window attribute | Attribute | Description | Data Type| Initial Value Allowed | | --------------- | ------------------------------------------------------------ | -------- | ----------------------- | -| designWidth | Baseline width for page design, in pixels. The size of an element is scaled by the actual device width.| Number | Yes (initial value: 720px) | -| autoDesignWidth | Whether to automatically calculate the baseline width for page design. If it is set to **true**, the **designWidth** attribute becomes invalid. The baseline width is calculated based on the device width and screen density.| Boolean| Yes (initial value: **false**)| +| designWidth | Baseline width for page design. The size of an element is scaled by the actual device width.| Number | Yes (initial value: 720px) | +| autoDesignWidth | Whether to automatically calculate the baseline width for page design. If it is set to **true**, the **designWidth** attribute becomes invalid. The baseline width is calculated based on the device width and screen density.| Boolean | Yes (initial value: **false**)| Table 24 Internal structure of the mode attribute | Attribute| Description | Data Type | Initial Value Allowed | | -------- | -------------------- | ----------------------------------- | --------------------------- | -| type | Type of the JavaScript component.| String. The value can be **pageAbility** or **form**.| Yes (initial value: **pageAbility**)| -| syntax | Syntax type of the JavaScript component.| String. The value can be **hml** or **ets**. | Yes (initial value: **hml**) | +| type | Type of the JS component. The value can be **"pageAbility"** or **"form"**. | String | Yes (initial value: **"pageAbility"**) | +| syntax | Syntax type of the JS component. The value can be **"hml"** or **"ets"**. | String | Yes (initial value: **"hml"**) | Example of the **js** attribute structure: @@ -549,8 +545,8 @@ Table 25 Internal structure of the shortcuts attribute | Attribute | Description | Data Type| Initial Value Allowed | | ---------- | ------------------------------------------------------------ | -------- | ------------------ | -| shortcutId | Shortcut ID. The value is a string with a maximum of 63 bytes. | String | No | -| label | Label of the shortcut, that is, the text description displayed by the shortcut. The value can be a string or a resource index to the description. The value is a string with a maximum of 63 bytes.| String | Yes (initial value: left empty)| +| shortcutId | ID of the shortcut. The value is a string with a maximum of 63 bytes. | String | No | +| label | Label of the shortcut, that is, the text description displayed for the shortcut. The value can be a string or a resource index to the description. The value is a string with a maximum of 63 bytes.| String | Yes (initial value: left empty)| | icon | Icon of the shortcut. The value is a resource index to the description. | String | Yes (initial value: left empty)| | intents | Intents to which the shortcut points. The attribute consists of the **targetClass** and **targetBundle** sub-attributes. For details, see Table 26.| Object array| Yes (initial value: left empty)| @@ -558,7 +554,7 @@ Table 26 Internal structure of the intents attribute | Attribute | Description | Data Type| Initial Value Allowed | | ------------ | --------------------------------------- | -------- | -------------------- | -| targetClass | Class name for the target ability of the shortcut. | String | Yes (initial value: left empty)| +| targetClass | Target class of the shortcut. | String | Yes (initial value: left empty)| | targetBundle | Application bundle name for the target ability of the shortcut.| String | Yes (initial value: left empty)| Example of the **shortcuts** attribute structure: @@ -582,31 +578,29 @@ Table 27 Internal structure of the forms attribute | Attribute | Description | Data Type | Initial Value Allowed | | ------------------- | ------------------------------------------------------------ | ---------- | ------------------------ | -| name | Class name of the widget. The value is a string with a maximum of 127 bytes. | String | No | +| name | Class name of the widget. The value is a string with a maximum of 127 bytes. | String | No | | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String | Yes (initial value: left empty) | -| isDefault | Whether the widget is a default one. Each ability has only one default widget.
**true**: The widget is the default one.
**false**: The widget is not the default one.| Boolean | No | -| type | Type of the widget. Available values are as follows:
**Java**: indicates a Java-programmed widget.
**JS**: indicates a JavaScript-programmed widget.| String | No | +| isDefault | Whether the widget is a default one. Each ability has only one default widget.
**true**: The widget is the default one.
**false**: The widget is not the default one.| Boolean | No | +| type | Type of the widget. Available values are as follows:
**JS**: indicates a JavaScript-programmed widget. | String | No | | colorMode | Color mode of the widget. Available values are as follows:
**auto**: The widget adopts the auto-adaptive color mode.
**dark**: The widget adopts the dark color mode.
**light**: The widget adopts the light color mode.| String | Yes (initial value: **auto**)| -| supportDimensions | Grid styles supported by the widget. Available values are as follows:
1 * 2: indicates a grid with one row and two columns.
2 * 2: indicates a grid with two rows and two columns.
2 * 4: indicates a grid with two rows and four columns.
4 * 4: indicates a grid with four rows and four columns.| String array| No | -| defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String | No | -| landscapeLayouts | Landscape layouts for the grid styles. Values in this array must correspond to the values in the **supportDimensions** array. This field is required only by Java-programmed widgets.| String array| No | -| portraitLayouts | Portrait layouts for the grid styles. Values in this array must correspond to the values in the **supportDimensions** array. This field is required only by Java-programmed widgets.| String array| No | -| updateEnabled | Whether the widget can be updated periodically. Available values are as follows:
**true**: The widget can be updated periodically, depending on the update way you select, either at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** is preferentially recommended.
**false**: The widget cannot be updated periodically.| Boolean | No | +| supportDimensions | Grid styles supported by the widget. Available values are as follows:
1 * 2: indicates a grid with one row and two columns.
2 * 1: indicates a grid with two rows and one column.
2 * 2: indicates a grid with two rows and two columns.
2 * 4: indicates a grid with two rows and four columns.
4 * 4: indicates a grid with four rows and four columns.| String array| No | +| defaultDimension | Default grid style of the widget. The value must be from the **supportDimensions** array of the widget.| String | No | +| updateEnabled | Whether the widget can be updated periodically. Available values are as follows:
**true**: The widget can be updated periodically, depending on the update way you select, either at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** is preferentially recommended.
**false**: The widget cannot be updated periodically.| Boolean | No | | scheduledUpdateTime | Scheduled time to update the widget. The value is in 24-hour format and accurate to minute. | String | Yes (initial value: **0:0**) | | updateDuration | Interval to update the widget. The value is a natural number, in the unit of 30 minutes.
If the value is **0**, this field does not take effect.
If the value is a positive integer ***N***, the interval is calculated by multiplying ***N*** and 30 minutes.| Number | Yes (initial value: **0**) | -| formConfigAbility | Link to a specific page of the application. The value is a URI. | String | Yes (initial value: left empty) | +| formConfigAbility | Name of the facility or activity used to adjust the ability. | String | Yes (initial value: left empty) | | formVisibleNotify | Whether the widget is allowed to use the widget visibility notification. | String | Yes (initial value: left empty) | -| jsComponentName | Component name of the widget. The value is a string with a maximum of 127 bytes. This attribute is required only by JavaScript-programmed widgets.| String | No | -| metaData | Metadata of the widget. This attribute contains the array of the **customizeData** attribute. For details, see Table 13. | Object | Yes (initial value: left empty) | -| customizeData | Custom information about the widget. For details, see Table 28. | Object array | Yes (initial value: left empty) | +| jsComponentName | Component name of the widget. The value is a string with a maximum of 127 bytes. This attribute is required only by JavaScript-programmed widgets.| String | No | +| metaData | Metadata of the widget. The value contains value of the **customizeData** attribute. For details, see Table 13. | Object | Yes (initial value: left empty) | +| customizeData | Custom information of the widget. For details, see Table 28. | Object array | Yes (initial value: left empty) | Table 28 Internal structure of the customizeData attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | --------------------------------------------------- | -------- | -------------------- | -| name | Name in the custom name-value pair. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| -| value | Value in the custom name-value pair. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| -| extra | Format of the current custom data. The value is the resource value of **extra**.| String | Yes (initial value: left empty)| +| name | Key name that identifies a data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| +| value | Value of the data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| +| extra | Current format of the custom data. The value indicates the resource.| String | Yes (initial value: left empty)| Example of the **forms** attribute structure: @@ -630,9 +624,9 @@ Example of the **forms** attribute structure: ] }, { - "name": "Form_Java", - "description": "It's Java Form", - "type": "Java", + "name": "Form_Js", + "description": "It's JS Form", + "type": "Js", "colorMode": "auto", "isDefault": false, "updateEnabled": true, @@ -663,13 +657,13 @@ Example of the **forms** attribute structure: Table 29 Internal structure of the distroFilter attribute -| Attribute | Description | Data Type| Initial Value Allowed| -| ------------- | ------------------------------------------------------------ | -------- | ---------- | -| apiVersion | Supported API versions. For details, see Table 30. | Object | No | -| screenShape | Supported screen shapes. For details, see Table 31. | Object array| No | -| screenWindow | Supported window resolutions when the application is running. This attribute applies only to the lite wearables. For details, see Table 32.| Object array| No | -| screenDensity | Pixel density of the screen, in dots per inch (DPI). For details, see Table 33. | Object array| No | -| countryCode | Country code used during application distribution. For details, see the ISO-3166-1 standard. Multiple enumerated values of countries and regions are supported. For details, see Table 34.| Object array| No | +| Attribute | Description | Data Type| Initial Value Allowed | +| ------------- | ------------------------------------------------------------ | -------- | -------------------- | +| apiVersion | Supported API versions. For details, see Table 30. | Object | No| +| screenShape | Supported screen shapes. For details, see Table 31. | Object array| No| +| screenWindow | Supported window resolutions for when the application is running. This attribute applies only to the lite wearables. For details, see Table 32.| Object array| No| +| screenDensity | Pixel density of the screen, in dots per inch (dpi). For details, see Table 33. | Object array| No| +| countryCode | Country code used for distributing the application. For details, see the ISO-3166-1 standard. Multiple enumerated values of countries and regions are supported. For details, see Table 34.| Object array| No| Table 30 Internal structure of the apiVersion attribute @@ -739,7 +733,7 @@ Table 35 Internal structure of the commonEvents attribute | ---------- | ------------------------------------------------------------ | ---------- | ------------------ | | name | Name of a static broadcast. | String | No | | permission | Permission needed to implement the static common event. | String array| Yes (initial value: left empty)| -| data | Additional data array to be carried by the current static common event. | String array| Yes (initial value: left empty)| +| data | Additional data array to be carried by the current static common event. | String array| Yes (initial value: left empty)| | type | Type array of the current static common event. | String array| Yes (initial value: left empty)| | events | A set of events for the wants that can be received. The value can be system predefined or custom.| String array| No | diff --git a/en/application-dev/quick-start/stage-structure.md b/en/application-dev/quick-start/stage-structure.md index 2733f0f0a7bfbeebf646813ff1395cf36babe49d..574597a20d7aa6f71d3eedfd177ef85fd526b72e 100644 --- a/en/application-dev/quick-start/stage-structure.md +++ b/en/application-dev/quick-start/stage-structure.md @@ -2,18 +2,18 @@ # Application Package Structure Configuration File -When developing an application in the Feature Ability (FA) model, you need to declare the package structure of the application in the **config.json** file. Similarly, when developing an application in the stage model, you need to declare the package structure of the application in the **module.json** and **app.json** files. +When developing an application in the Feature Ability (FA) model, you need to declare the package structure of the application in the **config.json** file. Similarly, when developing an application in the stage model, you need to declare the package structure of the application in the **module.json5** and **app.json** files. ## Configuration File Internal Structure -The configuration files consist of two parts: **app** and **module**. See Table 1 for details. +The configuration files each consist of two mandatory tags, namely, **app** and **module**. For details, see Table 1. Table 1 Configuration file internal structure | Tag| Description | Data Type| Initial Value Allowed| | -------- | ------------------------------------------------------------ | -------- | ---------- | -| app | Global configuration of an application. Different HAP files of an application must use the same **app** configuration. For details, see [Internal Structure of the app Tag](#internal-structure-of-the-app-tag).| Object | No | -| module | Configuration of a HAP file. The **module** configuration is valid only for the current HAP file. For details, see [Internal Structure of the module Tag](#internal-structure-of-the-module-tag).| Object | No | +| app | Global configuration of the application. Different HAP files of an application must use the same **app** configuration. For details, see [Internal Structure of the app Tag](#internal-structure-of-the-app-tag).| Object | No | +| module | Configuration of the HAP file. It is valid only for the current HAP file. For details, see [Internal Structure of the module Tag](#internal-structure-of-the-module-tag).| Object | No | ### Internal Structure of the app Tag @@ -49,7 +49,7 @@ Table 2 Internal structure of the app tag | Attribute | Description | Data Type| Initial Value Allowed | | ------------------------------ | ------------------------------------------------------------ | -------- | ------------------------------------------- | -| bundleName | Bundle name that uniquely identifies the application. The value must comply with the following rules:
(1) Consists of letters, digits, underscores (_), and periods (.).
(2) Starts with a letter.
(3) Contains 7 to 127 bytes.
You are advised to use the reverse domain name notion, for example, *com.example.xxx*, where the first part is the domain suffix **com**, the second part is the vendor/individual name, and the third part is the application name, which can be of multiple levels.
For an application compiled with the system source code, its bundle name must be in the format of **com.ohos.*xxx***, where **ohos** signifies OpenHarmony. | String | No | +| bundleName | Bundle name that uniquely identifies the application. The value must comply with the following rules:
(1) Consists of letters, digits, underscores (_), and periods (.).
(2) Starts with a letter.
(3) Contains 7 to 127 bytes.
You are advised to use the reverse domain name notion, for example, *com.example.xxx*, where the first part is the domain suffix **com**, the second part is the vendor/individual name, and the third part is the application name, which can be of multiple levels.
For an application compiled with the system source code, its bundle name must be in the format of **com.ohos.*xxx***, where **ohos** signifies OpenHarmony. | String | No | | debug | Whether the application can be debugged. | Boolean | Yes (initial value: **false**) | | icon | Icon of the application. The value is the index to the resource file. | String | No | | label | Name of the application. The value is a resource index to descriptions in multiple languages.| String | No | @@ -57,16 +57,16 @@ Table 2 Internal structure of the app tag | vendor | Application vendor. The value is a string with a maximum of 255 bytes.| String | Yes (initial value: left empty) | | versionCode | Version number of the application. The value is a 32-bit non-negative integer and less than 2 to the power of 31. It is used only to determine whether a version is later than another version. A larger value indicates a later version. Ensure that a new version of the application uses a value greater than any of its predecessors. | Number | No | | versionName | Text description of the version number, which is displayed to users.
The value consists of only digits and dots. The four-segment format *A.B.C.D* is recommended, wherein:
Segment 1: major version number, which ranges from 0 to 99. A major version consists of major new features or large changes.
Segment 2: minor version number, which ranges from 0 to 99. A minor version consists of some new features and large bug fixes.
Segment 3: feature version number, which ranges from 0 to 99. A feature version consists of scheduled new features.
Segment 4: maintenance release number or patch number, which ranges from 0 to 999. A maintenance release or patch consists of resolution to security flaws or minor bugs.| String | No | -| minCompatibleVersionCode | Minimum API version compatible with the application. | Number | Yes (initial value: value of **versionCode**)| -| minAPIVersion | Minimum API version required for running the application. | Number | No | -| targetAPIVersion | Target API version required for running the application. | Integer | No | +| minCompatibleVersionCode | Earliest version that the application is compatible with. | Number | Yes (initial value: value of **versionCode**)| +| minAPIVersion | Minimum API version required for running the application. | Number | No | +| targetAPIVersion | Target API version required for running the application. | Integer | No | | apiReleaseType | Type of the target API version required for running the application. The value can be **CanaryN**, **BetaN**, or **Release**, where **N** represents a positive integer.
**Canary**: indicates a restricted release.
**Beta**: indicates a publicly released beta version.
**Release**: indicates a publicly released official version.| String | Yes (initial value: **"Release"**) | | distributedNotificationEnabled | Whether the distributed notification feature is enabled for the application. | Boolean | Yes (initial value: **true**) | -| entityType | Category of the application, which can be **game**, **media**, **communication**, **news**, **travel**, **utility**, **shopping**, **education**, **kids**, **business**, and **photography**.| String | Yes (initial value: unspecified) | +| entityType | Category of the application, which can be **game**, **media**, **communication**, **news**, **travel**, **utility**, **shopping**, **education**, **kids**, **business**, and **photography**.| String | Yes (initial value: **"unspecified"**) | ### Internal Structure of the module Tag -Example of the **module.json** file: +Code snippet in the **module.json5** file: ```json { @@ -151,34 +151,34 @@ This tag stores the HAP configuration, which only applies to the current HAP fil Table 3 Internal structure of the module tag -| Attribute | Description | Data Type | Initial Value Allowed | -| ------------------- | ------------------------------------------------------------ | ---------- | ------------------------------------- | -| name | Name of the current module. After the module is packed into a HAP file, this attribute indicates the name of the HAP file. The value is a string with a maximum of 31 bytes and must be unique in the entire application.| String | No | -| type | Type of the current HAP file. There are three types: **entry**, **feature**, and **har**.| String | No | -| srcEntrance | Path of the entry JS code corresponding to the HAP file. The value is a string with a maximum of 127 bytes.| String | Yes | -| description | Description of the HAP file. The value can be a string or a resource index to descriptions in multiple languages.| String | Yes (initial value: left empty) | -| process | Process of the HAP file. The value is a string with a maximum of 31 bytes. If a process is configured under **hap**, all abilities of the application run in this process.| String | Yes (initial value: name of the HAP file) | -| mainElement | Entrance ability name or extension name of the HAP file. Only the ability or extension whose value is **mainElement** can be displayed in the Service Center. This attribute cannot be left at the initial value for an OpenHarmony atomic service.| String | Yes for an OpenHarmony application | -| deviceTypes | Types of the devices on which the HAP file can run. Table 4 lists the device types predefined by the system.
Different from **syscap**, which is based on the device capability (such as Bluetooth and Wi-Fi), **deviceTypes** is based on the device type.| String array| No (can be left empty) | -| deliveryWithInstall | Whether the current HAP file will be installed when the user installs the application. The value **true** means that the HAP file will be automatically installed when the user installs the application, and **false** means the opposite.| Boolean | No | -| installationFree | Whether the HAP file supports the installation-free feature.
**true**: The HAP file supports the installation-free feature and meets installation-free constraints.
**false**: The HAP file does not support the installation-free feature.

When **entry.hap** is set to **true**, all **feature.hap** fields related to **entry.hap** must be **true**.
When **entry.hap** is set to **false**, **feature.hap** fields related to **entry.hap** can be set to **true** or **false** based on service requirements. | Boolean | No | -| virtualMachine | Type of the target virtual machine (VM) where the current HAP file is running. It is used for cloud distribution, such as the application market and distribution center.
The value **ark** means that the target VM type is Ark, and **default** means otherwise. This attribute is automatically inserted when DevEco Studio builds the HAP file. When the decompression tool parses the HAP file, if the HAP file does not contain this attribute, the value is set to **default**. | String | Yes (initial value: **default**) | -| uiSyntax | Syntax type of the JS component.
**hml**: indicates that the JS component is developed using HML, CSS, or JS.
**ets**: indicates that the JS component is developed using the eTS declarative syntax.| String | Yes (initial value: **hml**) | -| pages | Profile resource used to list information about each page in the JS component. For details about how to use **pages**, see the **pages** example.| Object | No in the ability scenario| -| metadata | Custom metadata of the HAP file. The configuration is valid only for the current module, ability, or extensionAbility. For details about **metadata**, see [Internal Structure of the metadata Attribute](#internal-structure-of-the-metadata-attribute).| Array | Yes (initial value: left empty) | -| abilities | Metadata capability configuration, which is valid only for the current ability. For details about **abilities**, see [Internal Structure of the abilities Attribute](#internal-structure-of-the-abilities-attribute).| Object | Yes (initial value: left empty) | -| extensionAbilities | Configuration of extensionAbilities, which is valid only for the current extensionAbility. For details about **extensionAbilities**, see [Internal structure of the extensionAbility attribute](#internal-structure-of-the-extensionability-attribute).| Object | Yes (initial value: left empty) | -| requestPermissions | A set of permissions that the application needs to apply for from the system when the application is running. For details about **requestPermissions**, see [Internal structure of the requestPermissions attribute](#internal-structure-of-the-requestpermissions-attribute).| Object | Yes (initial value: left empty) | +| Attribute | Description | Data Type | Initial Value Allowed | +| -------------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ | +| name | Name of the current module. After the module is packed into a HAP file, this attribute indicates the name of the HAP file. The value is a string with a maximum of 31 bytes and must be unique in the entire application.| String | No | +| type | Type of the HAP file. There are three types: **entry**, **feature**, and **har**.| String | No | +| srcEntrance | Path of the entry JS code corresponding to the HAP file. The value is a string with a maximum of 127 bytes.| String | Yes | +| description | Description of the HAP file. The value can be a string or a resource index to descriptions in multiple languages.| String | Yes (initial value: left empty) | +| process | Process of the HAP file. The value is a string with a maximum of 31 bytes. If a process is configured under **hap**, all abilities of the application run in this process. This attribute applies only to system applications.| String | Yes (initial value: value of **bundleName** under the **app** tag) | +| mainElement | Entrance ability name or extension name of the HAP file. Only the ability or extension whose value is **mainElement** can be displayed in the Service Center. This attribute cannot be left at the initial value for an OpenHarmony atomic service.| String | Yes for an OpenHarmony application | +| deviceTypes | Types of the devices on which the HAP file can run. Table 4 lists the device types predefined by the system.
Unlike **syscap**, which is based on the device capability (such as Bluetooth and Wi-Fi), **deviceTypes** is based on the device type.| String array| No (can be left empty) | +| deliveryWithInstall | Whether the current HAP file will be installed when the user installs the application. The value **true** means that the HAP file will be automatically installed when the user installs the application, and **false** means the opposite.| Boolean | No | +| installationFree | Whether the HAP file supports the installation-free feature.
**true**: The HAP file supports the installation-free feature and meets installation-free constraints.
**false**: The HAP file does not support the installation-free feature.

When **entry.hap** is set to **true**, all **feature.hap** fields related to **entry.hap** must be **true**.
When **entry.hap** is set to **false**, **feature.hap** fields related to **entry.hap** can be set to **true** or **false** based on service requirements. | Boolean | No | +| virtualMachine | Type of the target virtual machine (VM) where the current HAP file is running. It is used for cloud distribution, such as the application market and distribution center.
If the target VM type is Ark, the value is **ark**. Otherwise, the value is **default**. This attribute is automatically inserted when the IDE builds the HAP file. When the decompression tool parses the HAP file, if the HAP file does not contain this attribute, the value is set to **default**. | String | Yes (initial value: **default**) | +| uiSyntax | Syntax type of the JS component.
**"hml"**: indicates that the JS component is developed using HML, CSS, or JS.
**"ets"**: indicates that the JS component is developed using the eTS declarative syntax. | String | Yes (initial value: **"hml"**) | +| pages | Profile resource used to list information about each page in the JS component. For details about how to use **pages**, see the **pages** example.| Object | No in the ability scenario | +| metadata | Custom metadata of the HAP file. The configuration is valid only for the current module, ability, or extensionAbility. For details, see [Internal Structure of the metadata Attribute](#internal-structure-of-the-metadata-attribute). | Array | Yes (initial value: left empty) | +| abilities | Ability configuration, which is valid only for the current ability. For details, see [Internal Structure of the abilities Attribute](#internal-structure-of-the-abilities-attribute).| Object | Yes (initial value: left empty) | +| extensionAbilities | Extension ability configuration, which is valid only for the current Extension ability. For details, see [Internal structure of the extensionAbility attribute](#internal-structure-of-the-extensionability-attribute).| Object | Yes (initial value: left empty) | +| requestPermissions | A set of permissions that the application needs to request from the system when the application is running. For details, see [Internal structure of the requestPermissions attribute](#internal-structure-of-the-requestpermissions-attribute). | Object | Yes (initial value: left empty) | Table 4 System-defined deviceTypes values -| Device Type | Value | Description | -| ----------- | -------- | -------------------------------------------------------- | -| Tablet | tablet | Tablet, speaker with a screen | -| Smart TV | tv | Smart TV | -| Smart watch | wearable | Smart watch, kids' watch, especially a watch that provides call features| -| Head unit | car | Head unit | -| Router | router | Router | +| Value | Device Type | +| -------- | -------------------------------------------------------- | +| tablet | Tablet, speaker with a screen | +| tv | Smart TV | +| wearable | Smart watch, kids' watch, especially a watch that provides call features| +| car | Head unit | +| router | Router | Example of the **deviceTypes** attribute structure: @@ -232,8 +232,8 @@ Table 5 Internal structure of the metadata attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | -------------------------- | -| name | Name of a data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| -| value | Value of a data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty) | +| name | Name of the data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty)| +| value | Value of the data item. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty) | | resource | Custom data format. The value is an index to the resource that identifies the data.| String | Yes (initial value: left empty) | Example of the **metadata** attribute structure: @@ -267,14 +267,14 @@ Table 6 Internal structure of the abilities attribute | --------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ | | name | Logical name of the ability, which must be unique in the entire application. The value is a string with a maximum of 127 bytes.| String | No | | srcEntrance | JS code path corresponding to the ability. The value is a string with a maximum of 127 bytes.| String | No | -| launchType | Ability startup mode. The value can be **standard**, **singleton**, or **specified**. The default value is **singleton**. The value **standard** indicates common multi-instance, the value **singleton** indicates a singleton, and the value **specified** indicates one or more specified instances, depending on the internal service of the ability.| String | Yes (initial value: **singleton**) | +| launchType | Ability startup mode. Available values are as follows:
**"standard"**: indicates common multi-instance.
**"singleton"**: indicates a singleton.
**"specified"**: indicates one or more specified instances, depending on the internal service of the ability. | String | Yes (initial value: **singleton**) | | description | Ability description. The value can be a string or a resource index to descriptions in multiple languages.| String | Yes (initial value: left empty) | | icon | Icon of the ability. The value is the index to the resource file. | String | Yes (initial value: left empty)
If **ability** is set to **MainElement**, this attribute is mandatory.| -| permissions | A set of permissions that need to be applied for when the capability of another application is invoked. The value is a string array. Each array element is a permission name, which is usually represented by a reverse domain name (a maximum of 255 bytes). The permission can be predefined by the system or customized by the application. For the latter, the value must be the same as the **name** value of a permission defined in the **defPermissions** attribute. | String array| Yes (initial value: left empty) | -| metadata | Metadata about the ability. For details about metadata, see [Internal Structure of the metadata Attribute](#internal-structure-of-the-metadata-attribute).| Array | Yes (initial value: left empty) | +| permissions | Permissions required for abilities of another application to call the current ability. The value is an array of permission names predefined by the system, generally in the format of a reverse domain name the reverse domain name format (a maximum of 255 bytes).| String array| Yes (initial value: left empty) | +| metadata | Metadata of the ability. For details, see [Internal Structure of the metadata Attribute](#internal-structure-of-the-metadata-attribute).| Array | Yes (initial value: left empty) | | visible | Whether the ability can be invoked by other applications. The value **true** means that the ability can be invoked by other applications, and **false** means the opposite. | Boolean | Yes (initial value: **false**) | | continuable | Whether the ability can be migrated. The value **true** means that the ability can be migrated, and **false** means the opposite.| Boolean | Yes (initial value: **false**) | -| skills | Feature set of wants that can be received by the ability.
Configuration rule: In an entry package, you can configure multiple abilities with the **skills** attribute (where **action.system.home** and **entity.system.home** are configured) that has the entry capability. The **label** and **icon** in the first ability that has **skills** configured are used as the **label** and **icon** of the entire service/application.
The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application,
but not for an OpenHarmony service.
For details about the internal structure of **skills**, see [Internal Structure of the skills Attribute](#internal-structure-of-the-skills-attribute).| Array | Yes (initial value: left empty) | +| skills | Feature set of wants that can be received by the ability.
Configuration rule: In an entry package, you can configure multiple abilities with the **skills** attribute (where **action.system.home** and **entity.system.home** are configured) that has the entry capability. The **label** and **icon** in the first ability that has **skills** configured are used as the **label** and **icon** of the entire service/application.
The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application,
but not for an OpenHarmony service.
For details, see [Internal Structure of the skills Attribute](#internal-structure-of-the-skills-attribute). | Array | Yes (initial value: left empty) | | backgroundModes | Continuous task modes of the ability.
Continuous tasks are classified into the following types:
**dataTransfer**: service for downloading, backing up, sharing, or transferring data from the network or peer devices
**audioPlayback**: audio playback service
**audioRecording**: audio recording service
**location**: location and navigation services
**bluetoothInteraction**: Bluetooth scanning, connection, and transmission services (wearables)
**multiDeviceConnection**: multi-device interconnection service
**wifiInteraction**: Wi-Fi scanning, connection, and transmission services (multi-screen cloning)
**voip**: voice/video call and VoIP services
**taskKeeping**: computing service
| String | Yes (initial value: left empty) | Example of the **abilities** attribute structure: @@ -322,17 +322,17 @@ Table 7 Internal structure of the skills attribute | -------- | ------------------------------------------------------------ | ---------- | -------------------- | | actions | A set of want action values that can be received. The value can be a value predefined by the system or a custom value.| String array| Yes (initial value: left empty)| | entities | Categories of abilities that can receive the want. The value can be a value predefined by the system or a custom value.| String array| Yes (initial value: left empty)| -| uris | Data specification to be added to the want filter. The specification can be of data type only (**mimeType** attribute), URI only, or both. For details about the internal structure of **uris**, see Table 8.| Object array | Yes (initial value: left empty)| +| uris | Data specifications to be added to the want filter. The specification can be of data type only (**mimeType** attribute), URI only, or both. For details, see Table 8. | Object array | Yes (initial value: left empty)| Table 8 Internal structure of the uris attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------- | -------- | -------------------- | -| scheme | Scheme in the URI.| String | No | -| host | Host in the URI. | String | Yes (initial value: left empty)| -| port | Port number in the URI. | String | Yes (initial value: left empty)| -| path | Path in the URI. | String | Yes (initial value: left empty)| -| type | Type of the URI. | String | Yes (initial value: left empty)| +| scheme | Scheme of the URI.| String | No | +| host | Host value of the URI. | String | Yes (initial value: left empty)| +| port | Port number of the URI. | String | Yes (initial value: left empty)| +| path | **path** value of the URI. | String | Yes (initial value: left empty)| +| type | **type** value of the URI. | String | Yes (initial value: left empty)| Example of the **skills** attribute structure: @@ -391,23 +391,23 @@ Example of the **skills** attribute structure: #### Internal Structure of the extensionAbility Attribute -The **extensionAbility** attribute describes the configuration information of **extensionAbility**. The configuration is valid only for the current extensionAbility. +The **extensionAbility** attribute describes the configuration information of the current Extension ability. Table 9 Internal structure of the extensionAbility attribute | Attribute | Description | Data Type | Initial Value Allowed | | ----------- | ------------------------------------------------------------ | ---------- | ----------------------------- | -| name | Logical name of the current extensionAbility. The value is a string with a maximum of 127 bytes. The name must be unique in the entire application.| String | No | -| srcEntrance | JS code path corresponding to extensionAbility. The value is a string with a maximum of 127 bytes.| String | No | -| description | Description of the extensionAbility. The value can be a string or a resource index to descriptions in multiple languages.| String | Yes (initial value: left empty) | -| icon | Icon of the extensionAbility. The value is the index to the resource file. If **extensionAbility** is set to **MainElement**, this attribute is mandatory.| String | Yes (initial value: left empty) | -| label | Name of the extensionAbility displayed to users. The value is a resource index to names in multiple languages.
If **extensionAbility** is set to **MainElement**, this attribute is mandatory and the value must be unique in the application.| String | No | -| type | Type of the extension capability. The value can be **form**, **workScheduler**, **inputMethod**, service, **accessibility**, **dataShare**, **fileShare**, **staticSubscriber**, **wallpaper**, **backup**, or **window**.| String | No | +| name | Logical name of the current Extension ability. The value is a string with a maximum of 127 bytes. The name must be unique in the entire application.| String | No | +| srcEntrance | JS code path corresponding to the Extension ability. The value is a string with a maximum of 127 bytes.| String | No | +| description | Description of the Extension ability. The value can be a string or a resource index to descriptions in multiple languages.| String | Yes (initial value: left empty) | +| icon | Icon of the Extension ability. The value is the index to the resource file. If **extensionAbility** is set to **MainElement**, this attribute is mandatory.| String | Yes (initial value: left empty) | +| label | Name of the Extension ability displayed to users. The value is a resource index to names in multiple languages.
If **extensionAbility** is set to **MainElement**, this attribute is mandatory and the value must be unique in the application.| String | No | +| type | Type of the Extension ability. The value can be **"form"**, **"workScheduler"**, **"inputMethod"**, **"service"**, **"accessibility"**, **"dataShare"**, **"fileShare"**, **"staticSubscriber"**, **"wallpaper"**, **"backup"**, **"window"**, **"enterpriseAdmin"**, **"thumbnail"**, or **"preview"**.| String | No | | permissions | A set of permissions that need to be applied for when the capability of another application is invoked. The value is a string array. Each array element is a permission name, which is usually represented by a reverse domain name (a maximum of 255 bytes). The permission can be predefined by the system or customized by the application. For the latter, the value must be the same as the **name** value of a permission defined in the **defPermissions** attribute.| String array| Yes (initial value: left empty) | | uri | Data URI provided by the ability. The value is an array containing a maximum of 255 characters and is in the format of a reverse domain name. This attribute is mandatory when **type** is set to **extensionAbility** of the dataShare type.| String | Yes (initial value: left empty) | -| skills | Feature set of wants that can be received by the ability.
Configuration rule: In an entry package, you can configure multiple abilities with the **skills** attribute (where **action.system.home** and **entity.system.home** are configured) that has the entry capability. The **label** and **icon** in the first ability that has **skills** configured are used as the **label** and **icon** of the entire service/application.
The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application, but not for an OpenHarmony service.
For details about the internal structure of **skills**, see [Internal Structure of the skills Attribute](#internal-structure-of-the-skills-attribute). | Array | Yes (initial value: left empty) | -| metadata | Metadata of extensionAbility. For details about metadata, see [Internal Structure of the metadata Attribute](#internal-structure-of-the-metadata-attribute).| Object | Yes (initial value: left empty) | -| visible | Whether extensionAbility can be invoked by other applications. The value is of the Boolean type. The value **true** means that it can be invoked by other applications, and the value **false** means the opposite.| | Yes (initial value: **false**)| +| skills | Feature set of wants that can be received by the ability.
Configuration rule: In an entry package, you can configure multiple abilities with the **skills** attribute (where **action.system.home** and **entity.system.home** are configured) that has the entry capability. The **label** and **icon** in the first ability that has **skills** configured are used as the **label** and **icon** of the entire service/application.
The **skills** attribute with the entry capability can be configured for the feature package of an OpenHarmony application,
but not for an OpenHarmony service.
For details, see [Internal Structure of the skills Attribute](#internal-structure-of-the-skills-attribute). | Array | Yes (initial value: left empty) | +| metadata | Metadata of the Extension ability. For details, see [Internal Structure of the metadata Attribute](#internal-structure-of-the-metadata-attribute).| Object | Yes (initial value: left empty) | +| visible | Whether extensionAbility can be invoked by other applications. The value is of the Boolean type. The value **true** means that it can be invoked by other applications, and the value **false** means the opposite.| Boolean | Yes (initial value: **false**)| Example of the **extensionAbility** attribute structure: @@ -445,15 +445,15 @@ Example of the **extensionAbility** attribute structure: #### Internal Structure of the requestPermissions Attribute -This attribute identifies a set of permissions that the application needs to apply for from the system when the application is running. +The **requestPermissions** attribute indicates the permissions defined for the HAP file. -Table 10 requestPermissions attributes +Table 10 Internal structure of the requestPermissions attribute -| Attribute | Description | **Type** | **Value Range** | **Default Value** | **Restrictions** | -| --------- | ------------------------------------------------------------ | ------------------------------- | ----------------------------------------------------------- | ---------------------- | ------------------------------------------------------------ | -| name | Permission name. This attribute is mandatory. | String | Custom | N/A | Parsing will fail if this attribute is not set. | -| reason | Reason for requesting the permission. This attribute is mandatory when the permission to request is **user_grant**. | String | A maximum of 256 bytes | Empty | If the permission to request is **user_grant**, this attribute is required for the application to be released to AppGallery. Multi-language adaptation is required.| -| usedScene | Application scenario and timing for using the permission. This attribute is mandatory when the permission to request is **user_grant**. It consists of the **ability** and **when** sub-attributes. Multiple abilities can be configured.| **ability**: string array; **when**: string| **ability**: ability name; **when**: **inuse** or **always**| **ability**: null; **when**: **inuse**| If the permission to request is **user_grant**, the **ability** sub-attribute is mandatory and **when** is optional. | +| Attribute | Description | Type | Value Range | Default Value | Restrictions | +| --------- | ------------------------------------------------------------ | --------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------- | ------------------------------------------------------------ | +| name | Permission name. This attribute is mandatory. | String | Custom | N/A | Parsing will fail if this attribute is not set. | +| reason | Reason for requesting the permission. This attribute is mandatory when the permission to request is **user_grant**. | String | Resource reference of the string type in `$string: ***` format | Empty | If the permission to request is **user_grant**, this attribute is required for the application to be released to AppGallery. Multi-language adaptation is required. | +| usedScene | Application scenario and timing for using the permission. This attribute is mandatory when the permission to request is **user_grant**. It consists of the **abilities** and **when** sub-attributes. Multiple abilities can be configured. | **abilities**: string array; **when**: string | **abilities**: array of ability names; **when**: **inuse** and **always** | **abilities**: left empty; **when**: left empty | If the permission to request is **user_grant**, the **ability** sub-attribute is mandatory and **when** is optional. | Example of the **requestPermissions** attribute structure: @@ -464,7 +464,7 @@ Example of the **requestPermissions** attribute structure: "usedScene": { "abilities": [ "AudioAbility", - "VedioAbility", + "VideoAbility", ], "when": "inuse" } @@ -477,30 +477,28 @@ The **forms** attribute indicates the service widget configuration. The service 1. Set **type** to **form** in **extensions**. -2. Specify the **form** information in **metadata**, where: - - - **name** indicates the name of the service widget, for example, **ohos.extability.form**. - - - **resource** indicates where the resources of the service widget are stored. +2. Specify the **form** information in **metadata**, where: + - **name** indicates the name of the service widget, for example, **ohos.extability.form**. + - **resource** indicates where the resources of the service widget are stored. Table 11 Internal structure of the forms attribute -| Attribute | Description | Data Type | Initial Value Allowed | -| ----------------- | ------------------------------------------------------------ | ---------- | ----------------------------- | -| name | Class name of the widget. The value is a string with a maximum of 127 bytes. | String | No | -| description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String | Yes (initial value: left empty) | -| src | UI code of a JS service widget. It is recommended that you use the adaptive layout to display a service widget of different specifications. If the layout of a service widget of different specifications differs greatly, you are advised to use different service widgets.| String | Yes (initial value: left empty) | -| window | Adaptive capability of a JS service widget. For details about the window structure, see Table 12. | Object | Yes (initial value: left empty) | -| isDefault | Whether the service widget is the default one. Each ability has only one default service widget. **true**: The service widget is the default one. **false**: The service widget is not the default one.| Boolean | No | -| colorMode | Theme style of the service widget. The value can be **auto**, **dark**, or **light**.| String | Yes (initial value: **auto**) | -| supportDimensions | Dimensions supported by the service widget. The value can be **1 * 2**, **2 * 2**, **2 * 4**, or **4 * 4**, where the number before the asterisk (*) indicates the number of rows, and the number after the asterisk (*) indicates the number of columns.| String array| No | -| defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String | No | -| updateDuration | Update frequency of a widget. The unit is 30 minutes. The value is a multiple of 30. The highest frequency of refreshing a widget is once every 30 minutes. You can also use scheduled refresh to refresh a widget at a fixed time or once every 30 minutes. If both of them are configured, the scheduled refresh takes precedence.| Number | Yes (initial value: left empty) | -| metadata | Custom information about a widget. For details about the internal structure of metadata, see Table 5. | Object | Yes (initial value: left empty) | -| formConfigAbility | Ability name for widget adjustment. The value is a string of up to 127 characters. The value must be in the following format:
ability:// Name of an ability.
The name must be the same as that of the current application.| String | Yes (initial value: left empty) | -| formVisibleNotify | Whether the widget is allowed to use the visibility notification. The value is **true** or **false**.| Boolean | Yes (initial value: **false**)| - -Table 12 Internal structure of window +| Attribute | Description | Data Type | Initial Value Allowed | +| ------------------- | ------------------------------------------------------------ | ---------- | ----------------------------- | +| name | Class name of the widget. The value is a string with a maximum of 127 bytes. | String | No | +| description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String | Yes (initial value: left empty) | +| src | UI code of a JS service widget. It is recommended that you use the adaptive layout to display a service widget of different specifications. If the layout of a service widget of different specifications differs greatly, you are advised to use different service widgets.| String | Yes (initial value: left empty) | +| window | Adaptive capability of a JS service widget. For details, see Table 12. | Object | Yes (initial value: left empty) | +| isDefault | Whether the widget is a default one. Each ability has only one default widget. **true**: The service widget is the default one. **false**: The service widget is not the default one.| Boolean | No | +| colorMode | Color mode of the widget. The value can be **auto**, **dark**, or **light**.| String | Yes (initial value: **auto**) | +| supportDimensions | Dimensions supported by the service widget. The value can be **1 * 2**, **2 * 1**, **2 * 2**, **2 * 4**, or **4 * 4**, where the number before the asterisk (\*) indicates the number of rows, and the number after the asterisk (\*) indicates the number of columns. | String array| No | +| defaultDimension | Default grid style of the widget. The value must be from the **supportDimensions** array of the widget.| String | No | +| updateDuration | Update frequency of a widget. The unit is 30 minutes. The value is a multiple of 30. The highest frequency of refreshing a widget is once every 30 minutes. You can also use scheduled refresh to refresh a widget at a fixed time or once every 30 minutes. If both of them are configured, the scheduled refresh takes precedence.| Number | Yes (initial value: left empty) | +| metadata | Metadata of the widget. For details, see Table 5. | Object | Yes (initial value: left empty) | +| formConfigAbility | Ability name for widget adjustment. The value is a string of up to 127 characters. The value must be in the following format:
ability:// Name of an ability.
The name must be the same as that of the current application.| String | Yes (initial value: left empty) | +| formVisibleNotify | Whether the widget is allowed to use the visibility notification. The value is **true** or **false**.| Boolean | Yes (initial value: **false**)| + +Table 13 Internal structure of the window attribute | Attribute | Description | Data Type| Initial Value Allowed | | --------------- | ------------------------------------------------------------ | -------- | -------------------- | @@ -545,7 +543,7 @@ Define the **form_config.json** file (this file name is customizable) in **resou } ``` -Define metadata information in the **extension** component of the **module.json** file. +Define metadata information in the **extension** component of the **module.json5** file. ```json { @@ -578,8 +576,8 @@ Table 13 Internal structure of the shortcuts attribute | Attribute | Description | Data Type| Initial Value Allowed | | ---------- | ------------------------------------------------------------ | -------- | -------------------------- | -| shortcutId | ID of the shortcut. The value is a string with a maximum of 63 bytes. | String | No | -| label | Label of the shortcut, that is, the text description displayed by the shortcut. The value can be a string or a resource index to the description. The value is a string with a maximum of 63 bytes.| String | Yes (initial value: left empty) | +| shortcutId | ID of the shortcut. The value is a string with a maximum of 63 bytes. | String | No | +| label | Label of the shortcut, that is, the text description displayed for the shortcut. The value can be a string or a resource index to the description. The value is a string with a maximum of 63 bytes.| String | Yes (initial value: left empty) | | icon | Icon of the shortcut. The value is the index to the resource file. | String | Yes (initial value: left empty)| | wants | Wants to which the shortcut points. The attribute consists of the **bundleName** and **abilityName** sub-attributes.
**bundleName**: target bundle name of the shortcut; string type.
**abilityName**: target component name of the shortcut; string type.| Object | Yes (initial value: left empty) | @@ -603,7 +601,7 @@ Define the **shortcut_config.json** file (this file name is customizable) in **r } ``` -Define the **metadata** information under **module** in the **config.json** file as follows: +Define the **metadata** information under **module** in the **module.json5** file as follows: ```json { @@ -670,7 +668,7 @@ Define the **common_event_config.json** file in **resources/base/profile** in th } ``` -Define the **metadata** information under **extension** in the **module.json** file as follows: +Define the **metadata** information under **extension** in the **module.json5** file as follows: ```json "extensionAbilities": [ @@ -690,54 +688,54 @@ Define the **metadata** information under **extension** in the **module.json** f #### Internal Structure of the distroFilter Attribute -Application distribution rules. +Distribution rules of the application. -This attribute defines the rules for distributing HAP files based on different device specifications, so that precise matching can be performed when AppGallery distributes applications. Applications can be distributed by API version, screen shape, or screen resolution. During distribution, a unique HAP is determined based on the mapping between **deviceType** and these three factors. +This attribute defines the rules for distributing HAP files based on different device specifications, so that precise matching can be performed when AppGallery distributes applications. Distribution rules cover three factors: API version, screen shape, and screen resolution. During distribution, a unique HAP is determined based on the mapping between **deviceType** and these three factors. -Table 15 Internal structure of the distroFilter attribute +Table 16 Internal structure of the distroFilter attribute | Attribute | Description | Data Type| Initial Value Allowed | | ------------- | ------------------------------------------------------------ | -------- | -------------------------- | | apiVersion | Supported API versions. For details, see Table 16. | Object array| Yes (initial value: left empty)| | screenShape | Supported screen shapes. | Object array| Yes (initial value: left empty)| -| screenWindow | Supported window resolutions when the application is running. This attribute applies only to the lite wearables.| Object array| Yes (initial value: left empty)| -| screenDensity | Dots per inch (DPI) of the screen. This attribute is optional. The value options are as follows:
**sdpi**: small-scale dots per inch. This value is applicable for devices with a DPI range of (0, 120].
**mdpi**: medium-scale dots per inch. This value is applicable for devices with a DPI range of (120, 160].
**ldpi**: large-scale dots per inch. This value is applicable for devices with a DPI in the (160, 240] range.
**xldpi**: extra-large-scale dots per inch. This value is applicable for devices with a DPI in the (240, 320] range.
**xxldpi**: extra-extra-large-scale dots per inch (XXLDPI). This value is applicable for devices with a DPI in the (320, 480] range.
**xxxldpi**: extra-extra-extra-large-scale dots per inch. This value is applicable for devices with a DPI in the (480, 640] range.| Object array| Yes (initial value: left empty)| -| countryCode | Code of the country or region to which an application is to be distributed. For details, see ISO-3166-1. Enumerated definitions of multiple countries and regions are supported. This attribute is optional. The substring of the value consists of two uppercase letters and indicates the supported countries or regions.| Object array| Yes (initial value: left empty)| +| screenWindow | Supported window resolutions for when the application is running. This attribute applies only to the lite wearables.| Object array| Yes (initial value: left empty)| +| screenDensity | Pixel density of the screen, in dots per inch (dpi). This attribute is optional. The value options are as follows:
**sdpi**: small-scale dots per inch. This value is applicable for devices with a DPI range of (0, 120].
**mdpi**: medium-scale dots per inch. This value is applicable for devices with a DPI range of (120, 160].
**ldpi**: large-scale dots per inch. This value is applicable for devices with a DPI in the (160, 240] range.
**xldpi**: extra-large-scale dots per inch. This value is applicable for devices with a DPI in the (240, 320] range.
**xxldpi**: extra-extra-large-scale dots per inch (XXLDPI). This value is applicable for devices with a DPI in the (320, 480] range.
**xxxldpi**: extra-extra-extra-large-scale dots per inch. This value is applicable for devices with a DPI in the (480, 640] range.| Object array| Yes (initial value: left empty)| +| countryCode | Code of the country or region to which the application is to be distributed. For details, see ISO-3166-1. Enumerated definitions of multiple countries and regions are supported. This attribute is optional. The substring of the value consists of two uppercase letters and indicates the supported countries or regions. | Object array| Yes (initial value: left empty)| -Table 16 Internal structure of the apiVersion attribute +Table 17 Internal structure of the apiVersion attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | -------------------- | | policy | Blocklist and trustlist rule of the sub-attribute value. Set this attribute to **exclude** or **include**. **include** indicates that the sub-attribute value is in the trustlist. If the value matches any of the **value** enums, it matches this attribute.| String | Yes (initial value: left empty)| | value | An integer of the existing API version, for example, 4, 5, or 6. If an application uses two software versions developed using API 5 and API 6 for the same device model, two installation packages of the entry type can be released.| Array | Yes (initial value: left empty)| -Table 17 Internal structure of the screenShape attribute +Table 18 Internal structure of the screenShape attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | -------------------- | | policy | Blocklist and trustlist rule of the sub-attribute value. Set this attribute to **exclude** or **include**. **include** indicates that the sub-attribute value is in the trustlist. If the value matches any of the **value** enums, it matches this attribute.| String | Yes (initial value: left empty)| | value | The value can be **circle** or **rect**. Example: Different HAP files can be provided for a smart watch with a circular face and a smart watch with a rectangular face.| Array | Yes (initial value: left empty)| -Table 18 Internal structure of the screenWindow attribute +Table 19 Internal structure of the screenWindow attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | -------------------- | | policy | Blocklist and trustlist rule of the sub-attribute value. Set this attribute to **exclude** or **include**. **include** indicates that the sub-attribute value is in the trustlist. If the value matches any of the **value** enums, it matches this attribute.| String | Yes (initial value: left empty)| | value | Width and height of the screen. The value is in the "width * height" format, in pixels, for example, **454*454**.| Array | Yes (initial value: left empty)| -Table 19 Internal structure of the screenDensity attribute +Table 20 Internal structure of the screenDensity attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | -------------------- | | policy | Blocklist and trustlist rule of the sub-attribute value. Set this attribute to **exclude** or **include**. **include** indicates that the sub-attribute value is in the trustlist. If the value matches any of the **value** enums, it matches this attribute.| String | Yes (initial value: left empty)| -| value | Dots per inch (DPI) of the screen. | Array | Yes (initial value: left empty)| +| value | Pixel density of the screen, in dots per inch (dpi). | Array | Yes (initial value: left empty)| -Table 20 Internal structure of the countryCode attribute +Table 21 Internal structure of the countryCode attribute | Attribute| Description | Data Type| Initial Value Allowed | | -------- | ------------------------------------------------------------ | -------- | -------------------- | | policy | Blocklist and trustlist rule of the sub-attribute value. Set this attribute to **exclude** or **include**. **include** indicates that the sub-attribute value is in the trustlist. If the value matches any of the **value** enums, it matches this attribute.| String | Yes (initial value: left empty)| -| value | Code of the country or region to which an application is to be distributed. | Array | Yes (initial value: left empty)| +| value | Code of the country or region to which the application is to be distributed. | Array | Yes (initial value: left empty)| Example of the **distroFilter** attribute structure: @@ -762,7 +760,7 @@ Define the **distroFilter_config.json** file in **resources/base/profile** of th ] ``` -Define the **metadata** information under **extensionAbilities** in the **module.json** file as follows: +Define the **metadata** information under **extensionAbilities** in the **module.json5** file as follows: ```json "extensionAbilities": [ @@ -780,3 +778,4 @@ Define the **metadata** information under **extensionAbilities** in the **module ] ``` + diff --git a/en/application-dev/reference/apis/js-apis-Context.md b/en/application-dev/reference/apis/js-apis-Context.md index 9ceaca4f6f4c784172d6f6905d702b7970a67000..1a4006245c871421e5d88da6f8382d27198b98f0 100644 --- a/en/application-dev/reference/apis/js-apis-Context.md +++ b/en/application-dev/reference/apis/js-apis-Context.md @@ -27,9 +27,9 @@ If this API is called for the first time, a root directory will be created. **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the local root directory.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | -------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the local root directory.| **Example** @@ -55,8 +55,8 @@ If this API is called for the first time, a root directory will be created. **Return value** -| Type | Description | -| ---------------- | ----------- | +| Type | Description | +| ---------------- | ---------------------- | | Promise\ | Promise used to return the local root directory.| **Example** @@ -81,11 +81,11 @@ Verifies whether a specific PID and UID have the given permission. This API uses **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | --------------------------------------- | ---- | -------------------- | -| permission | string | Yes | Name of the permission to verify. | -| options | [PermissionOptions](#permissionoptions) | Yes | Permission options. | -| callback | AsyncCallback\ | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| +| Name | Type | Mandatory| Description | +| ---------- | --------------------------------------- | ---- | ------------------------------------- | +| permission | string | Yes | Name of the permission to verify. | +| options | [PermissionOptions](#permissionoptions) | Yes | Permission options. | +| callback | AsyncCallback\ | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| **Example** @@ -110,10 +110,10 @@ Verifies whether the current PID and UID have the given permission. This API use **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | ---------------------- | ---- | -------------------- | -| permission | string | Yes | Name of the permission to verify. | -| callback | AsyncCallback\ | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| +| Name | Type | Mandatory| Description | +| ---------- | ---------------------- | ---- | ------------------------------------- | +| permission | string | Yes | Name of the permission to verify. | +| callback | AsyncCallback\ | Yes | Callback used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| **Example** @@ -133,15 +133,15 @@ Verifies whether a specific PID and UID have the given permission. This API uses **Parameters** -| Name | Type | Mandatory | Description | -| ---------- | --------------------------------------- | ---- | -------- | -| permission | string | Yes | Name of the permission to verify.| -| options | [PermissionOptions](#permissionoptions) | No | Permission options. | +| Name | Type | Mandatory| Description | +| ---------- | --------------------------------------- | ---- | ---------------- | +| permission | string | Yes | Name of the permission to verify.| +| options | [PermissionOptions](#permissionoptions) | No | Permission options. | **Return value** -| Type | Description | -| ---------------- | ---------------------------------- | +| Type | Description | +| ---------------- | ----------------------------------------------------------- | | Promise\ | Promise used to return the permission verification result. The value **0** means that the PID and UID have the given permission, and the value **-1** means the opposite.| **Example** @@ -168,11 +168,11 @@ Requests certain permissions from the system. This API uses an asynchronous call **Parameters** -| Name | Type | Mandatory | Description | -| -------------- | ---------------------------------------- | ---- | ----------------------------------- | -| permissions | Array\ | Yes | Permissions to request. This parameter cannot be **null**. | -| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.| -| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Callback used to return the permission request result. | +| Name | Type | Mandatory| Description | +| -------------- | ------------------------------------------------------------ | ---- | ----------------------------------------------- | +| permissions | Array\ | Yes | Permissions to request. This parameter cannot be **null**. | +| requestCode | number | Yes | Request code to be passed to **PermissionRequestResult**.| +| resultCallback | AsyncCallback<[PermissionRequestResult](#permissionrequestresult)> | Yes | Callback used to return the permission request result. | **Example** @@ -242,9 +242,9 @@ Obtains information about the current application. This API uses an asynchronous **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------- | ---- | ------------ | -| callback | AsyncCallback\ | Yes | Callback used to return the application information.| +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | ------------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the application information.| **Example** @@ -266,8 +266,8 @@ Obtains information about the current application. This API uses a promise to re **Return value** -| Type | Description | -| ------------------------- | --------- | +| Type | Description | +| ------------------------- | ------------------ | | Promise\ | Promise used to return the application information.| **Example** @@ -293,9 +293,9 @@ Obtains the bundle name of this ability. This API uses an asynchronous callback **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ------------------ | -| callback | AsyncCallback\ | Yes | Callback used to return the bundle name.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ----------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the bundle name.| **Example** @@ -317,8 +317,8 @@ Obtains the bundle name of this ability. This API uses a promise to return the r **Return value** -| Type | Description | -| ---------------- | ---------------- | +| Type | Description | +| ---------------- | ------------------------- | | Promise\ | Promise used to return the bundle name.| **Example** @@ -344,9 +344,9 @@ Obtains information about the current process, including the PID and process nam **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the process information.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the process information.| **Example** @@ -368,8 +368,8 @@ Obtains information about the current process, including the PID and process nam **Return value** -| Type | Description | -| --------------------- | ------- | +| Type | Description | +| --------------------- | -------------- | | Promise\ | Promise used to return the process information.| **Example** @@ -397,9 +397,9 @@ This API is available only to Page abilities. **Parameters** -| Name | Type | Mandatory | Description | -| -------- | --------------------------- | ---- | -------------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the **ohos.bundle.ElementName** object.| +| Name | Type | Mandatory| Description | +| -------- | --------------------------- | ---- | ---------------------------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the **ohos.bundle.ElementName** object.| **Example** @@ -423,8 +423,8 @@ This API is available only to Page abilities. **Return value** -| Type | Description | -| --------------------- | ------------------------------------ | +| Type | Description | +| --------------------- | ------------------------------------------ | | Promise\ | Promise used to return the **ohos.bundle.ElementName** object.| **Example** @@ -448,9 +448,9 @@ Obtains the name of the current process. This API uses an asynchronous callback **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the process name.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | -------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the process name.| **Example** @@ -472,8 +472,8 @@ Obtains the name of the current process. This API uses a promise to return the r **Return value** -| Type | Description | -| ---------------- | ---------- | +| Type | Description | +| ---------------- | -------------------- | | Promise\ | Promise used to return the process name.| **Example** @@ -499,9 +499,9 @@ Obtains the bundle name of the calling ability. This API uses an asynchronous ca **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the bundle name.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the bundle name.| **Example** @@ -523,8 +523,8 @@ Obtains the bundle name of the calling ability. This API uses a promise to retur **Return value** -| Type | Description | -| ---------------- | -------------- | +| Type | Description | +| --------------- | ------------------------- | | Promise\ | Promise used to return the bundle name.| **Example** @@ -548,9 +548,9 @@ Obtains the cache directory of the application in the internal storage. This API **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | --------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the cache directory.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the cache directory.| **Example** @@ -576,8 +576,8 @@ Obtains the cache directory of the application in the internal storage. This API **Return value** -| Type | Description | -| ---------------- | --------------- | +| Type | Description | +| --------------- | ------------------------- | | Promise\ | Promise used to return the cache directory.| **Example** @@ -601,9 +601,9 @@ Obtains the file directory of the application in the internal storage. This API **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the file directory.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the file directory.| **Example** @@ -629,8 +629,8 @@ Obtains the file directory of the application in the internal storage. This API **Return value** -| Type | Description | -| ---------------- | ------------------- | +| Type | Description | +| --------------- | ------------------------- | | Promise\ | Promise used to return the file directory.| **Example** @@ -656,9 +656,9 @@ If the distributed file path does not exist, the system will create one and retu **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | ---------------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the distributed file path. If the distributed file path does not exist, the system will create one and return the created path.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the distributed file path. If the distributed file path does not exist, the system will create one and return the created path.| **Example** @@ -686,8 +686,8 @@ If the distributed file path does not exist, the system will create one and retu **Return value** -| Type | Description | -| ---------------- | ----------------------------------- | +| Type | Description | +| --------------- | ------------------------- | | Promise\ | Promise used to return the distributed file path. If this API is called for the first time, a new path will be created.| **Example** @@ -710,9 +710,9 @@ Obtains the application type. This API uses an asynchronous callback to return t **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------- | ---- | -------------------------------- | -| callback | AsyncCallback\ | Yes | Callback used to return the application type.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the application type.| **Example** @@ -738,8 +738,8 @@ Obtains the application type. This API uses a promise to return the result. **Return value** -| Type | Description | -| ---------------- | ------------------ | +| Type | Description | +| --------------- | ------------------------- | | Promise\ | Promise used to return the application type.| **Example** @@ -762,9 +762,9 @@ Obtains the **ModuleInfo** object of the application. This API uses an asynchron **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | --------------------------------------- | -| callback | AsyncCallback\<[HapModuleInfo](#hapmoduleinfo)> | Yes | Callback used to return the **ModuleInfo** object.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\<[HapModuleInfo](#hapmoduleinfo)> | Yes | Callback used to return the **ModuleInfo** object.| **Example** @@ -790,8 +790,8 @@ Obtains the **ModuleInfo** object of the application. This API uses a promise to **Return value** -| Type | Description | -| ---------------------------------------- | ------------------ | +| Type | Description | +| --------------- | ------------------------- | | Promise\<[HapModuleInfo](#hapmoduleinfo)> | Promise used to return the **ModuleInfo** object.| **Example** @@ -814,9 +814,9 @@ Obtains the version information of the application. This API uses an asynchronou **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | ------------------------------ | -| callback | AsyncCallback\<[AppVersionInfo](#appversioninfo)> | Yes | Callback used to return the version information.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\<[AppVersionInfo](#appversioninfo)> | Yes | Callback used to return the version information.| **Example** @@ -842,8 +842,8 @@ Obtains the version information of the application. This API uses a promise to r **Return value** -| Type | Description | -| ---------------------------------------- | --------- | +| Type | Description | +| --------------- | ------------------------- | | Promise\<[AppVersionInfo](#appversioninfo)> | Promise used to return the version information.| **Example** @@ -866,9 +866,9 @@ Obtains information about this ability. This API uses an asynchronous callback t **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | ---- | --------------------------------------- | -| callback | AsyncCallback\<[AbilityInfo](#abilityInfo)> | Yes | Callback used to return the ability information.| +| Name | Type | Mandatory| Description | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback\<[AbilityInfo](#abilityInfo)> | Yes |Callback used to return the ability information.| **Example** @@ -894,8 +894,8 @@ Obtains information about this ability. This API uses a promise to return the re **Return value** -| Type | Description | -| ---------------------------------------- | ------------------ | +| Type | Description | +| --------------- | ------------------------- | | Promise\<[AbilityInfo](#abilityInfo)> | Promise used to return the ability information.| **Example** @@ -918,9 +918,9 @@ Obtains the context of the application. **Return value** -| Type | Description | -| ------- | ---------- | -| Context | Application context.| +| Type | Description | +| --------- |------ | +| Context |Application context.| **Example** @@ -929,53 +929,99 @@ import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext().getApplicationContext(); ``` +## Context.getExternalCacheDir + +getExternalCacheDir(callback: AsyncCallback\): void + +Obtains the external cache directory of the application. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ------------------ | +| callback | AsyncCallback\ | Yes | Callback used to return the absolute path of the cache directory.| + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getExternalCacheDir() +``` + +## Context.getExternalCacheDir + +getExternalCacheDir(): Promise\; + +Obtains the external cache directory of the application. This API uses a promise to return the result. + +**System capability**: SystemCapability.Ability.AbilityRuntime.Core + +**Return value** + +| Type | Description | +| ---------------- | ---------------- | +| Promise\ | Promise used to return the absolute path of the cache directory.| + +**Example** + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getExternalCacheDir().then((data) => { + console.info("=======================>getExternalCacheDirCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); +}); +``` + ## PermissionOptions **System capability**: SystemCapability.Ability.AbilityRuntime.Core -| Name | Readable/Writable| Type | Mandatory | Description | -| ---- | ---- | ------ | ---- | ----- | -| pid | Read-only | number | No | Process ID.| -| uid | Read-only | number | No | User ID.| +| Name| Readable/Writable| Type | Mandatory| Description | +| ---- | -------- | ------ | ---- | ------ | +| pid | Read-only | number | No | Process ID.| +| uid | Read-only | number | No | User ID.| ## PermissionRequestResult **System capability**: SystemCapability.Ability.AbilityRuntime.Core -| Name | Readable/Writable| Type | Mandatory | Description | -| ----------- | ---- | -------------- | ---- | ---------- | -| requestCode | Read-only | number | Yes | Request code passed.| -| permissions | Read-only | Array\ | Yes | Permissions requested. | -| authResults | Read-only | Array\ | Yes | Permission request result. | +| Name | Readable/Writable| Type | Mandatory| Description | +| ----------- | -------- | -------------- | ---- | ------------------ | +| requestCode | Read-only | number | Yes | Request code passed.| +| permissions | Read-only | Array\ | Yes | Permissions requested. | +| authResults | Read-only | Array\ | Yes | Permission request result. | ## HapModuleInfo Describes the HAP module information. -| Name | Type | Readable | Writable | Description | -| ---------------- | ------------------- | -------- | -------- | ----------------------------------------- | -| name | string | Yes | No | Module name. | -| description | string | Yes | No | Module description. | -| descriptionId | number | Yes | No | Module description ID. | -| icon | string | Yes | No | Module icon. | -| label | string | Yes | No | Module label. | -| labelId | number | Yes | No | Module label ID. | -| iconId | number | Yes | No | Module icon ID. | -| backgroundImg | string | Yes | No | Module background image. | -| supportedModes | number | Yes | No | Running modes supported by the module. | -| reqCapabilities | Array\ | Yes | No | Capabilities required for module running. | -| deviceTypes | Array\ | Yes | No | Device types supported by the module. | -| abilityInfo | Array\ | Yes | No | Ability information. | -| moduleName | string | Yes | No | Module name. | -| mainAbilityName | string | Yes | No | Name of the main ability. | -| installationFree | boolean | Yes | No | Whether installation-free is supported. | -| mainElementName | string | Yes | No | Information about the main ability. | +| Name | Type| Readable| Writable| Description| +| ------ | ------ | ------ | ------ | ------ | +| name | string | Yes | No | Module name. | +| description | string | Yes | No | Module description. | +| descriptionId | number | Yes | No | Module description ID. | +| icon | string | Yes | No | Module icon. | +| label | string | Yes | No | Module label. | +| labelId | number | Yes | No | Module label ID. | +| iconId | number | Yes | No | Module icon ID. | +| backgroundImg | string | Yes | No | Module background image. | +| supportedModes | number | Yes | No | Running modes supported by the module. | +| reqCapabilities | Array\ | Yes | No | Capabilities required for module running.| +| deviceTypes | Array\ | Yes | No | Device types supported by the module.| +| abilityInfo | Array\ | Yes | No | Ability information. | +| moduleName | string | Yes | No | Module name. | +| mainAbilityName | string | Yes | No | Name of the main ability. | +| installationFree | boolean | Yes | No | Whether installation-free is supported. | +| mainElementName | string | Yes| No| Information about the main ability.| ## AppVersionInfo - -| Name | Type | Readable | Writable | Description | -| ----------- | ------ | ---- | ---- | ------- | -| appName | string | Yes | No | Module name. | -| versionCode | number | Yes | No | Module description.| -| versionName | string | Yes | No | Module description ID.| +| Name | Type| Readable | Writable | Description| +| ------ | ------ | ------| ------ | ------ | +| appName | string | Yes | No | Module name. | +| versionCode | number | Yes | No | Module description. | +| versionName | string | Yes | No | Module description ID. | diff --git a/en/application-dev/reference/apis/js-apis-data-rdb.md b/en/application-dev/reference/apis/js-apis-data-rdb.md index 1b17be0e8011b117e821248ce9bd0c07d1165d47..ca5674ff52d11f79a0352b01f4e93cb76d05462d 100644 --- a/en/application-dev/reference/apis/js-apis-data-rdb.md +++ b/en/application-dev/reference/apis/js-apis-data-rdb.md @@ -29,7 +29,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context | Context | Yes| Context of the application or function.
See [Context](js-apis-Context.md) for versions earlier than API version 9.
See [Context](js-apis-ability-context.md) for API version 9 or later.| +| context | [Context](js-apis-Context.md) | Yes| Application context.| | config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| | version | number | Yes| RDB store version.| | callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes| Callback invoked to return the RDB store obtained.| @@ -37,8 +37,13 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul **Example** ```js +// Obtain the context. +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext() + +// Call getRdbStore. const STORE_CONFIG = { name: "RdbTest.db"} -data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { +data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { if (err) { console.info("Failed to get RdbStore, err: " + err) return @@ -59,7 +64,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context | Context | Yes| Context of the application or function.
See [Context](js-apis-Context.md) for versions earlier than API version 9.
See [Context](js-apis-ability-context.md) for API version 9 or later.| +| context | [Context](js-apis-Context.md) | Yes| Application context.| | config | [StoreConfig](#storeconfig) | Yes| Configuration of the RDB store.| | version | number | Yes| RDB store version.| @@ -72,8 +77,13 @@ Obtains an RDB store. This API uses a promise to return the result. You can set **Example** ```js +// Obtain the context. +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext() + +// Call getRdbStore. const STORE_CONFIG = { name: "RdbTest.db" } -let promise = data_rdb.getRdbStore(this.context, STORE_CONFIG, 1); +let promise = data_rdb.getRdbStore(context, STORE_CONFIG, 1); promise.then(async (rdbStore) => { console.log("Got RdbStore successfully.") }).catch((err) => { @@ -92,13 +102,18 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context | Context | Yes| Context of the application or function.
See [Context](js-apis-Context.md) for versions earlier than API version 9.
See [Context](js-apis-ability-context.md) for API version 9 or later.| +| context | [Context](js-apis-Context.md) | Yes| Application context.| | name | string | Yes| Name of the RDB store to delete.| | callback | AsyncCallback<void> | Yes| Callback invoked to return the result.| **Example** ```js -data_rdb.deleteRdbStore(this.context, "RdbTest.db", function (err, rdbStore) { +// Obtain the context. +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext() + +// Call deleteRdbStore. +data_rdb.deleteRdbStore(context, "RdbTest.db", function (err) { if (err) { console.info("Failed to delete RdbStore, err: " + err) return @@ -118,7 +133,7 @@ Deletes an RDB store. This API uses a promise to return the result. **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| context | Context | Yes| Context of the application or function.
See [Context](js-apis-Context.md) for versions earlier than API version 9.
See [Context](js-apis-ability-context.md) for API version 9 or later.| +| context | [Context](js-apis-Context.md) | Yes| Application context.| | name | string | Yes| Name of the RDB store to delete.| **Return value** @@ -128,7 +143,12 @@ Deletes an RDB store. This API uses a promise to return the result. **Example** ```js -let promise = data_rdb.deleteRdbStore(this.context, "RdbTest.db") +// Obtain the context. +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext() + +// Call deleteRdbStore. +let promise = data_rdb.deleteRdbStore(context, "RdbTest.db") promise.then(()=>{ console.log("Deleted RdbStore successfully.") }).catch((err) => { @@ -166,7 +186,7 @@ let predicates = new data_rdb.RdbPredicates("EMPLOYEE") inDevices(devices: Array<string>): RdbPredicates -Connects to the specified remote devices on the network during distributed database synchronization. +Sets an **RdbPredicates** to specify the remote devices to connect on the network during distributed database synchronization. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -191,7 +211,7 @@ predicates.inDevices(['12345678abcde']) inAllDevices(): RdbPredicates -Connects to all remote devices on the network during distributed database synchronization. +Sets an **RdbPredicates** to specify all remote devices on the network to connect during distributed database synchronization. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -780,14 +800,7 @@ Sets an **RdbPredicates** to filter out duplicate records. **Example** ```js let predicates = new data_rdb.RdbPredicates("EMPLOYEE") -predicates.equalTo("NAME", "Rose").distinct("NAME") -let promise = rdbStore.query(predicates, ["NAME"]) -promise.then((resultSet) => { - console.log("resultSet column names:" + resultSet.columnNames) - console.log("resultSet column count:" + resultSet.columnCount) -}).catch((err) => { - console.log("query err.") -}) +predicates.equalTo("NAME", "Rose").distinct() ``` @@ -1434,7 +1447,7 @@ try { setDistributedTables(tables: Array<string>, callback: AsyncCallback<void>): void -Sets a list of distributed tables. This API uses an asynchronous callback to return the result. +Sets distributed tables. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core @@ -1460,7 +1473,7 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { setDistributedTables(tables: Array<string>): Promise<void> -Sets a list of distributed tables. This API uses a promise to return the result. +Sets distributed tables. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md index 01d064e9a3e12e2bda811a7de953cf15fea6efe7..5f1daa3d0ca5b492e4c5c9b8ce057f3b46966451 100644 --- a/en/application-dev/reference/apis/js-apis-data-storage.md +++ b/en/application-dev/reference/apis/js-apis-data-storage.md @@ -3,10 +3,13 @@ Lightweight storage provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. -> **NOTE** +> **NOTE**
> -> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. - +> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> - The APIs of this module are no longer maintained since API Version 9. You are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). +> +> - The APIs of this module can be used only in the FA model. ## Modules to Import @@ -35,15 +38,15 @@ Reads the specified file and loads its data to the **Storage** instance for data **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------ | -| path | string | Yes | Path of the target file. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| **Return value** -| Type | Description | -| ------------------- | ------------------------------------------------------ | -| [Storage](#storage) | **Storage** instance used for data storage operations. | +| Type | Description | +| ------------------- | ------------------------------------------------- | +| [Storage](#storage) | **Storage** instance used for data storage operations.| **Example** @@ -53,13 +56,13 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -let storage = data_storage.getStorageSync(path + '/mystore'); -storage.putSync('startup', 'auto'); -storage.flushSync(); + let storage = data_storage.getStorageSync(path + '/mystore'); + storage.putSync('startup', 'auto'); + storage.flushSync(); +}); ``` @@ -73,10 +76,10 @@ Reads the specified file and loads its data to the **Storage** instance for data **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------------------- | --------- | --------------------------------------------- | -| path | string | Yes | Path of the target file. | -| callback | AsyncCallback<[Storage](#storage)> | Yes | Callback used to return the execution result. | +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| +| callback | AsyncCallback<[Storage](#storage)> | Yes | Callback used to return the execution result. | **Example** @@ -86,18 +89,18 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -data_storage.getStorage(path + '/mystore', function (err, storage) { + data_storage.getStorage(path + '/mystore', function (err, storage) { if (err) { - console.info("Failed to get the storage. path: " + path + '/mystore'); - return; + console.info("Failed to get the storage. path: " + path + '/mystore'); + return; } storage.putSync('startup', 'auto'); storage.flushSync(); -}) + }) +}); ``` @@ -111,15 +114,15 @@ Reads the specified file and loads its data to the **Storage** instance for data **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------ | -| path | string | Yes | Path of the target file. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| **Return value** -| Type | Description | -| ---------------------------------- | ---------------------------------- | -| Promise<[Storage](#storage)> | Promise used to return the result. | +| Type | Description | +| ---------------------------------- | ------------------------------- | +| Promise<[Storage](#storage)> | Promise used to return the result.| **Example** @@ -129,17 +132,17 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -let getPromise = data_storage.getStorage(path + '/mystore'); -getPromise.then((storage) => { + let getPromise = data_storage.getStorage(path + '/mystore'); + getPromise.then((storage) => { storage.putSync('startup', 'auto'); storage.flushSync(); -}).catch((err) => { + }).catch((err) => { console.info("Failed to get the storage. path: " + path + '/mystore'); -}) + }) +}); ``` @@ -153,9 +156,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------ | -| path | string | Yes | Path of the target file. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| **Example** @@ -167,12 +170,11 @@ var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { path = filePath; console.info("======================>getFilesDirPromise====================>"); -}); -data_storage.deleteStorageSync(path + '/mystore'); + data_storage.deleteStorageSync(path + '/mystore'); +}); ``` - ## data_storage.deleteStorage deleteStorage(path: string, callback: AsyncCallback<void>): void @@ -183,9 +185,9 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | --------- | ------------------------------- | -| path | string | Yes | Path of the target file. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -196,17 +198,17 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -data_storage.deleteStorage(path + '/mystore', function (err) { + data_storage.deleteStorage(path + '/mystore', function (err) { if (err) { - console.info("Failed to delete the storage with err: " + err); - return; + console.info("Failed to delete the storage with err: " + err); + return; } console.info("Succeeded in deleting the storage."); -}) + }) +}); ``` @@ -220,13 +222,14 @@ Deletes the singleton **Storage** instance of a file from the memory, and delete **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------ | -| path | string | Yes | Path of the target file. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| **Return value** -| Type | Description | -| ------------------- | ------------------------------ | + +| Type | Description | +| ------------------- | ------------------------------- | | Promise<void> | Promise that returns no value. | **Example** @@ -237,16 +240,16 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -let promisedelSt = data_storage.deleteStorage(path + '/mystore'); -promisedelSt.then(() => { + let promisedelSt = data_storage.deleteStorage(path + '/mystore'); + promisedelSt.then(() => { console.info("Succeeded in deleting the storage."); -}).catch((err) => { + }).catch((err) => { console.info("Failed to delete the storage with err: " + err); -}) + }) +}); ``` @@ -259,10 +262,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Parameters** - -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------ | -| path | string | Yes | Path of the target file. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| **Example** @@ -274,9 +276,9 @@ var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { path = filePath; console.info("======================>getFilesDirPromise====================>"); + + data_storage.removeStorageFromCacheSync(path + '/mystore'); }); - -data_storage.removeStorageFromCacheSync(path + '/mystore'); ``` @@ -290,9 +292,9 @@ Removes the singleton **Storage** instance of a file from the cache. The removed **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | --------- | ------------------------------- | -| path | string | Yes | Path of the target file. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -303,17 +305,17 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -data_storage.removeStorageFromCache(path + '/mystore', function (err) { + data_storage.removeStorageFromCache(path + '/mystore', function (err) { if (err) { - console.info("Failed to remove storage from cache with err: " + err); - return; + console.info("Failed to remove storage from cache with err: " + err); + return; } console.info("Succeeded in removing storage from cache."); -}) + }) +}); ``` @@ -327,14 +329,14 @@ Removes the singleton **Storage** instance of a file from the cache. The removed **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------ | -| path | string | Yes | Path of the target file. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Path of the target file.| **Return value** -| Type | Description | -| ------------------- | ------------------------------ | +| Type | Description | +| ------------------- | ------------------------------- | | Promise<void> | Promise that returns no value. | **Example** @@ -345,24 +347,22 @@ import featureAbility from '@ohos.ability.featureAbility'; var path; var context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { - path = filePath; - console.info("======================>getFilesDirPromise====================>"); -}); + path = filePath; + console.info("======================>getFilesDirPromise====================>"); -let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore') -promiserevSt.then(() => { + let promiserevSt = data_storage.removeStorageFromCache(path + '/mystore') + promiserevSt.then(() => { console.info("Succeeded in removing storage from cache."); -}).catch((err) => { + }).catch((err) => { console.info("Failed to remove storage from cache with err: " + err); -}) + }) +}); ``` - ## Storage Provides APIs for obtaining and modifying storage data. - ### getSync getSync(key: string, defValue: ValueType): ValueType @@ -373,16 +373,16 @@ Obtains the value corresponding to a key. If the value is null or not in the def **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ----------------------- | --------- | ------------------------------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | -| defValue | [ValueType](#valuetype) | Yes | Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ------------------------------------------------------------ | +| key | string | Yes | Key of the data. It cannot be empty. | +| defValue | [ValueType](#valuetype) | Yes | Default value to be returned if the value of the specified key does not exist. It can be a number, string, or Boolean value.| **Return value** -| Type | Description | -| --------- | ------------------------------------------------------------ | -| ValueType | Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned. | +| Type | Description | +| --------- | -------------------------------------------------------- | +| ValueType | Value corresponding to the specified key. If the value is null or not in the default value format, the default value is returned.| **Example** @@ -402,11 +402,11 @@ Obtains the value corresponding to a key. If the value is null or not in the def **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------------ | --------- | ------------------------------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | -| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value. | -| callback | AsyncCallback<ValueType> | Yes | Callback used to return the execution result. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------ | ---- | ----------------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty. | +| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value.| +| callback | AsyncCallback<ValueType> | Yes | Callback used to return the execution result. | **Example** @@ -431,18 +431,19 @@ Obtains the value corresponding to a key. If the value is null or not in the def **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ----------------------- | --------- | ------------------------------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | -| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value. | +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | ----------------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty. | +| defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value.| **Return value** -| Type | Description | -| ------------------------ | ---------------------------------- | -| Promise<ValueType> | Promise used to return the result. | +| Type | Description | +| ------------------------ | ------------------------------- | +| Promise<ValueType> | Promise used to return the result.| **Example** + ```js let promiseget = storage.get('startup', 'default'); promiseget.then((value) => { @@ -463,15 +464,15 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ----------------------- | --------- | ------------------------------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | -| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value. | +| Name| Type | Mandatory| Description | +| ------ | ----------------------- | ---- | ----------------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty. | +| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.| **Example** ```js -storage.putSync('startup', 'auto') +storage.putSync('startup', 'auto'); ``` @@ -485,10 +486,10 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | --------- | ------------------------------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | -| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ----------------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty. | +| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.| | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -514,18 +515,19 @@ Obtains the **Storage** instance corresponding to the specified file, writes dat **Parameters** -| Name | Type | Mandatory | Description | -| ----- | ----------------------- | --------- | ------------------------------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | -| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value. | +| Name| Type | Mandatory| Description | +| ------ | ----------------------- | ---- | ----------------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty. | +| value | [ValueType](#valuetype) | Yes | New value to store. It can be a number, string, or Boolean value.| **Return value** -| Type | Description | -| ------------------- | ------------------------------ | +| Type | Description | +| ------------------- | --------------------------- | | Promise<void> | Promise that returns no value. | **Example** + ```js let promiseput = storage.put('startup', 'auto'); promiseput.then(() => { @@ -546,15 +548,15 @@ Checks whether the storage object contains data with a given key. **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty.| **Return value** -| Type | Description | -| ------- | ------------------------------------------------------------ | -| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise. | +| Type | Description | +| ------- | ------------------------------------- | +| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.| **Example** @@ -576,16 +578,16 @@ Checks whether the storage object contains data with a given key. This API uses **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ---------------------------- | --------- | --------------------------------------------- | -| key | string | Yes | Key of the data. It cannot be empty. | -| callback | AsyncCallback<boolean> | Yes | Callback used to return the execution result. | +| Name | Type | Mandatory| Description | +| -------- | ---------------------------- | ---- | ------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty.| +| callback | AsyncCallback<boolean> | Yes | Callback used to return the execution result. | **Return value** -| Type | Description | -| ------- | ------------------------------------------------------------ | -| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise. | +| Type | Description | +| ------- | ------------------------------- | +| boolean | Returns **true** if the storage object contains data with the specified key; returns **false** otherwise.| **Example** @@ -612,15 +614,15 @@ Checks whether the storage object contains data with a given key. This API uses **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty.| **Return value** -| Type | Description | -| ---------------------- | ---------------------------------- | -| Promise<boolean> | Promise used to return the result. | +| Type | Description | +| ---------------------- | --------------------------- | +| Promise<boolean> | Promise used to return the result.| **Example** @@ -646,14 +648,14 @@ Deletes data with the specified key from this storage object. **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | --------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty.| **Example** ```js -storage.deleteSync('startup') + storage.deleteSync('startup'); ``` @@ -667,9 +669,9 @@ Deletes data with the specified key from this storage object. This API uses an a **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | --------- | ------------------------------------ | -| key | string | Yes | Key of the data. It cannot be empty. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------- | +| key | string | Yes | Key of the data. It cannot be empty.| | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -695,14 +697,14 @@ Deletes data with the specified key from this storage object. This API uses a pr **Parameters** -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ---------------- | -| key | string | Yes | Key of the data. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | --------------------- | +| key | string | Yes | Key of the data.| **Return value** -| Type | Description | -| ------------------- | ------------------------------ | +| Type | Description | +| ------------------- | --------------------------- | | Promise<void> | Promise that returns no value. | **Example** @@ -728,7 +730,7 @@ Saves the modification of this object to the **Storage** instance and synchroniz **Example** ```js -storage.flushSync() +storage.flushSync(); ``` @@ -742,8 +744,8 @@ Saves the modification of this object to the **Storage** instance and synchroniz **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | --------- | ------------------------------- | +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -769,8 +771,8 @@ Saves the modification of this object to the **Storage** instance and synchroniz **Return value** -| Type | Description | -| ------------------- | ------------------------------ | +| Type | Description | +| ------------------- | --------------------------- | | Promise<void> | Promise that returns no value. | **Example** @@ -796,7 +798,7 @@ Clears this **Storage** object. **Example** ```js -storage.clearSync() +storage.clearSync(); ``` @@ -810,8 +812,8 @@ Clears this **Storage** object. This API uses an asynchronous callback to return **Parameters** -| Name | Type | Mandatory | Description | -| -------- | ------------------------- | --------- | ------------------------------- | +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<void> | Yes | Callback that returns no value. | **Example** @@ -836,9 +838,8 @@ Clears this **Storage** object. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core **Return value** - -| Type | Description | -| ------------------- | ------------------------------ | +| Type | Description | +| ------------------- | --------------------------- | | Promise<void> | Promise that returns no value. | **Example** @@ -863,10 +864,10 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe **Parameters** -| Name | Type | Description | -| -------- | --------------------------------------------------- | ------------------------------------------------------------ | -| type | string | Event type. The value **change** indicates data change events. | -| callback | Callback<[StorageObserver](#storageobserver)> | Callback used to return data changes. | +| Name | Type | Description | +| -------- | --------------------------------------------------- | ---------------------------------------- | +| type | string | Event type. The value **change** indicates data change events.| +| callback | Callback<[StorageObserver](#storageobserver)> | Callback used to return data changes. | **Example** @@ -890,10 +891,10 @@ Unsubscribes from data changes. **Parameters** -| Name | Type | Description | -| -------- | --------------------------------------------------- | ------------------------------------------------------------ | -| type | string | Event type. The value **change** indicates data change events. | -| callback | Callback<[StorageObserver](#storageobserver)> | Callback used to return data changes. | +| Name | Type | Description | +| -------- | --------------------------------------------------- | ---------------------------------------- | +| type | string | Event type. The value **change** indicates data change events.| +| callback | Callback<[StorageObserver](#storageobserver)> | Callback used to return data changes. | **Example** @@ -909,9 +910,9 @@ storage.off('change', observer); **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -| Name | Type | Mandatory | Description | -| ---- | ------ | --------- | ------------- | -| key | string | No | Data changed. | +| Name| Type| Mandatory| Description | +| ---- | -------- | ---- | ---------------- | +| key | string | No | Data changed.| ## ValueType @@ -919,8 +920,8 @@ Enumerates the value types. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -| Type | Description | -| ------- | ----------------------------- | -| number | The value is a number. | -| string | The value is a string. | -| boolean | The value is of Boolean type. | \ No newline at end of file +| Type | Description | +| ------- | -------------------- | +| number | The value is a number. | +| string | The value is a string. | +| boolean | The value is of Boolean type.| diff --git a/en/application-dev/reference/apis/js-apis-distributed-data.md b/en/application-dev/reference/apis/js-apis-distributed-data.md index 60ce09a55ff47f880dbd530a9fa901deaec63f69..7b98b6e068f9270d68c4f202e2bff753ad6109bb 100644 --- a/en/application-dev/reference/apis/js-apis-distributed-data.md +++ b/en/application-dev/reference/apis/js-apis-distributed-data.md @@ -250,7 +250,7 @@ Closes a KV store. This API uses an asynchronous callback to return the result. | appId | string | Yes | Bundle name of the app that invokes the KV store. | | storeId | string | Yes | Unique identifier of the KV store to close. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| | kvStore | [KVStore](#kvstore) | Yes | KV store to close. | -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| **Example** @@ -348,7 +348,7 @@ Deletes a KV store. This API uses an asynchronous callback to return the result. | ----- | ------ | ---- | ----------------------- | | appId | string | Yes | Bundle name of the app that invokes the KV store. | | storeId | string | Yes | Unique identifier of the KV store to delete. The length cannot exceed [MAX_STORE_ID_LENGTH](#constants).| -| callback | AsyncCallback<void> | Yes | Callback used to return the result.| +| callback | AsyncCallback<void> | Yes | Callback invoked to return the result.| **Example** @@ -444,7 +444,7 @@ Obtains the IDs of all KV stores that are created by [getKVStore()](#getkvstore) | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | appId | string | Yes | Bundle name of the app that invokes the KV store. | -| callback | AsyncCallback<string[]> | Yes |Callback used to return the KV store IDs obtained. | +| callback | AsyncCallback<string[]> | Yes |Callback invoked to return the KV store IDs obtained. | **Example** @@ -513,7 +513,7 @@ Subscribes to service status changes. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates a service status change event.| -| deathCallback | Callback<void> | Yes | Callback used to return a service status change event.| +| deathCallback | Callback<void> | Yes | Callback invoked to return a service status change event.| **Example** @@ -596,16 +596,15 @@ Enumerates the KV store types. Enumerates the KV store security levels. -**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | Name | Value| Description | | --- | ---- | ----------------------- | -| NO_LEVEL | 0 | No security level is set for the KV store. | -| S0 | 1 | The KV store security level is public.| -| S1 | 2 | The KV store security level is low. If data leakage occurs, minor impact will be caused on the database. For example, a KV store that contains system data such as wallpapers.| -| S2 | 3 | The KV store security level is medium. If data leakage occurs, moderate impact will be caused on the database. For example, a KV store that contains information created by users or call records, such as audio or video clips.| -| S3 | 5 | The KV store security level is high. If data leakage occurs, major impact will be caused on the database. For example, a KV store that contains information such as user fitness, health, and location data.| -| S4 | 6 | The KV store security level is critical. If data leakage occurs, severe impact will be caused on the database. For example, a KV store that contains information such as authentication credentials and financial data.| +| NO_LEVEL | 0 | No security level is set for the KV store.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore | +| S0 | 1 | The KV store security level is public.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| S1 | 2 | The KV store security level is low. If data leakage occurs, minor impact will be caused on the database. For example, a KV store that contains system data such as wallpapers.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| S2 | 3 | The KV store security level is medium. If data leakage occurs, moderate impact will be caused on the database. For example, a KV store that contains information created by users or call records, such as audio or video clips.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| S3 | 5 | The KV store security level is high. If data leakage occurs, major impact will be caused on the database. For example, a KV store that contains information such as user fitness, health, and location data.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | +| S4 | 6 | The KV store security level is critical. If data leakage occurs, severe impact will be caused on the database. For example, a KV store that contains information such as authentication credentials and financial data.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core | ## Constants @@ -2086,7 +2085,7 @@ Adds a KV pair of the specified type to this KV store. This API uses an asynchro | ----- | ------ | ---- | ----------------------- | | key | string | Yes |Key of the KV pair to add. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). | | value | Uint8Array \| string \| number \| boolean | Yes |Value of the KV pair to add. The value type can be Uint8Array, number, string, or boolean. A value of the Uint8Array or string type cannot exceed [MAX_VALUE_LENGTH](#constants). | -| callback | AsyncCallback<void> | Yes |Callback used to return the result. | +| callback | AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2159,7 +2158,7 @@ Deletes a KV pair from this KV store. This API uses an asynchronous callback to | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | key | string | Yes |Key of the KV pair to delete. It cannot be empty, and the length cannot exceed [MAX_KEY_LENGTH](#constants). | -| callback | AsyncCallback<void> | Yes |Callback used to return the result. | +| callback | AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2242,7 +2241,7 @@ Subscribes to data changes of the specified type. | ----- | ------ | ---- | ----------------------- | | event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. | | type |[SubscribeType](#subscribetype) | Yes |Type of data change. | -| observer |Callback<[ChangeNotification](#changenotification)> | Yes |Callback used to return a data change event.| +| observer |Callback<[ChangeNotification](#changenotification)> | Yes |Callback invoked to return a data change event.| **Example** @@ -2267,7 +2266,7 @@ Subscribes to synchronization complete events. | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event. | -| syncCallback |Callback<Array<[string, number]>> | Yes |Callback used to return a synchronization complete event. | +| syncCallback |Callback<Array<[string, number]>> | Yes |Callback invoked to return a synchronization complete event. | **Example** @@ -2328,7 +2327,7 @@ Inserts KV pairs in batches to this KV store. This API uses an asynchronous call | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | entries |[Entry](#entry)[] | Yes |KV pairs to insert in batches. | -| callback |Asyncallback<void> |Yes |Callback used to return the result.| +| callback |Asyncallback<void> |Yes |Callback invoked to return the result.| **Example** @@ -2430,7 +2429,7 @@ Deletes KV pairs in batches from this KV store. This API uses an asynchronous ca | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | keys |string[] | Yes |KV pairs to delete in batches. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2532,7 +2531,7 @@ Starts the transaction in this KV store. This API uses an asynchronous callback | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2619,7 +2618,7 @@ Commits the transaction in this KV store. This API uses an asynchronous callback | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2681,7 +2680,7 @@ Rolls back the transaction in this KV store. This API uses an asynchronous callb | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2744,7 +2743,7 @@ Sets data synchronization, which can be enabled or disabled. This API uses an as | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | enabled |boolean | Yes |Whether to enable data synchronization. The value **true** means to enable data synchronization, and **false** means the opposite. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -2814,7 +2813,7 @@ Sets the data synchronization range. This API uses an asynchronous callback to r | ----- | ------ | ---- | ----------------------- | | localLabels |string[] | Yes |Synchronization labels set for the local device. | | remoteSupportLabels |string[] | Yes |Synchronization labels set for remote devices. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -3141,7 +3140,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses an | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | query |[Query](#query8) | Yes |Key prefix to match. | -| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback used to return the KV pairs obtained. | +| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback invoked to return the KV pairs obtained. | **Example** @@ -3463,7 +3462,7 @@ Closes the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet]( | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | resultSet |[KvStoreResultSet](#kvstoreresultset8) | Yes |**KvStoreResultSet** object to close. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -3635,7 +3634,7 @@ Deletes data of a device. This API uses an asynchronous callback to return the r | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -3824,7 +3823,7 @@ Sets the default delay allowed for KV store synchronization. This API uses an as | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | defaultAllowedDelayMs |number | Yes |Default delay allowed for database synchronization, in ms. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -3961,7 +3960,7 @@ Obtains a string value that matches the specified device ID and key. This API us | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | | key |string | Yes |Key to match. | -| callback |AsyncCallback<boolean\|string\|number\|Uint8Array> | Yes |Callback used to return the value obtained. | +| callback |AsyncCallback<boolean\|string\|number\|Uint8Array> | Yes |Callback invoked to return the value obtained. | **Example** @@ -4040,7 +4039,7 @@ Obtains all KV pairs that match the specified device ID and key prefix. This API | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | | keyPrefix |string | Yes |Key prefix to match. | -| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback used to return the KV pairs obtained. | +| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback invoked to return the KV pairs obtained. | **Example** @@ -4146,7 +4145,7 @@ Obtains the KV pairs that match the specified **Query** object. This API uses an | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | query |[Query](#query8) | Yes |**Query** object to match. | -| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback used to return the KV pairs obtained. | +| callback |AsyncCallback<[Entry](#entry)[]> | Yes |Callback invoked to return the KV pairs obtained. | **Example** @@ -4682,7 +4681,7 @@ Closes the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet]( | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | resultSet |[KvStoreResultSet](#getresultset8) | Yes |**KvStoreResultSet** object to close. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** @@ -4961,7 +4960,7 @@ Deletes data of the specified device from this KV store. This API uses an asynch | Name | Type| Mandatory | Description | | ----- | ------ | ---- | ----------------------- | | deviceId |string | Yes |ID of the target device. | -| callback |AsyncCallback<void> | Yes |Callback used to return the result. | +| callback |AsyncCallback<void> | Yes |Callback invoked to return the result. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-pasteboard.md b/en/application-dev/reference/apis/js-apis-pasteboard.md index cf7fbb1caa02a7c9c8f6b434a227a3275574fa6c..15a9b3d0541776f618afdf0d836cdc6d64e09647 100644 --- a/en/application-dev/reference/apis/js-apis-pasteboard.md +++ b/en/application-dev/reference/apis/js-apis-pasteboard.md @@ -1,147 +1,145 @@ # Pasteboard +The **pasteboard** module provides the copy and paste support for the system pasteboard. You can use the APIs of this module to operate pasteboard content of the plain text, HTML, URI, Want, pixel map, and other types. -> **NOTE**
The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> - +> **NOTE** +> +> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import - -``` +```js import pasteboard from '@ohos.pasteboard'; ``` - ## Attributes **System capability**: SystemCapability.MiscServices.Pasteboard -| Name | Type | Readable | Writable | Description | +| Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| MAX_RECORD_NUM7+ | number | Yes | No | Maximum number of records allowed in a **PasteData** object. | -| MIMETYPE_TEXT_HTML7+ | string | Yes | No | MIME type of the HTML text. | -| MIMETYPE_TEXT_WANT7+ | string | Yes | No | MIME type of the Want text. | -| MIMETYPE_TEXT_PLAIN7+ | string | Yes | No | MIME type of the plain text. | -| MIMETYPE_TEXT_URI7+ | string | Yes | No | MIME type of the URI text. | +| MAX_RECORD_NUM7+ | number | Yes| No| Maximum number of records in a **PasteData** object.| +| MIMETYPE_TEXT_HTML7+ | string | Yes| No| MIME type of the HTML content.| +| MIMETYPE_TEXT_WANT7+ | string | Yes| No| MIME type of the Want content.| +| MIMETYPE_TEXT_PLAIN7+ | string | Yes| No| MIME type of the plain text content.| +| MIMETYPE_TEXT_URI7+ | string | Yes| No| MIME type of the URI content.| ## pasteboard.createPlainTextData -createPlainTextData(text:string): PasteData +createPlainTextData(text: string): PasteData -Creates a **PasteData** object for plain text. +Creates a **PasteData** object of the plain text type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| text | string | Yes | Plain text. | +| text | string | Yes| Plain text.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteData](#pastedata) | **PasteData** object with the specified content. | +| [PasteData](#pastedata) | **PasteData** object.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("content"); - ``` +```js +var pasteData = pasteboard.createPlainTextData("content"); +``` ## pasteboard.createHtmlData7+ -createHtmlData(htmlText:string): PasteData +createHtmlData(htmlText: string): PasteData -Creates a **PasteData** object for HTML text. +Creates a **PasteData** object of the HTML type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| htmlText | string | Yes | HTML text. | +| htmlText | string | Yes| HTML content.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteData](#pastedata) | **PasteData** object with the specified content. | +| [PasteData](#pastedata) | **PasteData** object.| **Example** - ```js - var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; - var pasteData = pasteboard.createHtmlData(html); - ``` +```js +var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; +var pasteData = pasteboard.createHtmlData(html); +``` ## pasteboard.createWantData7+ -createWantData(want:Want): PasteData +createWantData(want: Want): PasteData -Creates a **PasteData** object for Want text. +Creates a **PasteData** object of the Want type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| want | [Want](js-apis-application-Want.md) | Yes | Want text. | +| want | [Want](js-apis-featureAbility.md#want) | Yes| Want content.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteData](#pastedata) | **PasteData** object with the specified content. | +| [PasteData](#pastedata) | **PasteData** object.| **Example** - ```js - var object = { - bundleName: "com.example.aafwk.test", - abilityName: "com.example.aafwk.test.TwoAbility" - }; - var pasteData = pasteboard.createWantData(object); - ``` +```js +var object = { + bundleName: "com.example.aafwk.test", + abilityName: "com.example.aafwk.test.TwoAbility" +}; +var pasteData = pasteboard.createWantData(object); +``` ## pasteboard.createUriData7+ -createUriData(uri:string): PasteData +createUriData(uri: string): PasteData -Creates a **PasteData** object for URI text. +Creates a **PasteData** object of the URI type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uri | string | Yes | URI text. | +| uri | string | Yes| URI content.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteData](#pastedata) | **PasteData** object with the specified content. | +| [PasteData](#pastedata) | **PasteData** object.| **Example** - ```js - var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); - ``` - +```js +var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt"); +``` ## pasteboard.createPlainTextRecord7+ -createPlainTextRecord(text:string): PasteDataRecord +createPlainTextRecord(text: string): PasteDataRecord Creates a **PasteDataRecord** object of the plain text type. @@ -149,26 +147,26 @@ Creates a **PasteDataRecord** object of the plain text type. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| text | string | Yes | Plain text. | +| text | string | Yes| Plain text.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteDataRecord](#pastedatarecord7) | New plain text record. | +| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the plain text type.| **Example** - ```js - var record = pasteboard.createPlainTextRecord("hello"); - ``` +```js +var record = pasteboard.createPlainTextRecord("hello"); +``` ## pasteboard.createHtmlTextRecord7+ -createHtmlTextRecord(htmlText:string): PasteDataRecord +createHtmlTextRecord(htmlText: string): PasteDataRecord Creates a **PasteDataRecord** object of the HTML text type. @@ -176,80 +174,100 @@ Creates a **PasteDataRecord** object of the HTML text type. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| htmlText | string | Yes | HTML text. | +| htmlText | string | Yes| HTML content.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteDataRecord](#pastedatarecord7) | New HTML record. | +| [PasteDataRecord](#pastedatarecord7) | **PasteDataRecord** object of the HTML text type.| **Example** - ```js - var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; - var record = pasteboard.createHtmlTextRecord(html); - ``` +```js +var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; +var record = pasteboard.createHtmlTextRecord(html); +``` ## pasteboard.createWantRecord7+ -createWantRecord(want:Want): PasteDataRecord +createWantRecord(want: Want): PasteDataRecord -Creates a **PasteDataRecord** object of the Want text type. +Creates a **PasteDataRecord** object of the Want type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| want | [Want](js-apis-application-Want.md) | Yes | Want text. | +| want | [Want](js-apis-featureAbility.md#want) | Yes| Want content.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteDataRecord](#pastedatarecord7) | New Want record. | +| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the Want type.| **Example** - ```js - var object = { - bundleName: "com.example.aafwk.test", - abilityName: "com.example.aafwk.test.TwoAbility" - }; - var record = pasteboard.createWantRecord(object); - ``` +```js +var object = { + bundleName: "com.example.aafwk.test", + abilityName: "com.example.aafwk.test.TwoAbility" +}; +var record = pasteboard.createWantRecord(object); +``` ## pasteboard.createUriRecord7+ -createUriRecord(uri:string): PasteDataRecord +createUriRecord(uri: string): PasteDataRecord -Creates a **PasteDataRecord** object of the URI text type. +Creates a **PasteDataRecord** object of the URI type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uri | string | Yes | URI text. | +| uri | string | Yes| URI content.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteDataRecord](#pastedatarecord7) | New URI record. | +| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the URI type.| **Example** - ```js - var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); - ``` +```js +var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt"); +``` + +## pasteboard.getSystemPasteboard + +getSystemPasteboard(): SystemPasteboard + +Obtains this **SystemPasteboard** object. + +**System capability**: SystemCapability.MiscServices.Pasteboard + +**Return value** + +| Type| Description| +| -------- | -------- | +| [SystemPasteboard](#systempasteboard) | **SystemPasteboard** object.| + +**Example** + +```js +var systemPasteboard = pasteboard.getSystemPasteboard(); +``` ## PasteDataProperty7+ @@ -258,90 +276,92 @@ Defines the properties of all data records on the pasteboard, including the time **System capability**: SystemCapability.MiscServices.Pasteboard -| Name | Type | Readable | Writable | Description | +| Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| additions | {[key: string]: object} | Yes | Yes | Additional property data. | -| mimeTypes | Array<string> | Yes | No | Non-repeating data types of the data records on the pasteboard. | -| tag | string | Yes | Yes | User-defined tag. | -| timestamp | number | Yes | No | Timestamp at which the data is written to the pasteboard, in milliseconds. | -| localOnly | boolean | Yes | Yes | Whether local access only is set for the pasteboard.
- The default value is **true**.
- **true**: The **PasteData** is set for local access only.
- **false**: The **PasteData** can be shared between devices. | +| additions | {[key:string]:object} | Yes| Yes| Additional data.| +| mimeTypes | Array<string> | Yes| No| Non-repeating data types of the data records on the pasteboard.| +| tag | string | Yes| Yes| Custom tag.| +| timestamp | number | Yes| No| Timestamp when data is written to the pasteboard (unit: ms).| +| localOnly | boolean | Yes| Yes| Whether the pasteboard content is set for local access only. The default value is **true**.
- **true**: The pasteboard content is set for local access only.
- **false**: The pasteboard content can be shared between devices.| ## PasteDataRecord7+ -A data record is an abstract definition of the content on the pasteboard. The pasteboard content consists of one or more plain text, HTML, URI, or Want records. +Provides **PasteDataRecord** APIs. A **PasteDataRecord** is an abstract definition of the content on the pasteboard. The pasteboard content consists of one or more plain text, HTML, URI, or Want records. ### Attributes **System capability**: SystemCapability.MiscServices.Pasteboard -| Name | Type | Readable | Writable | Description | +| Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| htmlText7+ | string | Yes | No | HTML text. | -| want7+ | [Want](js-apis-application-Want.md) | Yes | No | Want text. | -| mimeType7+ | string | Yes | No | Data type. | -| plainText7+ | string | Yes | No | Plain text. | -| uri7+ | string | Yes | No | URI text. | +| htmlText7+ | string | Yes| No| HTML content.| +| want7+ | [Want](js-apis-featureAbility.md#want) | Yes| No| Want content.| +| mimeType7+ | string | Yes| No| Data type.| +| plainText7+ | string | Yes| No| Plain text.| +| uri7+ | string | Yes| No| URI content.| ### convertToText7+ convertToText(): Promise<string> -Forcibly converts the content in this **PasteData** object to the plain text. This API uses a promise to return the result. +Forcibly converts the content in a **PasteData** object to text. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| Promise<void> | Promise used to return the result. If the operation is successful, the plain text content after conversion is returned. Otherwise, error information is returned. | +| Promise<string> | Promise used to return the text obtained from the conversion.| **Example** - ```js - var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); - record.convertToText().then((data) => { - console.info('convertToText success data : ' + JSON.stringify(data)); - }).catch((error) => { - console.error('convertToText failed because ' + JSON.stringify(error)); - }); - ``` +```js +var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt"); +record.convertToText().then((data) => { + console.info('Succeeded in converting to text. Data: ' + JSON.stringify(data)); +}).catch((err) => { + console.error('Failed to convert to text. Cause: ' + JSON.stringify(err)); +}); +``` ### convertToText7+ convertToText(callback: AsyncCallback<string>): void -Forcibly converts the content in this **PasteData** object to the plain text. This API uses an asynchronous callback to return the result. +Forcibly converts the content in a **PasteData** object to text. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<string> | Yes | Callback used to return the result. If this callback is successful, the plain text content after conversion is returned. Otherwise, error information is returned. | +| callback | AsyncCallback<string> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the text obtained from the conversion. Otherwise, **err** is error information.| **Example** - ```js - var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); - record.convertToText((err, data) => { - if (err) { - console.error('convertToText failed because ' + JSON.stringify(err)); - return; - } - console.info('convertToText success data : ' + JSON.stringify(data)); - }); - ``` +```js +var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt"); +record.convertToText((err, data) => { + if (err) { + console.error('Failed to convert to text. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in converting to text. Data: ' + JSON.stringify(data)); +}); +``` ## PasteData -Before calling any **PasteData** method, you must obtain a **PasteData** object. +Provides **PasteData** APIs. + +Before calling any **PasteData** API, you must obtain a **PasteData** object. **System capability**: SystemCapability.MiscServices.Pasteboard @@ -354,93 +374,92 @@ getPrimaryText(): string Obtains the plain text of the primary record. - **System capability**: SystemCapability.MiscServices.Pasteboard -**Return value** +**Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| string | Plain text. | +| string | Plain text.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var plainText = pasteData.getPrimaryText(); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var plainText = pasteData.getPrimaryText(); +``` ### getPrimaryHtml7+ getPrimaryHtml(): string -Obtains the HTML text of the primary record. +Obtains the HTML content of the primary record. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| string | HTML text. | +| string | HTML content.| **Example** - ```js - var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; - var pasteData = pasteboard.createHtmlData(html); - var htmlText = pasteData.getPrimaryHtml(); - ``` +```js +var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; +var pasteData = pasteboard.createHtmlData(html); +var htmlText = pasteData.getPrimaryHtml(); +``` ### getPrimaryWant7+ getPrimaryWant(): Want -Obtains the **Want** object of the primary record. +Obtains the Want object of the primary record. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [Want](js-apis-application-Want.md) | Want object. | +| [Want](js-apis-featureAbility.md#want) | Want object.| **Example** - ```js - var object = { - bundleName: "com.example.aafwk.test", - abilityName: "com.example.aafwk.test.TwoAbility" - }; - var pasteData = pasteboard.createWantData(object); - var want = pasteData.getPrimaryWant(); - ``` +```js +var object = { + bundleName: "com.example.aafwk.test", + abilityName: "com.example.aafwk.test.TwoAbility" +}; +var pasteData = pasteboard.createWantData(object); +var want = pasteData.getPrimaryWant(); +``` ### getPrimaryUri7+ getPrimaryUri(): string -Obtains the URI text of the primary record. +Obtains the URI of the primary record. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| string | URI text. | +| string | URI content.| **Example** - ```js - var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); - var uri = pasteData.getPrimaryUri(); - ``` +```js +var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt"); +var uri = pasteData.getPrimaryUri(); +``` ### addTextRecord7+ @@ -455,9 +474,9 @@ The pasteboard supports a maximum number of 128 data records. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| text | string | Yes | Plain text. | +| text | string | Yes| Plain text.| **Example** @@ -471,7 +490,7 @@ pasteData.addTextRecord("good"); addHtmlRecord(htmlText: string): void -Adds an HTML text record to this pasteboard, and adds **MIMETYPE_TEXT_HTML** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. +Adds an HTML record to this pasteboard, and adds **MIMETYPE_TEXT_HTML** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. The pasteboard supports a maximum number of 128 data records. @@ -479,24 +498,24 @@ The pasteboard supports a maximum number of 128 data records. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| htmlText | string | Yes | HTML text. | +| htmlText | string | Yes| HTML content.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; - pasteData.addHtmlRecord(html); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; +pasteData.addHtmlRecord(html); +``` ### addWantRecord7+ addWantRecord(want: Want): void -Adds a Want text record to this pasteboard, and adds **MIMETYPE_TEXT_WANT** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. +Adds a Want record to this pasteboard, and adds **MIMETYPE_TEXT_WANT** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. The pasteboard supports a maximum number of 128 data records. @@ -504,27 +523,27 @@ The pasteboard supports a maximum number of 128 data records. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| want | [Want](js-apis-application-Want.md) | Yes | Want object. | +| want | [Want](js-apis-featureAbility.md#want) | Yes| Want object.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var object = { - bundleName: "com.example.aafwk.test", - abilityName: "com.example.aafwk.test.TwoAbility" - }; - pasteData.addWantRecord(object); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var object = { + bundleName: "com.example.aafwk.test", + abilityName: "com.example.aafwk.test.TwoAbility" +}; +pasteData.addWantRecord(object); +``` ### addUriRecord7+ addUriRecord(uri: string): void -Adds a URI text record to this pasteboard, and adds **MIMETYPE_TEXT_URI** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. +Adds a URI record to this pasteboard, and adds **MIMETYPE_TEXT_URI** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails. The pasteboard supports a maximum number of 128 data records. @@ -532,16 +551,16 @@ The pasteboard supports a maximum number of 128 data records. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| uri | string | Yes | URI text. | +| uri | string | Yes| URI content.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - pasteData.addUriRecord("dataability:///com.example.myapplication1?user.txt"); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +pasteData.addUriRecord("dataability:///com.example.myapplication1/user.txt"); +``` ### addRecord7+ @@ -556,417 +575,396 @@ The pasteboard supports a maximum number of 128 data records. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| record | [PasteDataRecord](#pastedatarecord7) | Yes | Record to add. | +| record | [PasteDataRecord](#pastedatarecord7) | Yes| Record to add.| **Example** - ```js - var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1?user.txt"); - var textRecord = pasteboard.createPlainTextRecord("hello"); - var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; - var htmlRecord = pasteboard.createHtmlTextRecord(html); - pasteData.addRecord(textRecord); - pasteData.addRecord(htmlRecord); - ``` +```js +var pasteData = pasteboard.createUriData("dataability:///com.example.myapplication1/user.txt"); +var textRecord = pasteboard.createPlainTextRecord("hello"); +var html = "\n" + "\n" + "\n" + "\n" + "HTML-PASTEBOARD_HTML\n" + "\n" + "\n" + "

HEAD

\n" + "

\n" + "\n" + ""; +var htmlRecord = pasteboard.createHtmlTextRecord(html); +pasteData.addRecord(textRecord); +pasteData.addRecord(htmlRecord); +``` ### getMimeTypes7+ getMimeTypes(): Array<string> -Obtains **mimeTypes** in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty. +Obtains a list of **mimeTypes** objects in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| Array<string> | List of non-duplicate MIME types. | +| Array<string> | Non-repeating data types of the data records on the pasteboard.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var types = pasteData.getMimeTypes(); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var types = pasteData.getMimeTypes(); +``` ### getPrimaryMimeType7+ getPrimaryMimeType(): string -Obtains the data type of the primary record. +Obtains the data type of the primary record in this pasteboard. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| string | Data type of the primary record. | +| string | Data type of the primary record.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var type = pasteData.getPrimaryMimeType(); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var type = pasteData.getPrimaryMimeType(); +``` ### getProperty7+ getProperty(): PasteDataProperty -Obtains the property description object. +Obtains the property of the pasteboard data. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteDataProperty](#pastedataproperty7) | Property description object. | +| [PasteDataProperty](#pastedataproperty7) | Property of the pasteboard data.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var property = pasteData.getProperty(); - ``` - +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var property = pasteData.getProperty(); +``` ### getRecordAt7+ getRecordAt(index: number): PasteDataRecord -Obtains the record with the specified index. +Obtains the specified record in the pasteboard. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| index | number | Yes | Index of the specified record. | +| index | number | Yes| Index of the target record.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| [PasteDataRecord](#pastedatarecord7) | Record with the specified index. | +| [PasteDataRecord](#pastedatarecord7) | Record with the specified index.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var record = pasteData.getRecordAt(0); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var record = pasteData.getRecordAt(0); +``` ### getRecordCount7+ getRecordCount(): number -Obtains the number of data records in this pasteboard. +Obtains the number of records in the pasteboard. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| number | Number of records. | +| number | Number of records.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var count = pasteData.getRecordCount(); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var count = pasteData.getRecordCount(); +``` ### getTag7+ getTag(): string -Obtains the user-defined tag content. If the tag content is not set, null is returned. +Obtains the custom tag from the pasteboard. If no custom tag is set, null is returned. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| string | User-defined tag content if obtained and null if no tag is set. | +| string | Custom tag. If no custom tag is set, null is returned.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var tag = pasteData.getTag(); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var tag = pasteData.getTag(); +``` ### hasMimeType7+ hasMimeType(mimeType: string): boolean -Checks whether the content of this pasteboard contains the specified data type. +Checks whether the pasteboard contains data of the specified type. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| mimeType | string | Yes | Type of the data to query. | +| mimeType | string | Yes| Type of the data to query.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| boolean | Returns **true** if the specified data type exists; returns **false** otherwise. | +| boolean | Returns **true** if the specified data type exists; returns **false** otherwise.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN); +``` ### removeRecordAt7+ removeRecordAt(index: number): boolean -Removes the data record with a specified index from this pasteboard. +Removes the record with the specified index from the pasteboard. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| index | number | Yes | Specified index. | +| index | number | Yes| Specified index.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| boolean | Returns **true** if the operation is successful; returns **false** otherwise. | +| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var isRemove = pasteData.removeRecordAt(0); - ``` +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var isRemove = pasteData.removeRecordAt(0); +``` ### replaceRecordAt7+ replaceRecordAt(index: number, record: PasteDataRecord): boolean -Replaces the data record with a specified index in this pasteboard. +Replaces the record with the specified index in the pasteboard with a new record. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| index | number | Yes | Specified index. | -| record | [PasteDataRecord](#pastedatarecord7) | Yes | New record. | +| index | number | Yes| Specified index.| +| record | [PasteDataRecord](#pastedatarecord7) | Yes| New record.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| boolean | Returns **true** if the operation is successful; returns **false** otherwise. | +| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("hello"); - var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1?user.txt"); - var isReplace = pasteData.replaceRecordAt(0, record); - ``` - - -## pasteboard.getSystemPasteboard - -getSystemPasteboard(): SystemPasteboard - -Obtains the system pasteboard. - -**System capability**: SystemCapability.MiscServices.Pasteboard - -**Return value** - -| Type | Description | -| -------- | -------- | -| [SystemPasteboard](#systempasteboard) | System pasteboard. | - -**Example** - - ```js - var systemPasteboard = pasteboard.getSystemPasteboard(); - ``` - +```js +var pasteData = pasteboard.createPlainTextData("hello"); +var record = pasteboard.createUriRecord("dataability:///com.example.myapplication1/user.txt"); +var isReplace = pasteData.replaceRecordAt(0, record); +``` ## SystemPasteboard -Before calling any **SystemPasteboard** method, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard). +Provides **SystemPasteboard** APIs. -``` +Before calling any **SystemPasteboard** API, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard). + +```js var systemPasteboard = pasteboard.getSystemPasteboard(); ``` ### setPasteData -setPasteData(data:PasteData, callback:AsyncCallback<void>): void +setPasteData(data: PasteData, callback: AsyncCallback<void>): void -Writes data to a pasteboard. This API uses an asynchronous callback to return the result. +Writes a **PasteData** object to the pasteboard. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| data | [PasteData](#pastedata) | Yes | **PasteData** object. | -| callback | AsyncCallback<void> | Yes | Callback used to return the data write result. | +| data | [PasteData](#pastedata) | Yes| **PasteData** object.| +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("content"); - var systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.setPasteData(pasteData, (error, data) => { - if (error) { - console.error('Failed to setPasteData. Cause: ' + error.message); - return; - } - console.info('setPasteData successfully.'); - }); - ``` +```js +var pasteData = pasteboard.createPlainTextData("content"); +var systemPasteboard = pasteboard.getSystemPasteboard(); +systemPasteboard.setPasteData(pasteData, (err, data) => { + if (err) { + console.error('Failed to set PasteData. Cause: ' + err.message); + return; + } + console.info('Succeeded in setting PasteData.'); +}); +``` ### setPasteData -setPasteData(data:PasteData): Promise<void> +setPasteData(data: PasteData): Promise<void> -Writes data to a pasteboard. This API uses a promise to return the result. +Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Description | +| Name| Type| Description| | -------- | -------- | -------- | -| data | [PasteData](#pastedata) | **PasteData** object. | +| data | [PasteData](#pastedata) | **PasteData** object.| **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| Promise<void> | Promise used to return the data write result. | +| Promise<void> | Promise that returns no value.| **Example** - ```js - var pasteData = pasteboard.createPlainTextData("content"); - var systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.setPasteData(pasteData).then((data) => { - console.info('setPasteData success.'); - }).catch((error) => { - console.error('Failed to setPasteData. Cause: ' + error.message); - }); - ``` +```js +var pasteData = pasteboard.createPlainTextData("content"); +var systemPasteboard = pasteboard.getSystemPasteboard(); +systemPasteboard.setPasteData(pasteData).then((data) => { + console.info('Succeeded in setting PasteData.'); +}).catch((err) => { + console.error('Failed to set PasteData. Cause: ' + err.message); +}); +``` ### getPasteData -getPasteData( callback:AsyncCallback<PasteData>): void +getPasteData( callback: AsyncCallback<PasteData>): void -Reads the system pasteboard content. This API uses an asynchronous callback to return the result. +Obtains a **PasteData** object from the pasteboard. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<[PasteData](#pastedata)> | Yes | Callback used to return the system pasteboard data. | +| callback | AsyncCallback<[PasteData](#pastedata)> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the system pasteboard data. Otherwise, **err** is an error object.| **Example** - ```js - var systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.getPasteData((error, pasteData) => { - if (error) { - console.error('Failed to getPasteData. Cause: ' + error.message); - return; - } - var text = pasteData.getPrimaryText(); - }); - ``` +```js +var systemPasteboard = pasteboard.getSystemPasteboard(); +systemPasteboard.getPasteData((err, pasteData) => { + if (err) { + console.error('Failed to get PasteData. Cause: ' + err.message); + return; + } + var text = pasteData.getPrimaryText(); +}); +``` ### getPasteData getPasteData(): Promise<PasteData> -Reads the system pasteboard content. This API uses a promise to return the result. +Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| Promise<[PasteData](#pastedata)> | Promise used to return the system pasteboard data. | +| Promise<[PasteData](#pastedata)> | Promise used to return the system pasteboard data.| **Example** - ```js - var systemPasteboard = pasteboard.getSystemPasteboard(); - systemPasteboard.getPasteData().then((pasteData) => { - var text = pasteData.getPrimaryText(); - }).catch((error) => { - console.error('Failed to getPasteData. Cause: ' + error.message); - }) - ``` +```js +var systemPasteboard = pasteboard.getSystemPasteboard(); +systemPasteboard.getPasteData().then((pasteData) => { + var text = pasteData.getPrimaryText(); +}).catch((err) => { + console.error('Failed to get PasteData. Cause: ' + err.message); +}) +``` ### on('update')7+ on(type: 'update', callback: () =>void ): void -Subscribes to the content change event of the system pasteboard. If the pasteboard content changes, the callback is triggered. +Subscribes to the content change event of the system pasteboard. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes | Data type. The value **update** indicates the pasteboard content has changed. | -| callback | function | Yes | Callback invoked when the pasteboard content changes. | +| type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.| +| callback | function | Yes| Callback invoked when the pasteboard content changes.| **Example** - ```js - var systemPasteboard = pasteboard.getSystemPasteboard(); - var listener = () => { - console.info('The system pasteboard has changed'); - }; - systemPasteboard.on('update', listener); - ``` +```js +var systemPasteboard = pasteboard.getSystemPasteboard(); +var listener = () => { + console.info('The system pasteboard has changed.'); +}; +systemPasteboard.on('update', listener); +``` ### off('update')7+ @@ -979,120 +977,120 @@ Unsubscribes from the system pasteboard content change event. **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| type | string | Yes | Data type. The value **update** indicates the pasteboard content has changed. | -| callback | function | No | Callback invoked when the pasteboard content changes. | +| type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.| +| callback | function | No| Callback invoked when the pasteboard content changes.| **Example** - ```js - let listener = () => { - console.info('The system pasteboard has changed'); - }; - systemPasteboard.off('update', listener); - ``` +```js +let listener = () => { + console.info('The system pasteboard has changed.'); +}; +systemPasteboard.off('update', listener); +``` ### hasPasteData7+ hasPasteData(callback: AsyncCallback<boolean>): void -Checks whether the system pasteboard contains content. This API uses an asynchronous callback to return the result. +Checks whether the system pasteboard contains data. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<boolean> | Yes | Returns **true** if the pasteboard contains content; returns **false** otherwise. | +| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.| **Example** - ```js - systemPasteboard.hasPasteData((err, data) => { - if (err) { - console.error('failed to hasPasteData because ' + JSON.stringify(err)); - return; - } - console.info('success hasPasteData : ' + JSON.stringify(data)); - }); - ``` +```js +systemPasteboard.hasPasteData((err, data) => { + if (err) { + console.error('Failed to check the PasteData. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in checking the PasteData. Data: ' + JSON.stringify(data)); +}); +``` ### hasPasteData7+ -hasPasteData(): Promise<boolean> +hasPasteData(): Promise<boolean> -Checks whether the system pasteboard contains content. This API uses a promise to return the result. +Checks whether the system pasteboard contains data. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| Promise<boolean> | Returns **true** if the pasteboard contains content; returns **false** otherwise. | +| Promise<boolean> | Promise used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.| **Example** ```js systemPasteboard.hasPasteData().then((data) => { - console.info('Operation succeeded. ' + JSON.stringify(data)); -}).catch((error) => { - console.error('failed to hasPasteData because ' + JSON.stringify(error)); + console.info('Succeeded in checking the PasteData. Data: ' + JSON.stringify(data)); +}).catch((err) => { + console.error('Failed to check the PasteData. Cause: ' + JSON.stringify(err)); }); ``` ### clear7+ -clear(callback: AsyncCallback<void>): void +clear(callback: AsyncCallback<void>): void -Clears the system pasteboard content. This API uses an asynchronous callback to return the result. +Clears the system pasteboard. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Parameters** -| Name | Type | Mandatory | Description | +| Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| callback | AsyncCallback<void> | Yes | Callback used to return the result. | +| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.| **Example** - ```js - systemPasteboard.clear((err, data) => { - if (err) { - console.error('failed to clear because ' + JSON.stringify(err)); - return; - } - console.info('success clear'); - }); - ``` +```js +systemPasteboard.clear((err, data) => { + if (err) { + console.error('Failed to clear the PasteData. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Succeeded in clearing the PasteData.'); +}); +``` ### clear7+ -clear(): Promise<void> +clear(): Promise<void> -Clears the system pasteboard content. This API uses a promise to return the result. +Clears the system pasteboard. This API uses a promise to return the result. **System capability**: SystemCapability.MiscServices.Pasteboard **Return value** -| Type | Description | +| Type| Description| | -------- | -------- | -| Promise<void> | Promise used to return the result. | +| Promise<void> | Promise that returns no value.| **Example** - ```js - systemPasteboard.clear().then((data) => { - console.info('success clear'); - }).catch((error) => { - console.error('failed to clear because ' + JSON.stringify(error)); - }); - ``` +```js +systemPasteboard.clear().then((data) => { + console.info('Succeeded in clearing the PasteData.'); +}).catch((err) => { + console.error('Failed to clear the PasteData. Cause: ' + JSON.stringify(err)); +}); +``` diff --git a/en/application-dev/reference/apis/js-apis-url.md b/en/application-dev/reference/apis/js-apis-url.md index d97e984d438c8b18febfae5e578cf73dbff244d3..c997fbe314acd2835fb73708e593a1512018c0dd 100755 --- a/en/application-dev/reference/apis/js-apis-url.md +++ b/en/application-dev/reference/apis/js-apis-url.md @@ -26,16 +26,16 @@ Creates a **URLSearchParams** instance. | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | -| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object | +| init | string[][] \| Record<string, string> \| string \| URLSearchParams | No| Input parameter objects, which include the following:
- **string[][]**: two-dimensional string array
- **Record<string, string>**: list of objects
- **string**: string
- **URLSearchParams**: object| **Example** ```js -var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); -var objectParams1 = new Url.URLSearchParams({"fod" : 1 , "bard" : 2}); -var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); -var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); -var params = new Url.URLSearchParams(urlObject.search); +let objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); +let objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'}); +let objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); +let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); +let params = new Url.URLSearchParams(urlObject.search); ``` @@ -59,7 +59,7 @@ Appends a key-value pair into the query string. ```js let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); -paramsObject.append('fod', 3); +paramsObject.append('fod', '3'); ``` @@ -109,10 +109,10 @@ Obtains all the key-value pairs based on the specified key. **Example** ```js -let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); -paramsObject.append('fod', 3); // Add a second value for the fod parameter. -console.log(params.getAll('fod')) // Output ["1","3"]. +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let params = new Url.URLSearchParams(urlObject.search.slice(1)); +params.append('fod', '3'); // Add a second value for the fod parameter. +console.log(params.getAll('fod').toString()) // Output ["1","3"]. ``` @@ -133,7 +133,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th **Example** ```js -var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); +let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs console.log(pair[0]+ ', '+ pair[1]); } @@ -192,15 +192,14 @@ Obtains the value of the first key-value pair based on the specified key. | Type | Description | | -------- | -------- | | string | Returns the value of the first key-value pair if obtained. | -| null | Returns null if no value is obtained. | +| null | Returns **null** if no value is obtained.| **Example** ```js -var paramsOject = new Url.URLSearchParams(document.location.search.substring(1)); -var name = paramsOject.get("name"); // is the string "Jonathan" -var age = parseInt(paramsOject.get("age"), 10); // is the number 18 -var address = paramsOject.get("address"); // null +let paramsObject = new Url.URLSearchParams('name=Jonathan&age=18'); +let name = paramsObject.get("name"); // is the string "Jonathan" +let age = parseInt(paramsObject.get("age"), 10); // is the number 18 ``` @@ -253,7 +252,7 @@ Sets the value for a key. If key-value pairs matching the specified key exist, t ```js let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); -paramsObject.set('baz', 3); // Add a third parameter. +paramsObject.set('baz', '3'); // Add a third parameter. ``` @@ -268,7 +267,7 @@ Sorts all key-value pairs contained in this object based on the Unicode code poi **Example** ```js -var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object +let searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object searchParamsObject.sort(); // Sort the key/value pairs console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 ``` @@ -291,7 +290,7 @@ Obtains an ES6 iterator that contains the keys of all the key-value pairs. **Example** ```js -var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +let searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing for (var key of searchParamsObject .keys()) { // Output key-value pairs console.log(key); } @@ -315,8 +314,8 @@ Obtains an ES6 iterator that contains the values of all the key-value pairs. **Example** ```js -var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing -for (var value of searchParams.values()) { +let searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +for (var value of searchParams.values()) { console.log(value); } ``` @@ -340,7 +339,7 @@ Obtains an ES6 iterator. Each item of the iterator is a JavaScript array, and th ```js const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap'); -for (const [name, value] of paramsObject) { +for (const [name, value] of paramsObject) { console.log(name, value); } ``` @@ -365,7 +364,7 @@ Obtains search parameters that are serialized as a string and, if necessary, per ```js let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let params = new Url.URLSearchParams(url.search.slice(1)); -params.append('fod', 3); +params.append('fod', '3'); console.log(params.toString()); ``` @@ -405,16 +404,16 @@ Creates a URL. | Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | | url | string | Yes | Input object. | -| base | string \ |& URL | No | Input parameter, which can be any of the following:
- **string**: string
- **URL**: string or object | +| base | string \| URL | No| Input parameter, which can be any of the following:
- **string**: string
- **URL**: string or object| **Example** ```js -var mm = 'http://username:password@host:8080'; -var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; -var b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; +let mm = 'http://username:password@host:8080'; +let a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; +let b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; -var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +let c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 @@ -443,7 +442,7 @@ Converts the parsed URL into a string. ```js const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toString() +url.toString(); ``` @@ -464,5 +463,5 @@ Converts the parsed URL into a JSON string. **Example** ```js const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toJSON() -``` \ No newline at end of file +url.toJSON(); +``` diff --git a/en/application-dev/reference/apis/js-apis-util.md b/en/application-dev/reference/apis/js-apis-util.md index 2ac8daeb3799908d57a5b7a2c5fd456dcfee8f59..8239f4f8e42d5a73bb3576264c4725f3d68925a0 100755 --- a/en/application-dev/reference/apis/js-apis-util.md +++ b/en/application-dev/reference/apis/js-apis-util.md @@ -141,7 +141,7 @@ Processes an asynchronous function and returns a promise version. | Name| Type| Readable| Writable| Description| | -------- | -------- | -------- | -------- | -------- | -| encoding | string | Yes| No| Encoding format.
- Supported formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u, macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, windows-1256, windows-1257, windows-1258, x-mac-cyrilli, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, euc-kr, utf-16be, utf-16le| +| encoding | string | Yes| No| Encoding format.
- Supported formats: utf-8.| | fatal | boolean | Yes| No| Whether to display fatal errors.| | ignoreBOM | boolean | Yes| No| Whether to ignore the byte order marker (BOM). The default value is **false**, which indicates that the result contains the BOM.| diff --git a/en/application-dev/reference/arkui-ts/ts-basic-components-textclock.md b/en/application-dev/reference/arkui-ts/ts-basic-components-textclock.md index 32e8897dfc8623d7167c4c3294d2efd5e2619601..c11f57336cbdcca75ed8d1eba822972f2a12e795 100644 --- a/en/application-dev/reference/arkui-ts/ts-basic-components-textclock.md +++ b/en/application-dev/reference/arkui-ts/ts-basic-components-textclock.md @@ -1,49 +1,50 @@ # TextClock -> ![](public_sys-resources/icon-note.gif) **NOTE** This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. - The **** component displays the current system time in text format for different time zones. The time is accurate to seconds. -## Required Permissions - -None +>**NOTE** +> +>This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. ## Child Components -None +Not supported ## APIs -TextClock(options?: {timeZoneOffset?: number, contorller?: TextClockController}) +TextClock(options?: { timeZoneOffset?: number, controller?: TextClockController }) -- Parameters +**Parameters** - | Name | Type| Mandatory| Default Value | Description | - | -------- | -------- | ---- | ------------------ | ------------------------------------------------------------ | - | timeZoneOffset | number | No | Time zone offset| Sets the time zone offset. The value range is [-14, 12], indicating UTC+12 to UTC-12. A negative value indicates Eastern Standard Time, and a positive value indicates Western Standard Time. For example, **-8** indicates UTC+8. For countries or regions crossing the International Date Line, use -13 (UTC+13) and -14 (UTC+14) to ensure consistent time within the entire country or region.| - | contorller | [TextClockContorller](#TextClockController) | No| null | Binds a controller to control the status of the **** component.| +| Name | Type | Mandatory | Description | +| -------------- | -------- | ------ | --------------------------------------------------------------------------- | +| timeZoneOffset | number | No | Time zone offset.
The value range is [-14, 12], indicating UTC+12 to UTC-12. A negative value indicates Eastern Standard Time, and a positive value indicates Western Standard Time. For example, **-8** indicates UTC+8.
For countries or regions crossing the International Date Line, use -13 (UTC+13) and -14 (UTC+14) to ensure consistent time within the entire country or region. If the set value is not within the valid range, the time zone offset of the current system will be used.
Default value: time zone offset of the current system | +| controller | [TextClockController](#textclockcontroller) | No | Controller to control the status of the **** component. | ## Attributes -| Name | Type| Default Value | Description | -| ------ | -------- | -------- | ------------------------------------------------------------ | -| format | string | 'hhmmss' | Time format, for example, **yyyy/mm/dd** or **yyyy-mm-dd**. Supported time format strings:
  • yyyy (year)
  • mm (two-letter abbreviated month name)
  • mmm (three-letter abbreviated month name)
  • mmmm (full month name)
  • dd (two-letter abbreviated day of the week)
  • ddd (three-letter abbreviated day of the week)
  • dddd (full day of the week)
  • HH (24-hour format)
  • hh (12-hour format)
  • MM/mm (minute)
  • SS/ss (second)
| +In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. + +| Name | Type | Description | +| ------ | --------------- | ------------------------------------------------------------ | +| format | string | Time format.
The date separator is a slash (/), and the time separator is a colon (:).
For example, yyyyMMdd and yyyy-MM-dd are displayed as yyyy/MM/dd,
and hhmmss is displayed as hh:mm:ss.
Only one digit is required for the time format. This means that hhmmss is equivalent to hms.
Supported time format strings:
- YYYY/yyyy: four-digit year
- YY/yy: last two digits of year
- M: one-digit month (MM for two-digit month, for example, 01)
- d: one-digit day (dd for two-digit day, for example, 01)
- D: number of days that have elapsed in the year
- H: 24-hour format
- h: 12-hour format
- m: minute
- s: second
- SSS: millisecond
Default value: **'hms'**| ## Events +In addition to the universal events (ts-universal-events-click.md), the following events are supported. + | Name | Description | | -------------------------------------------- | ------------------------------------------------------------ | -| onDateChange(event: (value: number) => void) | Triggered when the time changes in seconds at minimum.
**value**: Unix time stamp, which is the number of milliseconds that have elapsed since the Unix epoch.| +| onDateChange(event: (value: number) => void) | Called when the time changes in seconds at minimum.
- **value**: Unix time stamp, which is the number of milliseconds that have elapsed since the Unix epoch.| ## TextClockController -Controller of the **** component, which can be bound to the component for status control. +Defines the controller of the **** component, which can be bound to the component for status control. A **\** component can be bound to only one controller. ### Objects to Import -``` +```ts controller: TextClockController = new TextClockController() - ``` ### start @@ -61,7 +62,7 @@ Stops the **** component. ## Example -``` +```ts @Entry @Component struct Second { @@ -69,26 +70,26 @@ struct Second { controller: TextClockController = new TextClockController() build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center}) { - Text('current milliseconds is' + this.accumulateTime) - .fontSize(20) - TextClock({timeZoneOffset: -8, controller: this.controller}) - .format('hhmmss') - .onDateChange((value: number) => { - this.accumulateTime = value - }) - .margin(20) - .fontSize(30) - Button("start TextClock") - .margin({ bottom: 10 }) - .onClick(()=>{ - this.controller.start() - }) - Button("stop TextClock") - .onClick(()=>{ - this.controller.stop() - }) - } + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Current milliseconds is ' + this.accumulateTime) + .fontSize(20) + TextClock({ timeZoneOffset: -8, controller: this.controller }) + .format('hms') + .onDateChange((value: number) => { + this.accumulateTime = value + }) + .margin(20) + .fontSize(30) + Button("start TextClock") + .margin({ bottom: 10 }) + .onClick(() => { + this.controller.start() + }) + Button("stop TextClock") + .onClick(() => { + this.controller.stop() + }) + } .width('100%') .height('100%') } diff --git a/en/application-dev/reference/arkui-ts/ts-matrix-transformation.md b/en/application-dev/reference/arkui-ts/ts-matrix-transformation.md index 0eded3f87db1c32ab188901e7d9f68e62ef17ddc..cb762620ba0315dc148e9c7278660fac936ee067 100644 --- a/en/application-dev/reference/arkui-ts/ts-matrix-transformation.md +++ b/en/application-dev/reference/arkui-ts/ts-matrix-transformation.md @@ -1,14 +1,14 @@ # Matrix Transformation -> **NOTE**
+> **NOTE** +> > This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. ## Modules to Import - -``` +```ts import matrix4 from '@ohos.matrix4' ``` @@ -23,45 +23,45 @@ None init(array: Array<number>): Object -Matrix constructor, which is used to create a 4x4 matrix by using the input parameter. Column-major order is used. +Implements a 4x4 matrix by using the input parameter. The column-major order is used. - Parameters - | Name | Type | Mandatory | Default Value | Description | + | Name | Type | Mandatory | Default Value | Description | | -------- | -------- | -------- | -------- | -------- | | array | Array<number> | Yes | [1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1] | A number array whose length is 16 (4 x 4). For details, see the parameter description. | - Return value - | Type | Description | + | Type | Description | | -------- | -------- | | Object | 4x4 matrix object created based on the input parameter. | - Parameter description - | Name | Type | Mandatory | Description | + | Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | - | m00 | number | Yes | Scaling value of the x-axis. Defaults to **1** for the unit matrix. | - | m01 | number | Yes | The second value, which is affected by the rotation of the x, y, and z axes. | - | m02 | number | Yes | The third value, which is affected by the rotation of the x, y, and z axes. | + | m00 | number | Yes | Scaling value along the x-axis. Defaults to **1** for the identity matrix. | + | m01 | number | Yes | The second value, which is affected by the rotation along the x, y, and z axes. | + | m02 | number | Yes | The third value, which is affected by the rotation along the x, y, and z axes. | | m03 | number | Yes | Meaningless. | - | m10 | number | Yes | The fifth value, which is affected by the rotation of the x, y, and z axes. | - | m11 | number | Yes | Scaling value of the y-axis. Defaults to **1** for the unit matrix. | - | m12 | number | Yes | The seventh value, which is affected by the rotation of the x, y, and z axes. | + | m10 | number | Yes | The fifth value, which is affected by the rotation along the x, y, and z axes. | + | m11 | number | Yes | Scaling value along the y-axis. Defaults to **1** for the identity matrix. | + | m12 | number | Yes | The seventh value, which is affected by the rotation along the x, y, and z axes. | | m13 | number | Yes | Meaningless. | - | m20 | number | Yes | The ninth value, which is affected by the rotation of the x, y, and z axes. | - | m21 | number | Yes | The tenth value, which is affected by the rotation of the x, y, and z axes. | - | m22 | number | Yes | Scaling value of the z-axis. Defaults to **1** for the unit matrix. | + | m20 | number | Yes | The ninth value, which is affected by the rotation along the x, y, and z axes. | + | m21 | number | Yes | The tenth value, which is affected by the rotation along the x, y, and z axes. | + | m22 | number | Yes | Scaling value along the z-axis. Defaults to **1** for the identity matrix. | | m23 | number | Yes | Meaningless. | - | m30 | number | Yes | Translation value of the x-axis, in px. Defaults to **0** for the unit matrix. | - | m31 | number | Yes | Translation value of the y-axis, in px. Defaults to **0** for the unit matrix. | - | m32 | number | Yes | Translation value of the z-axis, in px. Defaults to **0** for the unit matrix. | + | m30 | number | Yes | Translation value along the x-axis, in px. Defaults to **0** for the identity matrix. | + | m31 | number | Yes | Translation value along the y-axis, in px. Defaults to **0** for the identity matrix. | + | m32 | number | Yes | Translation value along the z-axis, in px. Defaults to **0** for the identity matrix. | | m33 | number | Yes | Valid in homogeneous coordinates, presenting the perspective projection effect. | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' // Create a 4x4 matrix. - let matrix = Matrix4.init([1.0, 0.0, 0.0, 0.0, + let matrix = matrix4.init([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) @@ -73,20 +73,20 @@ Matrix constructor, which is used to create a 4x4 matrix by using the input para identity(): Object -Matrix initialization function. Can return a unit matrix object. +Performs matrix initialization. This API returns an identity matrix object. - Return value - | Type | Description | + | Type | Description | | -------- | -------- | - | Object | Unit matrix object. | + | Object | Identity matrix object. | - Example - ``` + ```ts // The effect of matrix 1 is the same as that of matrix 2. - import Matrix4 from '@ohos.matrix4' - let matrix = Matrix4.init([1.0, 0.0, 0.0, 0.0, + import matrix4 from '@ohos.matrix4' + let matrix = matrix4.init([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]) @@ -99,22 +99,22 @@ Matrix initialization function. Can return a unit matrix object. copy(): Object -Matrix copy function, which is used to copy the current matrix object. +Copies this matrix object. - Return value - | Type | Description | + | Type | Description | | -------- | -------- | - | Object | Copy object of the current matrix. | + | Object | Copy of the current matrix object. | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private matrix1 = Matrix4.identity().translate({x:100}) + private matrix1 = matrix4.identity().translate({x:100}) private matrix2 = this.matrix1.copy().scale({x:2}) build() { Column() { @@ -143,28 +143,28 @@ Matrix copy function, which is used to copy the current matrix object. combine(matrix: Matrix4): Object -Matrix overlay function, which is used to overlay the effects of two matrices to generate a new matrix object. +Combines this matrix object with another to generate a new matrix object. - Parameters - | Name | Type | Mandatory | Default Value | Description | + | Name | Type | Mandatory | Default Value | Description | | -------- | -------- | -------- | -------- | -------- | - | matrix | Matrix4 | Yes | - | Matrix object to be overlaid. | + | matrix | Matrix4 | Yes | - | Matrix object to combine. | - Return value | Type | Description | | -------- | -------- | - | Object | Object after matrix overlay. | + | Object | Object after the combination. | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private matrix1 = Matrix4.identity().translate({x:200}).copy() - private matrix2 = Matrix4.identity().scale({x:2}).copy() + private matrix1 = matrix4.identity().translate({x:200}).copy() + private matrix2 = matrix4.identity().scale({x:2}).copy() build() { Column() { // Translate the x-axis by 100 pixels and then scale it up or down by 2x. @@ -185,21 +185,21 @@ Matrix overlay function, which is used to overlay the effects of two matrices to invert(): Object -Matrix inverse function. Can return an inverse matrix of the current matrix object, that is, get an opposite effect. +Inverts this matrix object. - Return value - | Type | Description | + | Type | Description | | -------- | -------- | | Object | Inverse matrix object of the current matrix. | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' // The effect of matrix 1 (width scaled up by 2x) is opposite to that of matrix 2 (width scaled down by 2x). - let matrix1 = Matrix4.identity().scale({x:2}) - let matrix2 = matrix1.invert() + let matrix1 = matrix4.identity().scale({x:2}) + let matrix2 = matrix1.copy().invert() ``` @@ -208,15 +208,15 @@ Matrix inverse function. Can return an inverse matrix of the current matrix obje translate({x?: number, y?: number, z?: number}): Object -Matrix translation function, which is used to add the translation effect to the x, y, and z axes of the current matrix. +Translates this matrix object along the x, y, and z axes. - Parameters - | Name | Type | Mandatory | Default Value | Description | + | Name | Type | Mandatory | Default Value | Description | | -------- | -------- | -------- | -------- | -------- | - | x | number | No | 0 | Translation distance of the x-axis, in px. | - | y | number | No | 0 | Translation distance of the y-axis, in px. | - | z | number | No | 0 | Translation distance of the z-axis, in px. | + | x | number | No | 0 | Translation distance along the x-axis, in px. | + | y | number | No | 0 | Translation distance along the y-axis, in px. | + | z | number | No | 0 | Translation distance along the z-axis, in px. | - Return value @@ -226,12 +226,12 @@ Matrix translation function, which is used to add the translation effect to the - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private matrix1 = Matrix4.identity().translate({x:100, y:200, z:30}) + private matrix1 = matrix4.identity().translate({x:100, y:200, z:30}) build() { Column() { Image($r("app.media.bg1")).transform(this.matrix1) @@ -250,32 +250,32 @@ Matrix translation function, which is used to add the translation effect to the scale({x?: number, y?: number, z?: number, centerX?: number, centerY?: number}): Object -Matrix scaling function, which is used to add the scaling effect to the x, y, and z axes of the current matrix. +Scales this matrix object along the x, y, and z axes. - Parameters - | Name | Type | Mandatory | Default Value | Description | + | Name | Type | Mandatory | Default Value | Description | | -------- | -------- | -------- | -------- | -------- | - | x | number | No | 1 | Scaling multiple of the x-axis. | - | y | number | No | 1 | Scaling multiple of the y-axis. | - | z | number | No | 1 | Scaling multiple of the z-axis. | + | x | number | No | 1 | Scaling multiple along the x-axis. | + | y | number | No | 1 | Scaling multiple along the y-axis. | + | z | number | No | 1 | Scaling multiple along the z-axis. | | centerX | number | No | 0 | X coordinate of the center point. | | centerY | number | No | 0 | Y coordinate of the center point. | - Return value - | Type | Description | + | Type | Description | | -------- | -------- | | Object | Matrix object after the scaling effect is added. | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private matrix1 = Matrix4.identity().scale({x:2, y:3, z:4, centerX:50, centerY:50}) + private matrix1 = matrix4.identity().scale({x:2, y:3, z:4, centerX:50, centerY:50}) build() { Column() { Image($r("app.media.bg1")).transform(this.matrix1) @@ -294,11 +294,11 @@ Matrix scaling function, which is used to add the scaling effect to the x, y, an rotate({x?: number, y?: number, z?: number, angle?: number, centerX?: Length, centerY?: Length}): Object -Matrix rotation function, which is used to add the rotation effect to the x, y, and z axes of the current matrix. +Rotates this matrix object along x, y, and z axes. - Parameters - | Name | Type | Mandatory | Default Value | Description | + | Name | Type | Mandatory | Default Value | Description | | -------- | -------- | -------- | -------- | -------- | | x | number | No | 1 | X coordinate of the rotation axis vector. | | y | number | No | 1 | Y coordinate of the rotation axis vector. | @@ -309,18 +309,18 @@ Matrix rotation function, which is used to add the rotation effect to the x, y, - Return value - | Type | Description | + | Type | Description | | -------- | -------- | | Object | Matrix object after the rotation effect is added. | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' @Entry @Component struct Test { - private matrix1 = Matrix4.identity().rotate({x:1, y:1, z:2, angle:30}) + private matrix1 = matrix4.identity().rotate({x:1, y:1, z:2, angle:30}) build() { Column() { Image($r("app.media.bg1")).transform(this.matrix1) @@ -339,30 +339,30 @@ Matrix rotation function, which is used to add the rotation effect to the x, y, transformPoint(point: Point): Point -Matrix point transformation function, which is used to apply the current transformation effect to a coordinate point. +Applies this transformation effect to a coordinate point. - Parameters - | Name | Type | Mandatory | Default Value | Description | + | Name | Type | Mandatory | Default Value | Description | | -------- | -------- | -------- | -------- | -------- | | point | Point | Yes | - | Point to be transformed. | - Return value - | Type | Description | + | Type | Description | | -------- | -------- | | Point | Point object after matrix transformation | - Example - ``` - import Matrix4 from '@ohos.matrix4' + ```ts + import matrix4 from '@ohos.matrix4' import prompt from '@system.prompt' @Entry @Component struct Test { - private matrix1 = Matrix4.identity().transformPoint([100, 10]) + private matrix1 = matrix4.identity().transformPoint([100, 10]) build() { Column() { Button("get Point") diff --git a/en/application-dev/security/accesstoken-guidelines.md b/en/application-dev/security/accesstoken-guidelines.md index 84af1e12e66edeb59ddb1f196d381b2b2d4dc70e..c5f3499f52137a06f2be5bd08b367ce630bff0b1 100644 --- a/en/application-dev/security/accesstoken-guidelines.md +++ b/en/application-dev/security/accesstoken-guidelines.md @@ -133,9 +133,8 @@ onStart() { context.requestPermissionsFromUser(array, 1, (err, data)=>{ console.info("====>requestdata====>" + JSON.stringify(data)); console.info("====>requesterrcode====>" + JSON.stringify(err.code)); - } + }) } ``` > **NOTE**
> For details about how to use **requestPermissionsFromUser**, see [API Reference](../reference/apis/js-apis-ability-context.md). - diff --git a/en/application-dev/ui/Readme-EN.md b/en/application-dev/ui/Readme-EN.md index 8c41acc214947881abfc99bc2ec6b59ca55b7662..3a568247a67de806486b75eee982e7aa7a583f29 100644 --- a/en/application-dev/ui/Readme-EN.md +++ b/en/application-dev/ui/Readme-EN.md @@ -4,72 +4,75 @@ - TypeScript-based Declarative Development Paradigm - [Overview](ui-ts-overview.md) - Framework Overview - - File Organization - - [Directory Structure](ts-framework-directory.md) - - [Rules for Accessing Application Code Files](ts-framework-file-access-rules.md) - - ["js" Tag](ts-framework-js-tag.md) - - Resource Management - - [Resource File Categories](ui-ts-basic-resource-file-categories.md) - - [Accessing Resources](ts-resource-access.md) - - [Pixel Units](ts-pixel-units.md) + - File Organization + - [Directory Structure](ts-framework-directory.md) + - [Rules for Accessing Application Code Files](ts-framework-file-access-rules.md) + - ["js" Tag](ts-framework-js-tag.md) + - Resource Management + - [Resource File Categories](ui-ts-basic-resource-file-categories.md) + - [Accessing Resources](ts-resource-access.md) + - [Pixel Units](ts-pixel-units.md) - Declarative Syntax - - [Overview](ts-syntax-intro.md) - - General UI Description Specifications - - [Basic Concepts](ts-general-ui-concepts.md) - - Declarative UI Description Specifications - - [Configuration Without Parameters](ts-parameterless-configuration.md) - - [Configuration with Mandatory Parameters](ts-configuration-with-mandatory-parameters.md) - - [Attribute Configuration](ts-attribution-configuration.md) - - [Event Configuration](ts-event-configuration.md) - - [Child Component Configuration](ts-child-component-configuration.md) - - Componentization - - [@Component](ts-component-based-component.md) - - [@Entry](ts-component-based-entry.md) - - [@Preview](ts-component-based-preview.md) - - [@Builder](ts-component-based-builder.md) - - [@Extend](ts-component-based-extend.md) - - [@CustomDialog](ts-component-based-customdialog.md) - - [@Styles](ts-component-based-styles.md) - - About UI State Management - - [Basic Concepts](ts-ui-state-mgmt-concepts.md) - - Managing Component States - - [@State](ts-component-states-state.md) - - [@Prop](ts-component-states-prop.md) - - [@Link](ts-component-states-link.md) - - Managing Application States - - [AppStorage](ts-application-states-appstorage.md) - - [PersistentStorage](ts-application-states-apis-persistentstorage.md) - - [Environment](ts-application-states-apis-environment.md) - - Managing Other States - - [@Observed and @ObjectLink](ts-other-states-observed-objectlink.md) - - [@Consume and @Provide](ts-other-states-consume-provide.md) - - [@Watch](ts-other-states-watch.md) - - About Rendering Control Syntax - - [if/else](ts-rending-control-syntax-if-else.md) - - [ForEach](ts-rending-control-syntax-foreach.md) - - [LazyForEach](ts-rending-control-syntax-lazyforeach.md) - - About @Component - - [build Function](ts-function-build.md) - - [Initialization of Custom Components' Member Variables](ts-custom-component-initialization.md) - - [Custom Component Lifecycle Callbacks](ts-custom-component-lifecycle-callbacks.md) - - [Component Creation and Re-initialization](ts-component-creation-re-initialization.md) - - [About Syntactic Sugar](ts-syntactic-sugar.md) + - [Overview](ts-syntax-intro.md) + - General UI Description Specifications + - [Basic Concepts](ts-general-ui-concepts.md) + - Declarative UI Description Specifications + - [Configuration Without Parameters](ts-parameterless-configuration.md) + - [Configuration with Mandatory Parameters](ts-configuration-with-mandatory-parameters.md) + + - [Attribute Configuration](ts-attribution-configuration.md) + - [Event Configuration](ts-event-configuration.md) + - [Child Component Configuration](ts-child-component-configuration.md) + - Componentization + - [@Component](ts-component-based-component.md) + - [@Entry](ts-component-based-entry.md) + - [@Preview](ts-component-based-preview.md) + - [@Builder](ts-component-based-builder.md) + - [@Extend](ts-component-based-extend.md) + - [@CustomDialog](ts-component-based-customdialog.md) + - [@Styles](ts-component-based-styles.md) + - About UI State Management + - [Basic Concepts](ts-ui-state-mgmt-concepts.md) + - Managing Component States + - [@State](ts-component-states-state.md) + - [@Prop](ts-component-states-prop.md) + - [@Link](ts-component-states-link.md) + - Managing Application States + - [AppStorage](ts-application-states-appstorage.md) + - [PersistentStorage](ts-application-states-apis-persistentstorage.md) + - [Environment](ts-application-states-apis-environment.md) + - Managing Other States + - [@Observed and @ObjectLink](ts-other-states-observed-objectlink.md) + - [@Consume and @Provide](ts-other-states-consume-provide.md) + - [@Watch](ts-other-states-watch.md) + - About Rendering Control Syntax + - [if/else](ts-rending-control-syntax-if-else.md) + - [ForEach](ts-rending-control-syntax-foreach.md) + - [LazyForEach](ts-rending-control-syntax-lazyforeach.md) + - About @Component + - [build Function](ts-function-build.md) + - [Initialization of Custom Components' Member Variables](ts-custom-component-initialization.md) + - [Custom Component Lifecycle Callbacks](ts-custom-component-lifecycle-callbacks.md) + - [Component Creation and Re-initialization](ts-component-creation-re-initialization.md) + - [About Syntactic Sugar](ts-syntactic-sugar.md) - Common Component Development Guidelines - - [Button](ui-ts-basic-components-button.md) - - [Web](ui-ts-components-web.md) + - [Button](ui-ts-basic-components-button.md) + - [Web](ui-ts-components-web.md) - Common Layout Development Guidelines - - [Flex Layout](ui-ts-layout-flex.md) - - [Grid Layout](ui-ts-layout-grid-container.md) - - [Media Query](ui-ts-layout-mediaquery.md) + - [Flex Layout](ui-ts-layout-flex.md) + - [Grid Layout](ui-ts-layout-grid-container.md) + - [Media Query](ui-ts-layout-mediaquery.md) - Experiencing the Declarative UI - - [Creating a Declarative UI Project](ui-ts-creating-project.md) - - [Getting to Know Components](ui-ts-components.md) - - [Creating a Simple Page](ui-ts-creating-simple-page.md) + - [Creating a Declarative UI Project](ui-ts-creating-project.md) + - [Getting to Know Components](ui-ts-components.md) + - [Creating a Simple Page](ui-ts-creating-simple-page.md) - Defining Page Layout and Connection - - [Building a Food Data Model](ui-ts-building-data-model.md) - - [Building a Food Category List Layout](ui-ts-building-category-list-layout.md) - - [Building a Food Category Grid Layout](ui-ts-building-category-grid-layout.md) - - [Implementing Page Redirection and Data Transmission](ui-ts-page-redirection-data-transmission.md) + - [Building a Food Data Model](ui-ts-building-data-model.md) + - [Building a Food Category List Layout](ui-ts-building-category-list-layout.md) + - [Building a Food Category Grid Layout](ui-ts-building-category-grid-layout.md) + - [Implementing Page Redirection and Data Transmission](ui-ts-page-redirection-data-transmission.md) + - [Recommendations for Improving Performance](ts-performance-improvement-recommendation.md) + - JavaScript-based Web-like Development Paradigm - [Overview](ui-js-overview.md) - Framework diff --git a/en/application-dev/ui/ts-performance-improvement-recommendation.md b/en/application-dev/ui/ts-performance-improvement-recommendation.md new file mode 100644 index 0000000000000000000000000000000000000000..ee06f5113f1f857d280efd30a6170293eab52d33 --- /dev/null +++ b/en/application-dev/ui/ts-performance-improvement-recommendation.md @@ -0,0 +1,304 @@ +# Recommendations for Improving Performance + +Poor-performing code may work, but will take away from your application performance. This topic presents a line-up of recommendations that you can take to improve your implementation, thereby avoiding possible performance drop. + +## Lazy Loading + +When developing a long list, use of loop rendering, as in the code snippet below, can greatly slow down page loading and increase server load. + +```ts +@Entry +@Component +struct MyComponent { + @State arr: number[] = Array.from(Array(100), (v,k) =>k); // Construct an array of 0 to 99. + build() { + List() { + ForEach(this.arr, (item: number) => { + ListItem() { + Text(`item value: ${item}`) + } + }, (item: number) => item.toString()) + } + } +} +``` + +The preceding code snippet loads all of the 100 list elements at a time during page loading. This is generally not desirable. Instead, what we need is to load data from the data source and create corresponding components on demand. This can be achieved through lazy loading. The sample code is as follows: + +```ts +class BasicDataSource implements IDataSource { + private listeners: DataChangeListener[] = [] + + public totalCount(): number { + return 0 + } + + public getData(index: number): any { + return undefined + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + console.info('add listener') + this.listeners.push(listener) + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + console.info('remove listener') + this.listeners.splice(pos, 1) + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded() + }) + } + + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index) + }) + } + + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index) + }) + } + + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index) + }) + } + + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to) + }) + } +} + +class MyDataSource extends BasicDataSource { + private dataArray: string[] = ['item value: 0', 'item value: 1', 'item value: 2'] + + public totalCount(): number { + return this.dataArray.length + } + + public getData(index: number): any { + return this.dataArray[index] + } + + public addData(index: number, data: string): void { + this.dataArray.splice(index, 0, data) + this.notifyDataAdd(index) + } + + public pushData(data: string): void { + this.dataArray.push(data) + this.notifyDataAdd(this.dataArray.length - 1) + } +} + +@Entry +@Component +struct MyComponent { + private data: MyDataSource = new MyDataSource() + + build() { + List() { + LazyForEach(this.data, (item: string) => { + ListItem() { + Row() { + Text(item).fontSize(20).margin({ left: 10 }) + } + } + .onClick(() => { + this.data.pushData('item value: ' + this.data.totalCount()) + }) + }, item => item) + } + } +} +``` + +The preceding code initializes only three list elements during page loading and loads a new list item each time a list element is clicked. + +## Prioritizing Conditional Rendering over Visibility Control + +Use of the visibility attribute to hide or show a component, as in the code snippet below, results in re-creation of the component, leading to performance drop. + +```ts +@Entry +@Component +struct MyComponent { + @State isVisible: Visibility = Visibility.Visible; + + build() { + Column() { + Button ("Show/Hide") + .onClick(() => { + if (this.isVisible == Visibility.Visible) { + this.isVisible = Visibility.None + } else { + this.isVisible = Visibility.Visible + } + }) + Row().visibility(this.isVisible) + .width(300).height(300).backgroundColor(Color.Pink) + }.width('100%') + } +} +``` + +To avoid the preceding issue, use the **if** conditional statement instead. The sample code is as follows: + +```ts +@Entry +@Component +struct MyComponent { + @State isVisible: boolean = true; + + build() { + Column() { + Button ("Show/Hide") + .onClick(() => { + this.isVisible = !this.isVisible + }) + if (this.isVisible) { + Row() + .width(300).height(300).backgroundColor(Color.Pink) + } + }.width('100%') + } +} +``` + +## Prioritizing Flex over Column/Row + +By default, the flex container needs to re-lay out flex items to comply with the **flexShrink** and **flexGrow** settings. This may result in drop in rendering performance. + +```ts +@Entry +@Component +struct MyComponent { + build() { + Flex({ direction: FlexDirection.Column }) { + Flex().width(300).height(200).backgroundColor(Color.Pink) + Flex().width(300).height(200).backgroundColor(Color.Yellow) + Flex().width(300).height(200).backgroundColor(Color.Grey) + } + } +} +``` + +To avoid the preceding issue, replace **Flex** with **Column** and **Row**, which can create the same page layout as **Flex** does. + +```ts +@Entry +@Component +struct MyComponent { + build() { + Column() { + Row().width(300).height(200).backgroundColor(Color.Pink) + Row().width(300).height(200).backgroundColor(Color.Yellow) + Row().width(300).height(200).backgroundColor(Color.Grey) + } + } +} +``` + +## Setting Width and Height for \ Components + +When a **\** component is nested within a **\** component, all of its content will be loaded if its width and height is not specified, which may result in performance drop. + +```ts +@Entry +@Component +struct MyComponent { + private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + build() { + Scroll() { + List() { + ForEach(this.arr, (item) => { + ListItem() { + Text(`item value: ${item}`).fontSize(30).margin({ left: 10 }) + }.height(100) + }, (item) => item.toString()) + } + }.backgroundColor(Color.Pink) + } +} +``` + +Therefore, in the above scenario, you are advised to set the width and height for the **\** component as follows: + +```ts +@Entry +@Component +struct MyComponent { + private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + build() { + Scroll() { + List() { + ForEach(this.arr, (item) => { + ListItem() { + Text(`item value: ${item}`).fontSize(30).margin({ left: 10 }) + }.height(100) + }, (item) => item.toString()) + }.width('100%').height(500) + }.backgroundColor(Color.Pink) + } +} +``` + +## Minimizing White Blocks During Swiping +To minimize white blocks durign swiping, expand the UI loading range by increasing the value of **cachedCount** for the **\** and **\** components. **cachedCount** indicates the number of list or grid items preloaded outside of the screen. + +If an item needs to request an online image, set **cachedCount** as appropriate so that the the image is downloaded in advance before the item comes into view on the screen, thereby reducing the number of white blocks. + +The following is an example of using **cachedCount**: + +```ts +@Entry +@Component +struct MyComponent { + private source: MyDataSource = new MyDataSource(); + build() { + List() { + LazyForEach (this.source, item => { + ListItem() { + Text("Hello" + item) + .fontSize(100) + .onAppear(()=>{ + console.log("appear:" + item) + }) + } + }) + }.cachedCount(3) // Increase the value to enlarge the range of logs that appear. + } +} +class MyDataSource implements IDataSource { + data: number[] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; + public totalCount(): number { + return this.data.length + } + public getData(index: number): any { + return this.data[index] + } + registerDataChangeListener(listener: DataChangeListener): void { + } + unregisterDataChangeListener(listener: DataChangeListener): void { + } +} +``` +**Instructions** + +A greater **cachedCount** value may result in higher CPU and memory overhead of the UI. Adjust the value by taking into account both the comprehensive performance and user experience. \ No newline at end of file diff --git a/zh-cn/application-dev/device/sensor-guidelines.md b/zh-cn/application-dev/device/sensor-guidelines.md index 7880e3a07bea3c19a4f117fae76d5322fd233704..e0dfb477374c29ce46b2885b68a568678c2a627c 100644 --- a/zh-cn/application-dev/device/sensor-guidelines.md +++ b/zh-cn/application-dev/device/sensor-guidelines.md @@ -26,58 +26,30 @@ | -------- | -------- | -------- | | ohos.sensor | sensor.on(sensorType, callback:AsyncCallback<Response>): void | 持续监听传感器数据变化 | | ohos.sensor | sensor.once(sensorType, callback:AsyncCallback<Response>): void | 获取一次传感器数据变化 | -| ohos.sensor | sensor.off(sensorType, callback:AsyncCallback<void>): void | 注销传感器数据的监听 | +| ohos.sensor | sensor.off(sensorType, callback?:AsyncCallback<void>): void | 注销传感器数据的监听 | ## 开发步骤 -1. 获取设备上传感器的数据,需要在“config.json”里面进行配置请求权限。具体如下: - - ``` - "reqPermissions":[ - { - "name":"ohos.permission.ACCELEROMETER", - "reason":"", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - { - "name":"ohos.permission.GYROSCOPE", - "reason":"", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - { - "name":"ohos.permission.ACTIVITY_MOTION", - "reason":"ACTIVITY_MOTION_TEST", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - { - "name":"ohos.permission.READ_HEALTH_DATA", - "reason":"HEALTH_DATA_TEST", - "usedScene":{ - "ability": ["sensor.index.MainAbility",".MainAbility"], - "when":"inuse" - } - }, - ] - ``` +1. 获取设备上传感器的数据前,需要检查是否已经配置请求相应的权限。
+ 系统提供的传感器权限有: + - ohos.permission.ACCELEROMETER + + - ohos.permission.GYROSCOPE + + - ohos.permission.ACTIVITY_MOTION + + - ohos.permission.READ_HEALTH_DATA + + 具体配置方式请参考[权限申请声明](../security/accesstoken-guidelines.md)。 2. 持续监听传感器数据变化。 ``` - import sensor from "@ohos.sensor" - sensor.on(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data){ - console.info("Subscription succeeded. data = " + data);//调用成功,打印对应传感器的数据 - } - ); + import sensor from "@ohos.sensor"; + sensor.on(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data){ + console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z);// 获取数据成功 + }); ``` 以SensorType为SENSOR_TYPE_ID_ACCELEROMETER为例展示运行结果,持续监听传感器接口的结果如下图所示: @@ -87,11 +59,8 @@ 3. 注销传感器数据监听。 ``` - import sensor from "@ohos.sensor" - sensor.off(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function() { - console.info("Succeeded in unsubscribing from acceleration sensor data.");//注销成功,返回打印结果 - } - ); + import sensor from "@ohos.sensor"; + sensor.off(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER); ``` 以SensorType为SENSOR_TYPE_ID_ACCELEROMETER为例展示运行结果,注销传感器成功结果如下图所示: @@ -101,11 +70,10 @@ 4. 获取一次传感器数据变化。 ``` - import sensor from "@ohos.sensor" - sensor.once(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data) { - console.info("Data obtained successfully. data=" + data);//获取数据成功,打印对应传感器的数据 - } - ); + import sensor from "@ohos.sensor"; + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data) { + console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z);// 获取数据成功 + }); ``` 以SensorType为SENSOR_TYPE_ID_ACCELEROMETER为例展示运行结果,获取数据成功日志如下图所示: @@ -115,15 +83,15 @@ 若接口调用不成功,建议使用try/catch语句捕获代码中可能出现的错误信息。例如: ``` + import sensor from "@ohos.sensor"; try { - sensor.once(sensor.sensorType.SENSOR_TYPE_ACCELEROMETER,function(data) { - console.info("Data obtained successfully. data=" + data);//获取数据成功,打印对应传感器的数据 + sensor.once(sensor.SensorType.SENSOR_TYPE_ID_ACCELEROMETER, function(data) { + console.info("Data obtained successfully. x: " + data.x + "y: " + data.y + "z: " + data.z);// 获取数据成功 }); } catch (error) { - console.error(error); + console.error("Get sensor data fail"); } ``` - ## 相关实例 针对传感器开发,有以下相关实例可供参考: diff --git a/zh-cn/application-dev/device/sensor-overview.md b/zh-cn/application-dev/device/sensor-overview.md index b7ac1a9a5a89a7ab80adb9e533e3493daa280ab7..9ddd92b21304953d41e930de86e31b4c3e601a28 100644 --- a/zh-cn/application-dev/device/sensor-overview.md +++ b/zh-cn/application-dev/device/sensor-overview.md @@ -8,10 +8,10 @@ OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽 | 传感器类型 | 描述 | 说明 | 主要用途 | | --------------------------------------- | --------- | ---------------------------------------- | -------------------- | -| SENSOR_TYPE_ACCELEROMETER | 加速度传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的加速度(包括重力加速度),单位 : m/s2 | 检测运动状态 | -| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | 未校准加速度传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的未校准的加速度(包括重力加速度),单位 : m/s2 | 检测加速度偏差估值 | -| SENSOR_TYPE_LINEAR_ACCELERATION | 线性加速度传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的线性加速度(不包括重力加速度),单位 : m/s2 | 检测每个单轴方向上的线性加速度 | -| SENSOR_TYPE_GRAVITY | 重力传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的重力加速度,单位 : m/s2 | 测量重力大小 | +| SENSOR_TYPE_ACCELEROMETER | 加速度传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的加速度(包括重力加速度),单位 : m/s² | 检测运动状态 | +| SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED | 未校准加速度传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的未校准的加速度(包括重力加速度),单位 : m/s² | 检测加速度偏差估值 | +| SENSOR_TYPE_LINEAR_ACCELERATION | 线性加速度传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的线性加速度(不包括重力加速度),单位 : m/s² | 检测每个单轴方向上的线性加速度 | +| SENSOR_TYPE_GRAVITY | 重力传感器 | 测量三个物理轴(x、y 和 z)上,施加在设备上的重力加速度,单位 : m/s² | 测量重力大小 | | SENSOR_TYPE_GYROSCOPE | 陀螺仪传感器 | 测量三个物理轴(x、y 和 z)上,设备的旋转角速度,单位 : rad/s | 测量旋转的角速度 | | SENSOR_TYPE_GYROSCOPE_UNCALIBRATED | 未校准陀螺仪传感器 | 测量三个物理轴(x、y 和 z)上,设备的未校准旋转角速度,单位 : rad/s | 测量旋转的角速度及偏差估值 | | SENSOR_TYPE_SIGNIFICANT_MOTION | 大幅度动作传感器 | 测量三个物理轴(x、y 和 z)上,设备是否存在大幅度运动;如果取值为1则代表存在大幅度运动,取值为0则代表没有大幅度运动 | 用于检测设备是否存在大幅度运动 | @@ -60,3 +60,4 @@ OpenHarmony传感器包含如下四个模块:Sensor API、Sensor Framework、S | 心率计 | ohos.permission.READ_HEALTH_DATA | user_grant | 允许读取健康数据 | 2. 传感器数据订阅和取消订阅接口成对调用,当不再需要订阅传感器数据时,开发者需要调用取消订阅接口停止数据上报。 + \ No newline at end of file diff --git a/zh-cn/application-dev/device/vibrator-guidelines.md b/zh-cn/application-dev/device/vibrator-guidelines.md index 4160018edfb53e3817f0d50053536c45daeedda1..6ba0789ca707b0034ee24c91b5e48e0d7fb5bc31 100644 --- a/zh-cn/application-dev/device/vibrator-guidelines.md +++ b/zh-cn/application-dev/device/vibrator-guidelines.md @@ -22,53 +22,18 @@ ## 开发步骤 -1. 控制设备上的振动器,需要在“config.json”里面进行配置请求权限。具体如下: - - ``` - ”reqPermissions“:[ - { - "name":"ohos.permission.ACCELEROMETER", - "reason"":"", - "usedScene":{ - "ability""[ - ".MainAbility" - ], - "when":"inuse" - } - }, - { - "name":"ohos.permission.VIBRATE", - "reason"":"", - "usedScene":{ - "ability""[ - ".MainAbility" - ], - "when":"inuse" - } - }, - { - "name":"ohos.permission.ACTIVITY_MOTION", - "reason"":"", - "usedScene":{ - "ability""[ - ".MainAbility" - ], - "when":"inuse" - } - }, - ] - ``` +1. 控制设备上的振动器,需要申请权限ohos.permission.VIBRATE。具体配置方式请参考[权限申请声明](../security/accesstoken-guidelines.md)。 2. 触发设备振动。 ``` import vibrator from "@ohos.vibrator" - vibrator.vibrate(1000).then((error)=>{ - if(error){//调用失败,打印error.code和error.message - console.log("Promise return failed.error.code"+error.code+"error.message"+error.message); - }else{//调用成功,设备开始振动 + vibrator.vibrate(1000).then((error) => { + if (error) { //调用失败,打印error.code和error.message + console.log("Promise return failed.error.code " + error.code + "error.message " + error.message); + } else { //调用成功,设备开始振动 console.log("Promise returned to indicate a successful vibration.") - }; + } }) ``` @@ -76,12 +41,12 @@ ``` import vibrator from "@ohos.vibrator" - vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then((error)=>{ - if(error){//调用失败,打印error.code和error.message - console.log("Promise return failed.error.code"+error.code+"error.message"+error.message); - }else{//调用成功,设备停止振动 - Console.log("Promise returned to indicate successful."); - }; + vibrator.stop(vibrator.VibratorStopMode.VIBRATOR_STOP_MODE_PRESET).then((error) => { + if (error) { //调用失败,打印error.code和error.message + console.log("Promise return failed.error.code " + error.code + "error.message " + error.message); + } else { //调用成功,设备停止振动 + console.log("Promise returned to indicate successful."); + } }) ``` diff --git a/zh-cn/application-dev/device/vibrator-overview.md b/zh-cn/application-dev/device/vibrator-overview.md index 11cec9fdec7c7cd0745edddb3e4a9f390fe78daf..bfed518954a85218102635a48808aab4146788b8 100644 --- a/zh-cn/application-dev/device/vibrator-overview.md +++ b/zh-cn/application-dev/device/vibrator-overview.md @@ -23,7 +23,7 @@ Vibrator属于控制类小器件,主要包含以下四个模块:Vibrator API ## 约束与限制 -在使用振动器时,开发者需要配置请求振动器的权限ohos.permission.VIBRATE,才能控制振动器振动,权限类型是system_grant。 +在使用振动器时,开发者需要配置请求振动器的权限ohos.permission.VIBRATE,才能控制振动器振动。 diff --git a/zh-cn/application-dev/notification/background-agent-scheduled-reminder-guide.md b/zh-cn/application-dev/notification/background-agent-scheduled-reminder-guide.md index e79fc69f643862d720a36ee4c583c7254b8dbc7a..0ea89600622550d5f87c4af4c65e119011665ccf 100644 --- a/zh-cn/application-dev/notification/background-agent-scheduled-reminder-guide.md +++ b/zh-cn/application-dev/notification/background-agent-scheduled-reminder-guide.md @@ -1,4 +1,4 @@ -# 后台提醒开发指导 +# 后台代理提醒开发指导 ## 场景介绍 @@ -37,9 +37,7 @@ reminderAgent:封装了发布、取消提醒类通知的方法。 import reminderAgent from '@ohos.reminderAgent'; import notification from '@ohos.notification'; export default { - // JS工程写法: - // timer: { - // eTS工程写法: + // eTS工程: let timer : reminderAgent.ReminderRequestTimer = { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, triggerTimeInSeconds: 10, @@ -69,9 +67,7 @@ reminderAgent:封装了发布、取消提醒类通知的方法。 日历实例定义: ```js - // JS工程写法: - // calendar: { - // eTS工程写法: + // eTS工程: let calendar : reminderAgent.ReminderRequestCalendar = { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR, dateTime: { @@ -117,9 +113,7 @@ reminderAgent:封装了发布、取消提醒类通知的方法。 闹钟实例定义: ```js - // JS工程写法: - // alarm: { - // eTS工程写法: + // eTS工程: let alarm : reminderAgent.ReminderRequestAlarm = { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, hour: 11, diff --git a/zh-cn/application-dev/quick-start/start-overview.md b/zh-cn/application-dev/quick-start/start-overview.md index 4a341e529b40154f3b79a35b3682b84d032691b6..e3140e663309335d63bb76c993ca646b91631942 100644 --- a/zh-cn/application-dev/quick-start/start-overview.md +++ b/zh-cn/application-dev/quick-start/start-overview.md @@ -16,12 +16,13 @@ OpenHarmony提供了一套UI开发框架,即方舟开发框架(ArkUI框架)。方舟开发框架可为开发者提供应用UI开发所必需的能力,比如多种组件、布局计算、动画能力、UI交互、绘制等。 -方舟开发框架针对不同目的和技术背景的开发者提供了两种开发范式,分别是基于JS扩展的类Web开发范式(简称“类Web开发范式”)和基于TS扩展的声明式开发范式(简称“声明式开发范式”)。以下是两种开发范式的简单对比。 +方舟开发框架针对不同目的和技术背景的开发者提供了两种开发范式,分别是基于eTS的声明式开发范式(简称“声明式开发范式”)和兼容JS的类Web开发范式(简称“类Web开发范式”)。以下是两种开发范式的简单对比。 | **开发范式名称** | **语言生态** | **UI更新方式** | **适用场景** | **适用人群** | | -------- | -------- | -------- | -------- | -------- | +| 声明式开发范式 | eTS语言 | 数据驱动更新 | 复杂度较大、团队合作度较高的程序 | 移动系统应用开发人员、系统应用开发人员 | | 类Web开发范式 | JS语言 | 数据驱动更新 | 界面较为简单的程序应用和卡片 | Web前端开发人员 | -| 声明式开发范式 | 扩展的TS语言(eTS) | 数据驱动更新 | 复杂度较大、团队合作度较高的程序 | 移动系统应用开发人员、系统应用开发人员 | + 对于JS语言开发时,低代码方式在DevEco Studio V2.2 Beta1及更高版本中支持。 diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0001.gif b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0001.gif new file mode 100644 index 0000000000000000000000000000000000000000..fc737da287358cd81c65567e17da1bd4d701edff Binary files /dev/null and b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0001.gif differ diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0002.gif b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0002.gif new file mode 100644 index 0000000000000000000000000000000000000000..9e3ff82c3de3a8867949b0d65aa4ffe55360e7cb Binary files /dev/null and b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0002.gif differ diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0004.gif b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0004.gif new file mode 100644 index 0000000000000000000000000000000000000000..3b8462cf93c07e4b92c250bcb46409cc81e5129f Binary files /dev/null and b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0004.gif differ diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0005.gif b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0005.gif new file mode 100644 index 0000000000000000000000000000000000000000..2bb6aa6c2a2086f16ae6149e9d3e4b2340d6fe37 Binary files /dev/null and b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0005.gif differ diff --git a/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0006.gif b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0006.gif new file mode 100644 index 0000000000000000000000000000000000000000..2bb6aa6c2a2086f16ae6149e9d3e4b2340d6fe37 Binary files /dev/null and b/zh-cn/application-dev/reference/apis/figures/zh-cn_image_0006.gif differ diff --git a/zh-cn/application-dev/reference/apis/js-apis-Context.md b/zh-cn/application-dev/reference/apis/js-apis-Context.md index 8404d21f0912af47ecb183483a22fcff93d43f5d..b060ec1553fbf0db1f02cbbf937d3d8899d42a1a 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-Context.md +++ b/zh-cn/application-dev/reference/apis/js-apis-Context.md @@ -929,6 +929,53 @@ import featureAbility from '@ohos.ability.featureAbility' var context = featureAbility.getContext().getApplicationContext(); ``` +## Context.getExternalCacheDir + +getExternalCacheDir(callback: AsyncCallback\): void + +获取应用程序的外部缓存目录(callback形式)。 + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**参数:** + +| 名称 | 类型 | 必填 | 描述 | +| -------- | ---------------------- | ---- | ------------------ | +| callback | AsyncCallback\ | 是 | 返回应用程序的缓存目录的绝对路径。 | + +**示例:** + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getExternalCacheDir() +``` + +## Context.getExternalCacheDir + +getExternalCacheDir(): Promise\; + +获取应用程序的外部缓存目录(Promise形式)。 + +**系统能力**:SystemCapability.Ability.AbilityRuntime.Core + +**返回值:** + +| 类型 | 说明 | +| ---------------- | ---------------- | +| Promise\ | 返回应用程序的缓存目录的绝对路径。 | + +**示例:** + +```js +import featureAbility from '@ohos.ability.featureAbility' +var context = featureAbility.getContext(); +context.getExternalCacheDir().then((data) => { + console.info("=======================>getExternalCacheDirCallback====================>"); + console.info("====>data====>" + JSON.stringify(data)); +}); +``` + ## PermissionOptions **系统能力**:SystemCapability.Ability.AbilityRuntime.Core diff --git a/zh-cn/application-dev/reference/apis/js-apis-prompt.md b/zh-cn/application-dev/reference/apis/js-apis-prompt.md index fb04353173252c684eb05d1341f46f82a6cb13ac..64b154d5804aba6e8cf59848d1131733e1922d90 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-prompt.md +++ b/zh-cn/application-dev/reference/apis/js-apis-prompt.md @@ -35,6 +35,8 @@ prompt.showToast({ }); ``` + ![zh-cn_image_0001](figures/zh-cn_image_0001.gif) + ## ShowToastOptions 文本提示框的选项。 @@ -92,6 +94,8 @@ prompt.showDialog({ }) ``` + ![zh-cn_image_0002](figures/zh-cn_image_0002.gif) + ## prompt.showDialog showDialog(options: ShowDialogOptions, callback: AsyncCallback<ShowDialogSuccessResponse>):void @@ -132,6 +136,8 @@ prompt.showDialog({ }); ``` + ![zh-cn_image_0004](figures/zh-cn_image_0004.gif) + ## ShowDialogOptions 对话框的选项。 @@ -195,6 +201,8 @@ prompt.showActionMenu({ }) ``` + ![zh-cn_image_0005](figures/zh-cn_image_0005.gif) + ## prompt.showActionMenu showActionMenu(options: ActionMenuOptions): Promise<ActionMenuSuccessResponse> @@ -238,6 +246,8 @@ prompt.showActionMenu({ console.info('showActionMenu error: ' + err); }) ``` + ![zh-cn_image_0006](figures/zh-cn_image_0006.gif) + ## ActionMenuOptions 操作菜单的选项。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-url.md b/zh-cn/application-dev/reference/apis/js-apis-url.md index d85642ef859b8cae2765234923257bd7b640268c..44b873ad803829f77a47b79878496e9eaab5e92f 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-url.md +++ b/zh-cn/application-dev/reference/apis/js-apis-url.md @@ -25,16 +25,16 @@ URLSearchParams的构造函数。 | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | -| init | string[][] \| Record<string, string> \| string \| URLSearchParams | 否 | 入参对象。
- string[][]:字符串二维数组
- Record<string, string>:对象列表
- string:字符串
- URLSearchParams:对象 | +| init | string[][] \| Record<string, string> \| string \| URLSearchParams | 否 | 入参对象。
- string[][]:字符串二维数组
- Record<string, string>:对象列表
- string:字符串
- URLSearchParams:对象 | **示例:** ```js -var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); -var objectParams1 = new Url.URLSearchParams({"fod" : 1 , "bard" : 2}); -var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); -var urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); -var params = new Url.URLSearchParams(urlObject.search); +let objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); +let objectParams1 = new Url.URLSearchParams({"fod" : '1' , "bard" : '2'}); +let objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); +let urlObject = new Url.URL('https://developer.mozilla.org/?fod=1&bard=2'); +let params = new Url.URLSearchParams(urlObject.search); ``` @@ -58,7 +58,7 @@ append(name: string, value: string): void ```js let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); -paramsObject.append('fod', 3); +paramsObject.append('fod', '3'); ``` @@ -108,10 +108,10 @@ getAll(name: string): string[] **示例:** ```js -let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); -let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); -paramsObject.append('fod', 3); // Add a second value for the fod parameter. -console.log(params.getAll('fod')) // Output ["1","3"]. +let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); +let params = new Url.URLSearchParams(urlObject.search.slice(1)); +params.append('fod', '3'); // Add a second value for the fod parameter. +console.log(params.getAll('fod').toString()) // Output ["1","3"]. ``` @@ -127,12 +127,12 @@ entries(): IterableIterator<[string, string]> | 类型 | 说明 | | -------- | -------- | -| IterableIterator<[string, string]> | 返回一个ES6的迭代器。 | +| IterableIterator<[string, string]> | 返回一个ES6的迭代器。 | **示例:** ```js -var searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); +let searchParamsObject = new Url.URLSearchParams("keyName1=valueName1&keyName2=valueName2"); for (var pair of searchParamsObject .entries()) { // Show keyName/valueName pairs console.log(pair[0]+ ', '+ pair[1]); } @@ -191,15 +191,14 @@ get(name: string): string | null | 类型 | 说明 | | -------- | -------- | | string | 返回第一个值。 | -| null | 如果没找到,返回 null。 | +| null | 如果没找到,返回 null。 | **示例:** ```js -var paramsOject = new Url.URLSearchParams(document.location.search.substring(1)); -var name = paramsOject.get("name"); // is the string "Jonathan" -var age = parseInt(paramsOject.get("age"), 10); // is the number 18 -var address = paramsOject.get("address"); // null +let paramsObject = new Url.URLSearchParams('name=Jonathan&age=18'); +let name = paramsObject.get("name"); // is the string "Jonathan" +let age = parseInt(paramsObject.get("age"), 10); // is the number 18 ``` @@ -252,7 +251,7 @@ set(name: string, value: string): void ```js let urlObject = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)); -paramsObject.set('baz', 3); // Add a third parameter. +paramsObject.set('baz', '3'); // Add a third parameter. ``` @@ -267,7 +266,7 @@ sort(): void **示例:** ```js -var searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object +let searchParamsObject = new Url.URLSearchParams("c=3&a=9&b=4&d=2"); // Create a test URLSearchParams object searchParamsObject.sort(); // Sort the key/value pairs console.log(searchParamsObject.toString()); // Display the sorted query string // Output a=9&b=2&c=3&d=4 ``` @@ -290,7 +289,7 @@ keys(): IterableIterator<string> **示例:** ```js -var searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +let searchParamsObject = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing for (var key of searchParamsObject .keys()) { // Output key-value pairs console.log(key); } @@ -314,8 +313,8 @@ values(): IterableIterator<string> **示例:** ```js -var searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing -for (var value of searchParams.values()) { +let searchParams = new Url.URLSearchParams("key1=value1&key2=value2"); // Create a URLSearchParamsObject object for testing +for (var value of searchParams.values()) { console.log(value); } ``` @@ -333,13 +332,13 @@ for (var value of searchParams.values()) { | 类型 | 说明 | | -------- | -------- | -| IterableIterator<[string, string]> | 返回一个ES6的迭代器。 | +| IterableIterator<[string, string]> | 返回一个ES6的迭代器。 | **示例:** ```js const paramsObject = new Url.URLSearchParams('fod=bay&edg=bap'); -for (const [name, value] of paramsObject) { +for (const [name, value] of paramsObject) { console.log(name, value); } ``` @@ -364,7 +363,7 @@ toString(): string ```js let url = new Url.URL('https://developer.exampleUrl/?fod=1&bard=2'); let params = new Url.URLSearchParams(url.search.slice(1)); -params.append('fod', 3); +params.append('fod', '3'); console.log(params.toString()); ``` @@ -404,16 +403,16 @@ URL的构造函数。 | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | url | string | 是 | 入参对象。 | -| base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | +| base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | **示例:** ```js -var mm = 'http://username:password@host:8080'; -var a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; -var b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; +let mm = 'http://username:password@host:8080'; +let a = new Url.URL("/", mm); // Output 'http://username:password@host:8080/'; +let b = new Url.URL(mm); // Output 'http://username:password@host:8080/'; new Url.URL('path/path1', b); // Output 'http://username:password@host:8080/path/path1'; -var c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; +let c = new Url.URL('/path/path1', b); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', c); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', a); // Output 'http://username:password@host:8080/path/path1'; new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 @@ -442,7 +441,7 @@ toString(): string ```js const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toString() +url.toString(); ``` @@ -463,5 +462,5 @@ toJSON(): string **示例:** ```js const url = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toJSON() +url.toJSON(); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-util.md b/zh-cn/application-dev/reference/apis/js-apis-util.md index c0a79872d031576a7ebefe61a5b172b10d02f1c4..5ea6ca647065aa86029b5a3cbb6e8b7ce56a5421 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-util.md +++ b/zh-cn/application-dev/reference/apis/js-apis-util.md @@ -140,7 +140,7 @@ promiseWrapper(original: (err: Object, value: Object) => void): Object | 名称 | 参数类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | -| encoding | string | 是 | 否 | 编码格式。
- 支持格式:utf-8、ibm866、iso-8859-2、iso-8859-3、iso-8859-4、iso-8859-5、iso-8859-6、iso-8859-7、iso-8859-8、iso-8859-8-i、iso-8859-10、iso-8859-13、iso-8859-14、iso-8859-15、koi8-r、koi8-u、macintosh、windows-874、windows-1250、windows-1251、windows-1252、windows-1253、windows-1254、windows-1255、windows-1256、windows-1257、windows-1258、x-mac-cyrilli、gbk、gb18030、big5、euc-jp、iso-2022-jp、shift_jis、euc-kr、utf-16be、utf-16le。 | +| encoding | string | 是 | 否 | 编码格式。
- 支持格式:utf-8。 | | fatal | boolean | 是 | 否 | 是否显示致命错误。 | | ignoreBOM | boolean | 是 | 否 | 是否忽略BOM(byte order marker)标记,默认值为false ,表示解码结果包含BOM标记。 | diff --git a/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238952377.png b/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238952377.png new file mode 100644 index 0000000000000000000000000000000000000000..eb03ebe25132eb551b633d052cdfc984eda432ee Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-js/figures/zh-cn_image_0000001238952377.png differ diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-basic-button.md b/zh-cn/application-dev/reference/arkui-js/js-components-basic-button.md index 2470492c22ed4bfcbf86f4011e230e13dd2dfa27..49040e95f95cac8596408fb800473c8c0fb8ce9a 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-basic-button.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-basic-button.md @@ -43,17 +43,10 @@ | icon-height | <length> | - | 否 | 设置圆形按钮内部图标的高,默认填满整个圆形按钮。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> icon使用svg图源时必须设置该样式。 | | radius | <length> | - | 否 | 按钮圆角半径。在圆形按钮类型下该样式优先于通用样式的width和height样式。 | -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> - 胶囊按钮(type=capsule)时,不支持border相关样式; -> -> - 圆形按钮(type=circle)时,不支持文本相关样式; -> -> - 文本按钮(type=text)时,自适应文本大小,不支持尺寸设置(radius,width,height),背景透明不支持background-color样式。 - ### type设置为arc -除支持[通用样式](../arkui-js/js-components-common-styles.md)中background-color、opacity、display、visibility、position、[left|top|right|bottom外,还支持如下样式: +除支持[通用样式](../arkui-js/js-components-common-styles.md)中background-color、opacity、display、visibility、position、[left|top|right|bottom]外,还支持如下样式: | 名称 | 类型 | 默认值 | 必填 | 描述 | | -------- | -------- | -------- | -------- | -------- | diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-basic-piece.md b/zh-cn/application-dev/reference/arkui-js/js-components-basic-piece.md index 6052a8fea067fd39a6870faad84d93c0f80546f1..cbf3e14451c1f196726dbf3e612a7891d5804a2e 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-basic-piece.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-basic-piece.md @@ -1,10 +1,10 @@ # piece +一种块状的入口,可包含图片和文本。常用于展示收件人,例如:邮件收件人或信息收件人。 + > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > 从API version 5开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -一种块状的入口,可包含图片和文本。常用于展示收件人,例如:邮件收件人或信息收件人。 - ## 子组件 diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-basic-span.md b/zh-cn/application-dev/reference/arkui-js/js-components-basic-span.md index 1c8e3af694f3bbe4bbad43fb87d29072efd44cc2..c5651d7d84156d7639b989d4e58687dbc109ede0 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-basic-span.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-basic-span.md @@ -12,7 +12,7 @@ ## 子组件 -支持子组件<span>。 +无 ## 属性 diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-basic-toggle.md b/zh-cn/application-dev/reference/arkui-js/js-components-basic-toggle.md index a4693c14a7e68d09d545dc88d3bdebcedf20cc15..59b58bcf45b5c794595a5d8a6a934d79512a3a0c 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-basic-toggle.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-basic-toggle.md @@ -56,7 +56,7 @@ ## 示例 -``` +```html
1. Multiple choice example @@ -71,44 +71,61 @@
``` -``` +```css /* xxx.css */ .margin { margin: 7px; } ``` -``` +```js // xxx.js export default { - data: { - toggle_list: [ - { "id":"1001", "name":"Living room", "checked":true }, - { "id":"1002", "name":"Bedroom", "checked":false }, - { "id":"1003", "name":"Second bedroom", "checked":false }, - { "id":"1004", "name":"Kitchen", "checked":false }, - { "id":"1005", "name":"Study", "checked":false }, - { "id":"1006", "name":"Garden", "checked":false }, - { "id":"1007", "name":"Bathroom", "checked":false }, - { "id":"1008", "name":"Balcony", "checked":false }, - ], - toggles: ["Living room","Bedroom","Kitchen","Study"], - idx: "" - }, - allclick(arg) { - this.idx = arg - }, - allchange(e) { - if (e.checked === true) { - for (var i = 0; i < this.toggle_list.length; i++) { - if (this.toggle_list[i].id === this.idx) { - this.toggle_list[i].checked = true - } else { - this.toggle_list[i].checked = false + data: { + toggle_list: [ + { + "id": "1001", "name": "Living room", "checked": true + }, + { + "id": "1002", "name": "Bedroom", "checked": false + }, + { + "id": "1003", "name": "Second bedroom", "checked": false + }, + { + "id": "1004", "name": "Kitchen", "checked": false + }, + { + "id": "1005", "name": "Study", "checked": false + }, + { + "id": "1006", "name": "Garden", "checked": false + }, + { + "id": "1007", "name": "Bathroom", "checked": false + }, + { + "id": "1008", "name": "Balcony", "checked": false + }, + ], + toggles: ["Living room", "Bedroom", "Kitchen", "Study"], + idx: "" + }, + allclick(arg) { + this.idx = arg; + }, + allchange(e) { + if (e.checked != true) { + return; + } + for (var i = 0; i < this.toggle_list.length; i++) { + if (this.toggle_list[i].id === this.idx) { + this.toggle_list[i].checked = true; + } else { + this.toggle_list[i].checked = false; + } } - } } - } } ``` diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-basic-toolbar-item.md b/zh-cn/application-dev/reference/arkui-js/js-components-basic-toolbar-item.md index 21e0b16883e8065fa81dc2473a4382d8f9a956d4..d6b269a09543c379be402082f96bf2591362d683 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-basic-toolbar-item.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-basic-toolbar-item.md @@ -3,7 +3,7 @@ > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > 从API version 5开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -工具栏子组件。作为工具栏组件的子组件,用于展示工具栏上的一个操作选项。 + 工具栏[toolbar](js-components-basic-toolbar.md)子组件。 用于展示工具栏上的一个操作选项。 ## 子组件 @@ -57,15 +57,15 @@ ## 示例 -``` +```html - - - - - - - + + + + + + + ``` diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-container-dialog.md b/zh-cn/application-dev/reference/arkui-js/js-components-container-dialog.md index 3a5e23868d8e342c261f6e6ae1440ff2be1148db..0861906137dec516a47acda3fc65b2ca0c0469c1 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-container-dialog.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-container-dialog.md @@ -132,27 +132,27 @@ // xxx.js import prompt from '@system.prompt'; export default { - showDialog(e) { + showDialog() { this.$element('simpledialog').show() }, - cancelDialog(e) { + cancelDialog() { prompt.showToast({ message: 'Dialog cancelled' }) }, - cancelSchedule(e) { + cancelSchedule() { this.$element('simpledialog').close() prompt.showToast({ message: 'Successfully cancelled' }) }, - setSchedule(e) { + setSchedule() { this.$element('simpledialog').close() prompt.showToast({ message: 'Successfully confirmed' }) }, - doubleclick(e){ + doubleclick(){ prompt.showToast({ message: 'doubleclick' }) diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-container-list-item-group.md b/zh-cn/application-dev/reference/arkui-js/js-components-container-list-item-group.md index d11f2880032400ea6ee0152a2902820d519ab181..51932894a3f1faef6fe36c0885f290ba5ad82f74 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-container-list-item-group.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-container-list-item-group.md @@ -127,7 +127,8 @@ import prompt from '@system.prompt'; export default { data: { direction: 'column', - list: [] + list: [], + listAdd: [] }, onInit() { this.list = [] diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-container-stepper.md b/zh-cn/application-dev/reference/arkui-js/js-components-container-stepper.md index 9013c0a9d49a0eebdaed3f178df6810a89db1676..9481ba0c25f4bee0a81454b6217f29c23a2f4905 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-container-stepper.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-container-stepper.md @@ -95,6 +95,7 @@ height: 300px; } .stepperItem { + width: 100%; flex-direction: column; align-items: center; } diff --git a/zh-cn/application-dev/reference/arkui-js/js-components-container-swiper.md b/zh-cn/application-dev/reference/arkui-js/js-components-container-swiper.md index b017870ad7902efcdddb87bb6ca136bc1faefcf8..42c0f3f3c289d37cd75ba35635e398f003fd90b7 100644 --- a/zh-cn/application-dev/reference/arkui-js/js-components-container-swiper.md +++ b/zh-cn/application-dev/reference/arkui-js/js-components-container-swiper.md @@ -12,7 +12,7 @@ ## 子组件 -支持除<list>之外的子组件。 +可以包含子组件。 ## 属性 diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/Column.png b/zh-cn/application-dev/reference/arkui-ts/figures/Column.png deleted file mode 100644 index 90bb7a5557e42ccc9b6509f96f54328d7a27eea1..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/Column.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/Row.png b/zh-cn/application-dev/reference/arkui-ts/figures/Row.png deleted file mode 100644 index 6bf426a5f019e76b7b3a0953643988690eb67b1e..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/Row.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/align.png b/zh-cn/application-dev/reference/arkui-ts/figures/align.png new file mode 100644 index 0000000000000000000000000000000000000000..beed805dbff1ec1526bf034c011cf2c7b926eae8 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/align.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/badge.png b/zh-cn/application-dev/reference/arkui-ts/figures/badge.png new file mode 100644 index 0000000000000000000000000000000000000000..0041374b52a2be5a93f620dabed0cba74990ee6f Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/badge.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/blankmin.png b/zh-cn/application-dev/reference/arkui-ts/figures/blankmin.png new file mode 100644 index 0000000000000000000000000000000000000000..d37582ff571d36ecc41539453192955b84481765 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/blankmin.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup.gif b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup.gif deleted file mode 100644 index 5d4c6e059f96d3f021f100ffb7c9899630f982ee..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup1.png b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup1.png new file mode 100644 index 0000000000000000000000000000000000000000..7042b41c96d5eca395d4ac035fefb7d55347535d Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup1.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup2.png b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup2.png new file mode 100644 index 0000000000000000000000000000000000000000..7d7a2b901873cf2daedd412b96508b6c40aa0244 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup2.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup3.png b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup3.png new file mode 100644 index 0000000000000000000000000000000000000000..53988fae3e8f660fd8411ef44bfa2dc983886a5e Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/checkboxgroup3.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/focus.png b/zh-cn/application-dev/reference/arkui-ts/figures/focus.png new file mode 100644 index 0000000000000000000000000000000000000000..dcd16fbecdce07e04721915ff9d9777590d39e7a Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/focus.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/gauge-image.png b/zh-cn/application-dev/reference/arkui-ts/figures/gauge-image.png new file mode 100644 index 0000000000000000000000000000000000000000..d8fa99c3cc70ca08914a3850d95d2511eff923cd Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/gauge-image.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor1.png b/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor1.png new file mode 100644 index 0000000000000000000000000000000000000000..b82f81358cd03243b99ac23b6eb190238bf22f0b Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor1.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor2.png b/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor2.png new file mode 100644 index 0000000000000000000000000000000000000000..c50424c9fd41bdda195affb5170cac38bd3df0e5 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor2.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor3.png b/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor3.png new file mode 100644 index 0000000000000000000000000000000000000000..84d9674c5b43486a260ca9e1c9b1017b9022583c Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/gradientColor3.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/gridSpan.png b/zh-cn/application-dev/reference/arkui-ts/figures/gridSpan.png new file mode 100644 index 0000000000000000000000000000000000000000..80b67bee5bc99e753a2176ce2544b572ca41243e Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/gridSpan.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/imageeffect.png b/zh-cn/application-dev/reference/arkui-ts/figures/imageeffect.png new file mode 100644 index 0000000000000000000000000000000000000000..fbcc0c6b68235aa7306556030fc60fed716b26b4 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/imageeffect.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/mouse.png b/zh-cn/application-dev/reference/arkui-ts/figures/mouse.png new file mode 100644 index 0000000000000000000000000000000000000000..28baf4e713b69b4bea0e9ed3498a4a2ce12fc2b3 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/mouse.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/mouse1.png b/zh-cn/application-dev/reference/arkui-ts/figures/mouse1.png new file mode 100644 index 0000000000000000000000000000000000000000..dc3ea1fb958f1de66f6310e22b6163ebfbfb7494 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/mouse1.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/nozindex.png b/zh-cn/application-dev/reference/arkui-ts/figures/nozindex.png new file mode 100644 index 0000000000000000000000000000000000000000..8c131eabacb8bcdee0b8ba891faaab69bb2a08bd Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/nozindex.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/opacity.png b/zh-cn/application-dev/reference/arkui-ts/figures/opacity.png new file mode 100644 index 0000000000000000000000000000000000000000..d95114ede941db77cf865d3fab288f602ddcc1d0 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/opacity.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/popup.gif b/zh-cn/application-dev/reference/arkui-ts/figures/popup.gif new file mode 100644 index 0000000000000000000000000000000000000000..b32a43bd8fc4ae6416b8402c61e1d8e3b9e694ef Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/popup.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/position.png b/zh-cn/application-dev/reference/arkui-ts/figures/position.png new file mode 100644 index 0000000000000000000000000000000000000000..0c9e34bf611b4d51a49875d71f23fef24d6e2571 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/position.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/progress.png b/zh-cn/application-dev/reference/arkui-ts/figures/progress.png new file mode 100644 index 0000000000000000000000000000000000000000..d50f4b47628b425b09f93bc9a44853ad79e12631 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/progress.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/qrcode.png b/zh-cn/application-dev/reference/arkui-ts/figures/qrcode.png new file mode 100644 index 0000000000000000000000000000000000000000..762c952314fc6e52bbbc0ae55565422c40d05ff0 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/qrcode.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/richText.png b/zh-cn/application-dev/reference/arkui-ts/figures/richText.png new file mode 100644 index 0000000000000000000000000000000000000000..1520a854a9baed9fcc4e50e989bbfb4e83acf487 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/richText.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/search.gif b/zh-cn/application-dev/reference/arkui-ts/figures/search.gif new file mode 100644 index 0000000000000000000000000000000000000000..1b4847e0debeea617d8ea9af34112dca636651f2 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/search.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/search.png b/zh-cn/application-dev/reference/arkui-ts/figures/search.png deleted file mode 100644 index fddf98d7104f3bd8a370b5be86da322834ff0180..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/search.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/size.png b/zh-cn/application-dev/reference/arkui-ts/figures/size.png new file mode 100644 index 0000000000000000000000000000000000000000..5170abe9fb68747018cecc57e27df68806bafac4 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/size.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/span.png b/zh-cn/application-dev/reference/arkui-ts/figures/span.png new file mode 100644 index 0000000000000000000000000000000000000000..881f4945dac79e31cb9f11216a682110de4efec7 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/span.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/textExp1.png b/zh-cn/application-dev/reference/arkui-ts/figures/textExp1.png new file mode 100644 index 0000000000000000000000000000000000000000..15d8410388040337f52a039f946d20f3cc0504fc Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/textExp1.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/textExp2.png b/zh-cn/application-dev/reference/arkui-ts/figures/textExp2.png new file mode 100644 index 0000000000000000000000000000000000000000..f6d1aa365e071f3064e25fe45afa4ce4efcddb65 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/textExp2.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/text_clock.gif b/zh-cn/application-dev/reference/arkui-ts/figures/text_clock.gif new file mode 100644 index 0000000000000000000000000000000000000000..29a32d79a14fbcf8a27f6e27fc3fa226a2b83446 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/text_clock.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/text_clock.png b/zh-cn/application-dev/reference/arkui-ts/figures/text_clock.png deleted file mode 100644 index 7d8b74289c00f8d8cc8e53482a96bf3281c841e3..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/text_clock.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/textblur.png b/zh-cn/application-dev/reference/arkui-ts/figures/textblur.png new file mode 100644 index 0000000000000000000000000000000000000000..cd151a5e84516952ec7db39c2abd2a1524f728db Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/textblur.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/textstyle.png b/zh-cn/application-dev/reference/arkui-ts/figures/textstyle.png new file mode 100644 index 0000000000000000000000000000000000000000..38128cb5f1a6aa7a36a3b4e483bf2815c7170117 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/textstyle.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/touchtarget.gif b/zh-cn/application-dev/reference/arkui-ts/figures/touchtarget.gif new file mode 100644 index 0000000000000000000000000000000000000000..550dfe998ac31230b52ff3972974cdd4a7431b28 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/touchtarget.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/visibility.png b/zh-cn/application-dev/reference/arkui-ts/figures/visibility.png new file mode 100644 index 0000000000000000000000000000000000000000..89018fade9d9bef19dfc8a55d4477ba309353871 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/visibility.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001174104384.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001174104384.png new file mode 100644 index 0000000000000000000000000000000000000000..e13e20f195beab0c37dbcd33583dc5af1d8098ea Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001174104384.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001174264374.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001174264374.png new file mode 100644 index 0000000000000000000000000000000000000000..111a72e40d95524d0dfea95d6a0d926f46c2255a Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001174264374.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001184628104.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001184628104.png new file mode 100644 index 0000000000000000000000000000000000000000..80879c86fff48d1ed267c93bcc35f99e489103e0 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001184628104.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001219982725.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001219982725.png new file mode 100644 index 0000000000000000000000000000000000000000..b980148e07e0d6d9f42b0df75766da9cbfe09840 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image1_0000001219982725.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image2_0000001184628104.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image2_0000001184628104.png new file mode 100644 index 0000000000000000000000000000000000000000..67894b933c7d1470582a827bbc1aec5fb123e1f2 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image2_0000001184628104.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642010.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642010.gif new file mode 100644 index 0000000000000000000000000000000000000000..3b98469c99c310c291bb45eb2a7a89c73ef0bee3 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642010.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642020.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642020.gif new file mode 100644 index 0000000000000000000000000000000000000000..17a85e429e717138ae47456e080664856eb676a0 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642020.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642500.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642500.gif new file mode 100644 index 0000000000000000000000000000000000000000..2a6cf73b491304e3f53cb0a333588cad2e42f30b Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001118642500.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104384.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104384.gif deleted file mode 100644 index 0213b777e0352ac7830bde7d9bff40edf69a1a51..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104384.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104384.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104384.png new file mode 100644 index 0000000000000000000000000000000000000000..cbd85c4f6340743af87cb7210e2181def3d7c7b1 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104384.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104390.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104390.gif deleted file mode 100644 index fe69ab973cfd17f540dd1da4fd04de890af95c74..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104390.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104392.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104392.gif deleted file mode 100644 index ee69d15a36eda3047be045a3d037fd27a37166fe..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104392.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104394.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104394.png index b85ac72fcec0f4b2eb752307d4abe05ef4795ef2..3d9d5916e4dd08a6190848d402dcd1b6540ec613 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104394.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174104394.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264364.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264364.gif deleted file mode 100644 index acbeb39682258aa37a6162230fa5b5bd1ed6a226..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264364.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264364.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264364.png new file mode 100644 index 0000000000000000000000000000000000000000..defa53e2581a56c7fb0933d85c0ce1578ebbfd48 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264364.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264368.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264368.gif deleted file mode 100644 index 3174da059167d3560a99d50cca06ec678cabed96..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264368.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264372.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264372.gif deleted file mode 100644 index 323cd3b5bf1913f6740db4ce2203a07fcb30fb5e..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264372.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264372.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264372.png new file mode 100644 index 0000000000000000000000000000000000000000..3a47b72b0963c84b20b208c0806f7813c7ce652b Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264372.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264374.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264374.gif deleted file mode 100644 index d98a4ebc55b1fbc7c598a08095f871f4c3ab8678..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264374.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264374.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264374.png new file mode 100644 index 0000000000000000000000000000000000000000..4e244b1e2a26df6279a5f3558477069954c7bc12 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264374.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264380.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264380.gif index 41a08cbcc0e58aadc12328ab72a8ec3f01a375ad..1a5cf3b55ce3eabed1efbc9c1bf82ee5ad62177b 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264380.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264380.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264384.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264384.gif deleted file mode 100644 index dffa33c4389c4576d2492cd98499b71715b8ead8..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264384.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264386.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264386.png index ad2c71e4bcc008c0d286a05b2e969103aa06236d..2ff75f958a860f1ed483d799e2ef6431fbce5a74 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264386.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174264386.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422900.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422900.gif index 33a9b7c1a5a408a94cd58261742a29dc7519d880..9164d80285765dd97ef3a9d2d22bda3b4d34e86f 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422900.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422900.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422916.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422916.png deleted file mode 100644 index 2eb96b00f11e597fcc3e3d5ef32701e0a4ef5f5b..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422916.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422918.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422918.gif deleted file mode 100644 index 8b359a2d036a69fd442145d55e23031755c925c1..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174422918.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582848.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582848.gif deleted file mode 100644 index d5b827457bbb9fbb12c8d1cbee4886dede46a048..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582848.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582848.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582848.png new file mode 100644 index 0000000000000000000000000000000000000000..a5c155b70174d682f3536fa2b23381e1ce9c9361 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582848.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582856.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582856.gif deleted file mode 100644 index 78e7436bf654889a3a04e9d2e5dd53f5fb562906..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582856.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582856.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582856.png new file mode 100644 index 0000000000000000000000000000000000000000..837f6723b62e7402ba6e240372bd3de88e2ff0f6 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582856.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582860.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582860.png deleted file mode 100644 index 92ddc7d5d9ee2f87128ed8951b2294ea3c07f650..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001174582860.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001179613854.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001179613854.gif index b1724791e4acb31d193a0dce267e42c99288c6bd..aed89b3e86f0846762b81c0e40512d77260c8db7 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001179613854.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001179613854.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184400598.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184400598.gif deleted file mode 100644 index e97b2a2406059ce3af77ade27bb634845d807726..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184400598.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184628104.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184628104.png index e766d36181c3d1fbd96bb0acab1b3eb670e14cd4..8f23571d332303deff7085c23f28fbe759beb16f 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184628104.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001184628104.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001187055946.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001187055946.gif deleted file mode 100644 index 7631bb0d995839d59a9d3876f91fd7e688c35758..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001187055946.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001198839004.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001198839004.gif deleted file mode 100644 index b0667769e77a2a2d1b131736bdce96489b7e064e..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001198839004.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001209874754.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001209874754.gif index f0962619f5df0fec543cd693195045c9203378d9..e83d5b33f9b10e586aa2288f6271c51fd79fab47 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001209874754.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001209874754.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210195016.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210195016.gif index 7b839683df88c833812ce75bd656abd22dae950f..d54284f0f1e155f0b3ca105ca9095cd01c95d988 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210195016.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210195016.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210353788.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210353788.gif index b8a7961adce1b592b8fdbce98966c70cf1da68e8..38ffa5ca3c66dc3852f3a6045789473e8bdb0c41 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210353788.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001210353788.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662647.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662647.gif deleted file mode 100644 index b0e5e55e1af19bb46a74300bf2ae60f95225a874..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662647.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662669.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662669.png deleted file mode 100644 index 6b2c6040690cebf054da6dbc70c87d14c82be9d6..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662669.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662673.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662673.png deleted file mode 100644 index 5499902761b534f84a0405094afe2fb5d4724322..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219662673.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744185.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744185.gif deleted file mode 100644 index 49167ceae5eb50a96334c73496ed534d25bbecf4..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744185.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744185.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744185.png new file mode 100644 index 0000000000000000000000000000000000000000..0e103f4f2200e361cc966b8bed337c8a73380cfd Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744185.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744191.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744191.png index d34ba19a667f40c8dc3b4e668095bda1bd4868aa..c2aeef3f178867e832601aae0b723ae1ddf3db49 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744191.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744191.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744193.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744193.png index b7c6998d7f55a75562fbf709aa84b4bd12922ae6..5855095851b92058f270d69a46546db43ec974b8 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744193.png and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219744193.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864147.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864147.gif deleted file mode 100644 index 016da55bb5d98a3d2787d870bf2575fbaf383990..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864147.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864149.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864149.png deleted file mode 100644 index 2c20e6d28a0636b8122f6377052933c33cfcffaf..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864149.png and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864151.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864151.gif index c18ae783333765788db1b8bf6107ee0c117ec9e6..4edf113bcfe487f1b10ddd123dfdbb3ab612af92 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864151.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864151.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864155.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864155.gif deleted file mode 100644 index 627fff6c85420f981d9ae844d0e53a77d254ac7c..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219864155.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982709.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982709.gif deleted file mode 100644 index 3a2f5de773fed90a3c0c058d0b27bc0edd1f1904..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982709.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982725.jpg b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982725.jpg deleted file mode 100644 index e3d3e1023746c03c9ad426328de0114321ac3f66..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982725.jpg and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982725.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982725.png new file mode 100644 index 0000000000000000000000000000000000000000..048fdc4749a41e0675390e66e61b5d63953ed8e1 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001219982725.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001231374559.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001231374559.gif deleted file mode 100644 index 23a03cf07feddcb9866e7ab141c212ebf01bf8b2..0000000000000000000000000000000000000000 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001231374559.gif and /dev/null differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001231374559.png b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001231374559.png new file mode 100644 index 0000000000000000000000000000000000000000..9eb00739d606ea0b53542eba7c43f6cbb82c73c5 Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001231374559.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001250678457.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001250678457.gif index 96afd9a948c90e22cd52ab4c55218bf97591b3ec..3696c7f08f6c7ef551d16da53ca167ddb8b6a5fa 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001250678457.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001250678457.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001252667389.gif b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001252667389.gif index a5092180309ecb061248cc205e4bd667eb290085..198227c0282462bfb34f5363a7996a6817e1bb83 100644 Binary files a/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001252667389.gif and b/zh-cn/application-dev/reference/arkui-ts/figures/zh-cn_image_0000001252667389.gif differ diff --git a/zh-cn/application-dev/reference/arkui-ts/figures/zindex.png b/zh-cn/application-dev/reference/arkui-ts/figures/zindex.png new file mode 100644 index 0000000000000000000000000000000000000000..bb2193d497c6cce42b5d7c6c94671c8bf7f6158e Binary files /dev/null and b/zh-cn/application-dev/reference/arkui-ts/figures/zindex.png differ diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-blank.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-blank.md index ea8b4a0a7629efee1e72fdc24627659108047ec3..6d1d1b49596bbd1dc23c5852b8e471918e5d58cf 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-blank.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-blank.md @@ -7,11 +7,6 @@ > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 子组件 无 @@ -19,27 +14,26 @@ ## 接口 -Blank(min?: number | string) +Blank(min?: number | string) -**参数:** +**参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ------ | ---------------- | ---- | ------ | ------------------------------------ | -| min | number \| string | 否 | 0 | 空白填充组件在容器主轴上的最小大小。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| min | number \| string | 否 | 空白填充组件在容器主轴上的最小大小。
默认值:0 | ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ----- | ------------------------------------------- | -------- | ------------------------ | -| color | [ResourceColor](ts-types.md#resourcecolor8) | 0xffffff | 设置空白填充的填充颜色。 | +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -> **说明:** -> -> 不支持通用属性方法。 +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| color | [ResourceColor](ts-types.md#resourcecolor) | 设置空白填充的填充颜色。 | ## 示例 - +### 示例1 +Blank组件在横竖屏占满空余空间效果。 ```ts // xxx.ets @Entry @@ -64,3 +58,37 @@ struct BlankExample { 横屏状态 ![zh-cn_image_0000001174104388](figures/zh-cn_image_0000001174104388.gif) + + +### 示例2 +Blank组件的父组件未设置宽度时,min参数的使用效果。 + +```ts +// xxx.ets +@Entry +@Component +struct BlankExample { + build() { + Column({ space: 20 }) { + // blank父组件不设置宽度时,Blank失效,可以通过设置min最小宽度填充固定宽度 + Row() { + Text('Bluetooth').fontSize(18) + Blank().color(Color.Yellow) + Toggle({ type: ToggleType.Switch }) + }.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 }) + + Row() { + Text('Bluetooth').fontSize(18) + // 设置最小宽度为160 + Blank('160').color(Color.Yellow) + Toggle({ type: ToggleType.Switch }) + }.backgroundColor(0xFFFFFF).borderRadius(15).padding({ left: 12 }) + + }.backgroundColor(0xEFEFEF).padding(20).width('100%') + } +} +``` +Blank父组件未设置宽度时,子组件间无空白填充,使用min参数设置填充尺寸 + +![blankmin](figures/blankmin.png) + diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-checkboxgroup.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-checkboxgroup.md index 9b7b588d64e4f56a1b3ed976a02f8791272ea8df..bb76a56ad6dd536a03971d1217e9b7a91dd5dd8b 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-checkboxgroup.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-checkboxgroup.md @@ -12,49 +12,49 @@ ## 接口 -CheckboxGroup( options?: {group?: string} ) +CheckboxGroup(options?: { group?: string }) -创建多选框群组,可以控制群组内的Checkbox全选或者不全选,相同group的Checkbox和CheckboxGroup为同一群组。 +创建多选框群组,可以控制群组内的Checkbox全选或者不全选,group值相同的Checkbox和CheckboxGroup为同一群组。 -**参数:** +**参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| ------ | -------- | ---- | ---------- | -| group | string | 否 | 群组名称。 | -## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ------------- | ----- | ----- | ---------------- | -| selectAll | boolean | false | 设置是否全选。 | -| selectedColor | [ResourceColor](ts-types.md#resourcecolor8) | - | 设置被选中或部分选中状态的颜色。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| group | string | 否 | 群组名称。| -## 事件 +## 属性 -## onChange +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -onChange (callback: (event: CheckboxGroupResult ) => void ) +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| selectAll | boolean | 设置是否全选。
默认值:false | +| selectedColor | [ResourceColor](ts-types.md#resourcecolor) | 设置被选中或部分选中状态的颜色。 | -CheckboxGroup的选中状态或群组内的Checkbox的选中状态发生变化时,触发回调。 +## 事件 -| 名称 | 参数类型 | 必填 | 描述 | -| ----- | ------------------- | ---- | -------------------- | -| event | CheckboxGroupResult | 是 | 选中状态的回调结果。 | +除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件: -## CheckboxGroupResult +| 名称 | 功能描述 | +| -------- | -------- | +| onChange (callback: (event: [CheckboxGroupResult](#checkboxgroupresult对象说明)) => void ) |CheckboxGroup的选中状态或群组内的Checkbox的选中状态发生变化时,触发回调。| -| 名称 | 参数类型 | 描述 | -| ------ | ------------------- | -------------- | -| name | Array<string> | checkBox名称。 | -| status | SelectStatus | 选中状态。 | +## CheckboxGroupResult对象说明 +| 名称 | 类型 | 描述 | +| ------ | ------ | ------- | +| name | Array<string> | 群组内所有被选中的多选框名称。 | +| status | [SelectStatus](#selectstatus枚举说明) | 选中状态。 | ## SelectStatus枚举说明 -| 名称 | 描述 | -| ---- | ------------- | -| All | 群组多选择框全部选择。 | -| Part | 群组多选择框部分选择。 | -| None | 群组多选择框全部没有选择。 | +| 名称 | 描述 | +| ----- | -------------------- | +| All | 群组多选择框全部选择。 | +| Part | 群组多选择框部分选择。 | +| None | 群组多选择框全部没有选择。 | + ## 示例 @@ -63,36 +63,57 @@ CheckboxGroup的选中状态或群组内的Checkbox的选中状态发生变化 @Entry @Component struct CheckboxExample { - build() { Scroll() { Column() { - CheckboxGroup({group : 'checkboxGroup'}) - .selectedColor(0xed6f21) - .onChange((itemName:CheckboxGroupResult) => { - console.info("TextPicker::dialogResult is" + JSON.stringify(itemName)) - }) - Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) - .select(true) - .selectedColor(0x39a2db) - .onChange((value: boolean) => { - console.info('Checkbox1 change is' + value) - }) - Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) - .select(false) - .selectedColor(0x39a2db) - .onChange((value: boolean) => { - console.info('Checkbox2 change is' + value) - }) - Checkbox({ name: 'checkbox3', group: 'checkboxGroup' }) - .select(true) - .selectedColor(0x39a2db) - .onChange((value: boolean) => { - console.info('Checkbox3 change is' + value) - }) + // 全选按钮 + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + CheckboxGroup({ group: 'checkboxGroup' }) + .selectedColor(0xed6f21) + .onChange((itemName: CheckboxGroupResult) => { + console.info("checkbox group content" + JSON.stringify(itemName)) + }) + Text('Select All').fontSize(20) + } + + // 选项1 + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Checkbox({ name: 'checkbox1', group: 'checkboxGroup' }) + .selectedColor(0x39a2db) + .onChange((value: boolean) => { + console.info('Checkbox1 change is' + value) + }) + Text('Checkbox1').fontSize(20) + } + + // 选项2 + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Checkbox({ name: 'checkbox2', group: 'checkboxGroup' }) + .selectedColor(0x39a2db) + .onChange((value: boolean) => { + console.info('Checkbox2 change is' + value) + }) + Text('Checkbox2').fontSize(20) + } + + // 选项3 + Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { + Checkbox({ name: 'checkbox3', group: 'checkboxGroup' }) + .selectedColor(0x39a2db) + .onChange((value: boolean) => { + console.info('Checkbox3 change is' + value) + }) + Text('Checkbox3').fontSize(20) + } } } } } ``` -![](figures/checkboxgroup.gif) +多选框组三种状态图示: + +![](figures/checkboxgroup1.png) + +![](figures/checkboxgroup2.png) + +![](figures/checkboxgroup3.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md index cb7fae4c536a2df5ac01e9876f0249671bdc0d1e..cc8d763c17ca1ba2368d6f3570b348272f2ef1f8 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-datapanel.md @@ -2,41 +2,38 @@ 数据面板组件,用于将多个数据占比情况使用占比图进行展示。 -## 权限列表 +> **说明:** +> +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 + + -无 ## 子组件 无 + ## 接口 DataPanel(options:{values: number[], max?: number, type?: DataPanelType}) -**参数**: - -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ----------------- | ------------- | ---- | -------------------- | ---------------------------------------- | -| values | number[] | 是 | - | 数据值列表,最大支持9个数据。 | -| max | number | 否 | 100 | - max大于0,表示数据的最大值。
- max小于等于0,max等于value数组各项的和,按比例显示。 | -| type8+ | DataPanelType | 否 | DataPanelType.Circle | 数据面板的类型。 | - -## 属性 - -| 名称 | 参数类型 | 默认值 | 描述 | -| ----------- | -------- | ------ | ------------------------------------ | -| closeEffect | boolean | true | 设置是否禁用数据比率图表的特殊效果。 | +**参数:** +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ----------------- | -------- | ----- | -------- | +| values | number[] | 是 | 数据值列表,最大支持9个数据。 | +| max | number | 否 | - max大于0,表示数据的最大值。
- max小于等于0,max等于value数组各项的和,按比例显示。
默认值:100 | +| type8+ | [DataPanelType](#datapaneltype枚举说明) | 否 | 数据面板的类型。
默认值:DataPanelType.Circle | ## DataPanelType枚举说明 - -| 名称 | 描述 | -| ------ | ------- | -| Line | 线型数据面板。 | +| 名称 | 描述 | +| -------| ------------ | +| Line | 线型数据面板。 | | Circle | 环形数据面板。 | + ## 示例 ```ts diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-divider.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-divider.md index 0803a7f41d5fd0228cb5041071535d69a983feba..bc7f60cc562b411b5e95cc932f16282c02cc08c4 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-divider.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-divider.md @@ -6,32 +6,33 @@ > > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 ## 子组件 无 + ## 接口 Divider() ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ----------- | --------------------------------------------------------- | ----------------- | ------------------------------------------------------------ | -| vertical | boolean | false | 使用水平分割线还是垂直分割线,false: 水平分割线, true:垂直分割线。 | -| color | [ResourceColor](ts-types.md#resourcecolor8) | - | 设置分割线颜色。 | -| strokeWidth | number \| string | 1 | 设置分割线宽度。 | -| lineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 设置分割线条的端点样式。 | +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: + +| 名称 | 参数类型 | 描述 | +| ----------- | ---------- | ------------------ | +| vertical | boolean | 使用水平分割线还是垂直分割线。false: 水平分割线, true: 垂直分割线。
默认值:false | +| color | [ResourceColor](ts-types.md#resourcecolor) | 分割线颜色。 | +| strokeWidth | number \| string | 分割线宽度。
默认值:1 | +| lineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | 分割线的端点样式。
默认值:LineCapStyle.Butt | ## 事件 不支持通用事件。 + ## 示例 ```ts @@ -46,6 +47,7 @@ struct DividerExample { Divider() Row().width('100%').height(40).backgroundColor(0xF1F3F5) + // 纵向分割线 Text('Vertical divider').fontSize(9).fontColor(0xCCCCCC) Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.Wrap }) { Text('bravery') @@ -55,6 +57,7 @@ struct DividerExample { Text('upward') }.width(250) + // 设置分割线宽度和端点样式 Text('Custom Styles').fontSize(9).fontColor(0xCCCCCC) Row().width('100%').height(40).backgroundColor(0xF1F3F5) Divider().vertical(false).strokeWidth(5).color(0x2788D9).lineCap(LineCapStyle.Round) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-gauge.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-gauge.md index ea8cce2af4c9619c7d21012fe458baf430d3f1e5..52bfcd5ba688f84db5e9dc57264545caa4453b89 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-gauge.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-gauge.md @@ -2,35 +2,40 @@ 数据量规图表组件,用于将数据展示为环形图表。 + > **说明:** > > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 + ## 子组件 无 + ## 接口 Gauge(options:{value: number, min?: number, max?: number}) **参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| ------ | -------- | ---- | ---------------------------------- | -| value | number | 是 | 当前数据值。 | -| min | number | 否 | 当前数据段最小值。
默认值:0 | -| max | number | 否 | 当前数据段最大值。
默认值:100 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| value | number | 是 | 量规图的当前数据值,即图中指针指向位置。用于组件创建时量规图初始值的预置。 | +| min | number | 否 | 当前数据段最小值。
默认值:0 | +| max | number | 否 | 当前数据段最大值。
默认值:100 | ## 属性 -| 名称 | 参数类型 | 描述 | -| ----------- | ---------------------------------------- | --------------------------- | -| value | number | 设置当前数据图表的值。
默认值:0 | -| startAngle | number | 设置起始角度位置,时钟0点为0度,顺时针方向为正角度。
默认值:-150 | -| endAngle | number | 设置终止角度位置,时钟0点为0度,顺时针方向为正角度。
默认值:150 | -| colors | Array<ColorStop> | 设置图表的颜色,支持分段颜色设置。 | -| strokeWidth | [Length](ts-types.md#length) | 设置环形图表的环形厚度。 | +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: + +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| value | number | 设置量规图的数据值,可用于动态修改量规图的数据值。
默认值:0 | +| startAngle | number | 设置起始角度位置,时钟0点为0度,顺时针方向为正角度。
默认值:0 | +| endAngle | number | 设置终止角度位置,时钟0点为0度,顺时针方向为正角度。
默认值:360 | +| colors | Array<[ColorStop](#colorstop)> | 设置量规图的颜色,支持分段颜色设置。 | +| strokeWidth | Length | 设置环形量规图的环形厚度。 | ## ColorStop @@ -38,7 +43,7 @@ Gauge(options:{value: number, min?: number, max?: number}) | 名称 | 类型定义 | 描述 | | --------- | -------------------- | ------------------------------------------------------------ | -| ColorStop | [[ResourceColor](ts-types.md#resourcecolor8), number] | 描述渐进色颜色断点类型,第一个参数为颜色值,第二个参数为0~1之间的比例值。 | +| ColorStop | [[ResourceColor](ts-types.md#resourcecolor), number] | 描述渐进色颜色断点类型,第一个参数为颜色值,第二个参数为0~1之间的比例值。 | ## 示例 @@ -50,15 +55,30 @@ Gauge(options:{value: number, min?: number, max?: number}) @Component struct GaugeExample { build() { - Column() { - Gauge({ value: 50, min: 0, max: 100 }) - .startAngle(210).endAngle(150) - .colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]]) - .strokeWidth(20) + Column({ space: 20 }) { + // 使用默认的min和max为0-100,角度范围默认0-360,value值设置 + // 参数中设置当前值为75 + Gauge({ value: 75 }) + .width(200).height(200) + .colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1]]) + + // 参数设置当前值为75,属性设置值为25,属性设置优先级高 + Gauge({ value: 75 }) + .value(25) //属性和参数都设置时以参数为准 .width(200).height(200) + .colors([[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1]]) + + // 210--150度环形图表 + Gauge({ value: 30, min: 0, max: 100 }) + .startAngle(210) + .endAngle(150) + .colors([[0x317AF7, 0.1], [0x5BA854, 0.2], [0xE08C3A, 0.3], [0x9C554B, 0.4]]) + .strokeWidth(20) + .width(200) + .height(200) }.width('100%').margin({ top: 5 }) } } ``` -![zh-cn_image_0000001174422916](figures/zh-cn_image_0000001174422916.png) +![gauge](figures/gauge-image.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-image.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-image.md index 0623fba069c2d5b65fc0cf8ddffe7da16ad2b162..6c57d14b183abe5ab52bb93c56af5460057d1a65 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-image.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-image.md @@ -21,9 +21,9 @@ Image(src: string | PixelMap | Resource) **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ---- | ---------------------------------------- | ---- | ---- | ---------------------------------------- | -| src | string\| [PixelMap](../apis/js-apis-image.md#pixelmap7)\| [Resource](ts-types.md#resource) | 是 | - | 图片的数据源,支持本地图片和网络图片。
当使用相对路径引用图片资源时,例如`Image("common/test.jpg")`,不支持该Image组件被跨包/跨模块调用,建议使用`$r`方式来管理需全局使用的图片资源。
\- 支持的图片格式包括png、jpg、bmp、svg和gif。
\- 支持`Base64`字符串。格式`data:image/[png\|jpeg\|bmp\|webp];base64,[base64 data]`, 其中`[base64 data]`为`Base64`字符串数据。
\- 支持`dataability://`路径前缀的字符串,用于访问通过data ability提供的图片路径。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| ------ | ------------------------------------------------------------ | ---- | ------ | ------------------------------------------------------------ | +| src | string\| [PixelMap](../apis/js-apis-image.md#pixelmap7)\| [Resource](ts-types.md#resource) | 是 | - | 图片的数据源,支持本地图片和网络图片。
当使用相对路径引用图片资源时,例如`Image("common/test.jpg")`,不支持该Image组件被跨包/跨模块调用,建议使用`$r`方式来管理需全局使用的图片资源。
\- 支持的图片格式包括png、jpg、bmp、svg和gif。
\- 支持`Base64`字符串。格式`data:image/[png\|jpeg\|bmp\|webp];base64,[base64 data]`, 其中`[base64 data]`为`Base64`字符串数据。
\- 支持`dataability://`路径前缀的字符串,用于访问通过data ability提供的图片路径。
\- 支持file:///data/storage路径前缀的字符串,用于读取本应用安装目录下files文件夹下的图片资源。需要保证目录包路径下的文件有可读权限。 | ## 属性 @@ -41,6 +41,10 @@ Image(src: string | PixelMap | Resource) | autoResize | boolean | true | 是否需要在图片解码过程中对图源做resize操作,该操作会根据显示区域的尺寸决定用于绘制的图源尺寸,有利于减少内存占用。 | | syncLoad8+ | boolean | false | 设置是否同步加载图片,默认是异步加载。同步加载时阻塞UI线程,不会显示占位图。 | +> **说明:** +> +> 图片设置svg图源时,支持的标签范围有限,目前支持的svg标签包括svg、rect、circle、ellipse、path、line、polyline、polygon、animate、animateMotion、animateTransform。 + ## ImageInterpolation枚举说明 | 名称 | 描述 | @@ -265,3 +269,53 @@ struct ImageExample3 { ``` ![zh-cn_image_0000001205972610](figures/zh-cn_image_0000001205972610.gif) + +### 渲染沙箱路径图片 + +``` +import fileio from '@ohos.fileio'; +import image from '@ohos.multimedia.image'; + +const EMPTY_PATH = 'file://'; + +@Entry +@Component +struct LoadImageExample { + @State fileContent: string = ''; + @State path: string = EMPTY_PATH; + @State accountInfoHeadPic: any = ''; + + build() { + Column() { + Button('读取沙箱图片') + .margin({ bottom: 10 }) + .onClick(() => { + try { + this.path = EMPTY_PATH; + let context = getContext(this); + let path = context.getApplicationContext().filesDir + '/icon.png'; + console.log(`读取沙箱图片=========>${path}`); + let fd = fileio.openSync(path, 0o100, 0o666); + console.log(`create file========>${fd}`); + let srcPath = context.bundleCodeDir + '/entry/resource/base/media/icon.png'; + fileio.copyFileSync(srcPath, path); + console.log(`error:=============>${e.message}`); + } + }) + Button('读取资源图片') + .margin({ bottom: 10 }) + .onClick(() => { + this.path = EMPTY_PATH; + this.path += getContext(this.bundleCodeDir + '/entry/resource/base/media/icon.png'); + }) + Text(`图片路径:${this.path}`) + .fontSize(20) + .margin({ bottom: 10 }) + Image(this.path) + .width(100) + .height(100) + } + .width('100%').height('100%') + } +} +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-navigation.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-navigation.md index 144aa0933d300740fc14ddbcb1f91e1442f8191f..9c21ba142bb83e9a3a8c4443ea8d074dd0041d79 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-navigation.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-navigation.md @@ -2,9 +2,9 @@ Navigation组件一般作为Page页面的根容器,通过属性设置来展示页面的标题、工具栏、菜单。 -> **说明:** +> **说明:** > -> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 子组件 @@ -18,19 +18,20 @@ Navigation() 创建可以根据属性设置,自动展示导航栏、标题、工具栏的组件。 - ## 属性 +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: + | 名称 | 参数类型 | 描述 | | -------------- | ---------------------------------------- | ---------------------------------------- | | title | string \| [CustomBuilder](ts-types.md#custombuilder8)8+ | 页面标题。 | -| subtitle | string | 页面副标题。 | -| menus | Array8+ | 页面右上角菜单。 | -| titleMode | NavigationTitleMode | 页面标题栏显示模式。
默认值:NavigationTitleMode.Free | -| toolBar | object \| [CustomBuilder](ts-types.md#custombuilder8)8+ | 设置工具栏内容。
items: 工具栏所有项。 | -| hideToolBar | boolean | 设置隐藏/显示工具栏:
默认值:false
true: 隐藏工具栏。
false: 显示工具栏。 | -| hideTitleBar | boolean | 隐藏标题栏。
默认值:false | -| hideBackButton | boolean | 隐藏返回键。
默认值:false | +| subTitle | string | 页面副标题。 | +| menus | Array<[NavigationMenuItem](#navigationmenuitem类型说明)> \| [CustomBuilder](ts-types.md#custombuilder8)8+ | 页面右上角菜单。 | +| titleMode | [NavigationTitleMode](#navigationtitlemode枚举说明) | 页面标题栏显示模式。
默认值:NavigationTitleMode.Free | +| toolBar | [object](#object类型说明) \| [CustomBuilder](ts-types.md#custombuilder8)8+ | 设置工具栏内容。
items: 工具栏所有项。 | +| hideToolBar | boolean | 隐藏工具栏:
默认值:false
true: 隐藏工具栏。
false: 显示工具栏。 | +| hideTitleBar | boolean | 隐藏标题栏。
默认值:false
true: 隐藏标题栏。
false: 显示标题栏。 | +| hideBackButton | boolean | 隐藏返回键。
默认值:false
true: 隐藏返回键。
false: 显示返回键。 | ## NavigationMenuItem类型说明 @@ -40,7 +41,7 @@ Navigation() | icon | string | 否 | 菜单栏单个选项的图标资源路径。 | | action | () => void | 否 | 当前选项被选中的事件回调。 | -## Object类型说明 +## object类型说明 | 名称 | 类型 | 必填 | 描述 | | ------ | ----------------------- | ---- | ------------------------------ | @@ -57,8 +58,8 @@ Navigation() | Full | 固定为大标题模式(主副标题)。 | > **说明:** -> -> 目前可滚动组件只支持List。 +> 目前可滚动组件只支持List。 + ## 事件 @@ -70,7 +71,7 @@ Navigation() ## 示例 ```ts -// Example 01 +// xxx.ets @Entry @Component struct NavigationExample { @@ -158,7 +159,7 @@ struct NavigationExample { ![zh-cn_image_0000001237616085](figures/zh-cn_image_0000001237616085.gif) ```ts -// Example 02 +// xxx.ets @Entry @Component struct ToolbarBuilderExample { diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-progress.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-progress.md index f7382144373d1efa7b7a749b525f30ad85282676..8eda9f2b43c4a14bde707b27629ee0b07897b322 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-progress.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-progress.md @@ -14,18 +14,18 @@ ## 接口 -Progress(options: {value: number, total?: number, style?: ProgressStyle, type?: ProgressType}) +Progress(options: {value: number, total?: number, type?: ProgressType}) 创建进度组件,用于显示内容加载或操作处理进度。 -**参数:** +**参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| -------------------------- | ------------- | ---- | ------------------------------------------------------------ | -| value | number | 是 | 指定当前进度值。 | -| total | number | 否 | 指定进度总长。
默认值:100 | -| type8+ | ProgressType | 否 | 指定进度条类型。
默认值:ProgressType.Linear | -| styledeprecated | ProgressStyle | 否 | 指定进度条类型。
该参数从API Version8开始废弃,建议使用type替代。
默认值:ProgressStyle.Linear | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| value | number | 是 | 指定当前进度值。 | +| total | number | 否 | 指定进度总长。
默认值:100 | +| type8+ | [ProgressType](#progresstype枚举说明) | 否 | 指定进度条类型。
默认值:ProgressType.Linear | +| styledeprecated | [ProgressStyle](#progressstyle枚举说明) | 否 | 指定进度条样式。
该参数从API Version8开始废弃,建议使用type替代。
默认值:ProgressStyle.Linear | ## ProgressType枚举说明 @@ -37,7 +37,7 @@ Progress(options: {value: number, total?: number, style?: ProgressStyle, type?: | ScaleRing8+ | 环形有刻度样式,显示类似时钟刻度形式的进度展示效果。 | | Capsule8+ | 胶囊样式,头尾两端圆弧处的进度展示效果与Eclipse相同;中段处的进度展示效果与Linear相同。 | -## ProgressStyle枚举说明 +## ProgressStyle枚举说明 | 名称 | 描述 | | ---------------------- | ------------------------------------------------------------ | @@ -49,11 +49,11 @@ Progress(options: {value: number, total?: number, style?: ProgressStyle, type?: ## 属性 -| 名称 | 参数类型 | 描述 | -| ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -| value | number | 设置当前进度值。 | -| color | [ResourceColor](ts-types.md#resourcecolor8) | 设置进度条前景色。 | -| style8+ | {
strokeWidth?: [Length](ts-types.md#length),
scaleCount?: number,
scaleWidth?: [Length](ts-types.md#length)
} | 定义组件的样式。
strokeWidth: 设置进度条宽度。
scaleCount: 设置环形进度条总刻度数。
scaleWidth: 设置环形进度条刻度粗细。
刻度粗细大于进度条宽度时,刻度粗细为系统默认粗细。 | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| value | number | 设置当前进度值。 | +| color | [ResourceColor](ts-types.md#resourcecolor) | 设置进度条前景色。 | +| style8+ | {
strokeWidth?: [Length](ts-types.md#length),
scaleCount?: number,
scaleWidth?: [Length](ts-types.md#length)
} | 定义组件的样式。
- strokeWidth: 设置进度条宽度。
- scaleCount: 设置环形进度条总刻度数。
- scaleWidth: 设置环形进度条刻度粗细,刻度粗细大于进度条宽度时,为系统默认粗细。 | ## 示例 @@ -69,6 +69,7 @@ struct ProgressExample { Progress({ value: 10, type: ProgressType.Linear }).width(200) Progress({ value: 20, total: 150, type: ProgressType.Linear }).color(Color.Grey).value(50).width(200) + Text('Eclipse Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Row({ space: 40 }) { Progress({ value: 10, type: ProgressType.Eclipse }).width(100) @@ -83,6 +84,16 @@ struct ProgressExample { .style({ strokeWidth: 15, scaleCount: 15, scaleWidth: 5 }) } + // scaleCount和scaleWidth效果对比 + Row({ space: 40 }) { + Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }) + .color(Color.Grey).value(50).width(100) + .style({ strokeWidth: 20, scaleCount: 20, scaleWidth: 5 }) + Progress({ value: 20, total: 150, type: ProgressType.ScaleRing }) + .color(Color.Grey).value(50).width(100) + .style({ strokeWidth: 20, scaleCount: 30, scaleWidth: 3 }) + } + Text('Ring Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Row({ space: 40 }) { Progress({ value: 10, type: ProgressType.Ring }).width(100) @@ -105,4 +116,4 @@ struct ProgressExample { } ``` -![zh-cn_image_0000001198839004](figures/zh-cn_image_0000001198839004.gif) +![progress](figures/progress.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-qrcode.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-qrcode.md index 51121a42b6b6f79268bdd3829617c73d85637a64..d029ffdc31014f2046db268c33cc81917b2d783a 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-qrcode.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-qrcode.md @@ -1,15 +1,9 @@ # QRCode -显示二维码信息。 +用于显示单个二维码的组件。 > **说明:** -> -> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -## 权限列表 - -无 +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 子组件 @@ -21,18 +15,20 @@ QRCode(value: string) -**参数:** +**参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ----- | ------ | ---- | ---- | --------- | -| value | string | 是 | - | 二维码内容字符串。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| value | string | 是 | 二维码内容字符串。 | ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| --------------- | ------------------------------------------- | ------ | ---------------------- | -| color | [ResourceColor](ts-types.md#resourcecolor8) | Black | 设置二维码颜色。 | -| backgroundColor | [ResourceColor](ts-types.md#resourcecolor8) | White | 设置二维码的背景颜色。 | +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性。 + +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| color | [ResourceColor](ts-types.md#resourcecolor) | 设置二维码颜色。
默认值:Color.Black | +| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | 设置二维码背景颜色。
默认值:Color.White | ## 事件 @@ -48,17 +44,21 @@ QRCode(value: string) @Component struct QRCodeExample { private value: string = 'hello world' - build() { Column({ space: 5 }) { - Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC) + Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30) QRCode(this.value).width(200).height(200) - Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC) + // 设置二维码颜色 + Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30) QRCode(this.value).color(0xF7CE00).width(200).height(200) + + // 设置二维码背景色 + Text('backgroundColor').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30) + QRCode(this.value).width(200).height(200).backgroundColor(Color.Orange) }.width('100%').margin({ top: 5 }) } } ``` -![zh-cn_image_0000001219662669](figures/zh-cn_image_0000001219662669.png) +![qrcode](figures/qrcode.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-richtext.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-richtext.md index 273467da3e613e579039991551f43d056cc4752b..9c2e9b4549d90e899375aa186acd9e1c90d2bc5d 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-richtext.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-richtext.md @@ -53,28 +53,30 @@ RichText(content: string) @Entry @Component struct RichTextExample { - @State data: string = "

h1标题

" + - "

h1斜体

" + - "

h1下划线

" + - "

h2标题

" + - "

h3标题

" + - "

p常规


" + - "
" + - "

字体大小35px,行高45px

" + - "

" + - "

这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字

" + @State data: string = '

h1标题

' + + '

h1斜体

' + + '

h1下划线

' + + '

h2标题

' + + '

h3标题

' + + '

p常规


' + + '
' + + '

字体大小35px,行高45px

' + + '

' + + '

这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字这是一段文字

'; build() { - Flex({direction: FlexDirection.Column,alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center }){ + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center }) { RichText(this.data) - .onStart(()=>{ - console.info("RichText onStart") - }) - .onComplete(()=>{ - console.info("RichText onComplete") - }) + .onStart(() => { + console.info('RichText onStart'); + }) + .onComplete(() => { + console.info('RichText onComplete'); + }) } } } -``` \ No newline at end of file +``` + + ![richText](figures/richText.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-scrollbar.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-scrollbar.md index abdbb7717ef0cd865f807019130f588c11a675ca..59ea8bf4922847804e96d2dad708696fb5885d85 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-scrollbar.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-scrollbar.md @@ -7,11 +7,6 @@ > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 子组件 可以包含单个子组件。 @@ -23,22 +18,22 @@ ScrollBar(value: { scroller: Scroller, direction?: ScrollBarDirection, state?: B **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| --------- | ---------------------------------------- | ---- | --------------------------- | ----------------------- | -| scroller | [Scroller](ts-container-scroll.md#scroller) | 是 | - | 可滚动组件的控制器。用于与可滚动组件进行绑定。 | -| direction | ScrollBarDirection | 否 | ScrollBarDirection.Vertical | 滚动条的方向,控制可滚动组件对应方向的滚动。 | -| state | [BarState](ts-appendix-enums.md#barstate) | 否 | BarState.Auto | 滚动条状态。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| scroller | [Scroller](ts-container-scroll.md#scroller) | 是 | 可滚动组件的控制器。用于与可滚动组件进行绑定。 | +| direction | [ScrollBarDirection](#scrollbardirection枚举说明) | 否 | 滚动条的方向,控制可滚动组件对应方向的滚动。
默认值:ScrollBarDirection.Vertical | +| state | [BarState](ts-appendix-enums.md#barstate) | 否 | 滚动条状态。
默认值:BarState.Auto | > **说明:** -> ScrollBar组件负责定义可滚动区域的行为样式,ScrollBar的子节点负责定义滚动条的行为样式。 -> -> 滚动条组件与可滚动组件通过Scroller进行绑定,且只有当两者方向相同时,才能联动,ScrollBar与可滚动组件仅支持一对一绑定。 +> ScrollBar组件负责定义可滚动区域的行为样式,ScrollBar的子节点负责定义滚动条的行为样式。 +> +> 滚动条组件与可滚动组件通过Scroller进行绑定,且只有当两者方向相同时,才能联动,ScrollBar与可滚动组件仅支持一对一绑定。 ## ScrollBarDirection枚举说明 -| 名称 | 描述 | -| ---------- | ------ | -| Vertical | 纵向滚动条。 | +| 名称 | 描述 | +| -------- | -------- | +| Vertical | 纵向滚动条。 | | Horizontal | 横向滚动条。 | diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-search.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-search.md index 95e7221fd461c629737bae93c0f0e6bb711de982..6fd4c47601161a4aec2605000618b6eca8284088 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-search.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-search.md @@ -1,6 +1,6 @@ # Search -提供搜索框组件,用于提供用户搜索内容的输入区域。 +搜索框组件,适用于浏览器的搜索内容输入框等应用场景。 > **说明:** > @@ -18,33 +18,36 @@ Search(options?: { value?: string; placeholder?: string; icon?: string; controll | 参数名 | 参数类型 | 必填 | 参数描述 | | ----------- | ---------------- | ---- | ------------------------------------------------------------ | -| value | string | 否 | 搜索文本值。 | -| placeholder | string | 否 | 无输入时的提示文本。 | -| icon | string | 否 | 搜索图标路径,默认使用系统搜索图标,支持的图标格式: svg, jpg和png。 | -| controller | SearchController | 否 | 控制器。 | +| value | string | 否 | 设置当前显示的搜索文本内容。 | +| placeholder | string | 否 | 设置无输入时的提示文本。 | +| icon | string | 否 | 设置搜索图标路径,默认使用系统搜索图标,图标支持的图源格式: svg、jpg和png。 | +| controller | SearchController | 否 | 设置Search组件控制器。 | ## 属性 -| 名称 | 参数类型 | 描述 | -| ---------------- | ------------------------------------------- | ------------------------------------------ | -| searchButton | string | 搜索框末尾搜索按钮文本值,默认无搜索按钮。 | -| placeholderColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置placeholder颜色。 | -| placeholderFont | [Font](ts-types.md#font) | 设置placeholder文本样式。 | -| textFont | [Font](ts-types.md#font) | 设置搜索框内文本样式。 | +| 名称 | 参数类型 | 描述 | +| ---------------- | ------------------------------------------- | ---------------------------------------------------------- | +| searchButton | string | 搜索框末尾搜索按钮文本内容,默认无搜索按钮。 | +| placeholderColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置placeholder文本颜色。 | +| placeholderFont | [Font](ts-types.md#font) | 设置placeholder文本样式。 | +| textFont | [Font](ts-types.md#font) | 设置搜索框内输入文本样式。 | +| textAlign | [TextAlign](ts-appendix-enums.md#textalign) | 设置文本在搜索框中的对齐方式。
默认值:TextAlign.Start | ## 事件 -| 名称 | 功能描述 | -| ---------------------------------------- | ---------------------------------------- | -| onSubmit(callback: (value: string) => void) | 点击搜索图标、搜索按钮或者按下软键盘搜索按钮时触发。
-value: 当前输入文本框的内容。 | -| onChange(callback: (value: string) => void) | 输入内容发生变化时,触发回调。
-value: 当前输入文本框的内容。 | -| onCopy(callback: (value: string) => void) | 组件触发系统剪切板复制操作。
-value: 复制的文本内容。 | -| onCut(callback: (value: string) => void) | 组件触发系统剪切板剪切操作。
-value: 剪切的文本内容。 | -| onPaste(callback: (value: string) => void) | 组件触发系统剪切板粘贴操作。
-value: 粘贴的文本内容。 | +除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件: + +| 名称 | 功能描述 | +| ------------------------------------------- | ------------------------------------------------------------ | +| onSubmit(callback: (value: string) => void) | 点击搜索图标、搜索按钮或者按下软键盘搜索按钮时触发该回调。
-value: 当前搜索框中输入的文本内容。 | +| onChange(callback: (value: string) => void) | 输入内容发生变化时,触发该回调。
-value: 当前搜索框中输入的文本内容。 | +| onCopy(callback: (value: string) => void) | 长按搜索框弹出剪切板之后,点击剪切板的复制按钮触发该回调。
-value: 复制的文本内容。 | +| onCut(callback: (value: string) => void) | 长按搜索框弹出剪切板之后,点击剪切板的剪切按钮触发该回调
-value: 剪切的文本内容。 | +| onPaste(callback: (value: string) => void) | 长按搜索框弹出剪切板之后,点击剪切板的粘贴按钮触发该回调。
-value: 粘贴的文本内容。 | ## SearchController -Search组件的控制器,通过它操作Search组件。 +Search组件的控制器,目前通过它可控制Search组件的光标位置。 ### 导入对象 ``` @@ -70,30 +73,36 @@ caretPosition(value: number): void @Entry @Component struct SearchExample { - @State changeValue: string = '' - @State submitValue: string = '' - controller: SearchController = new SearchController() + @State changeValue: string = ''; + @State submitValue: string = ''; + controller: SearchController = new SearchController(); build() { - Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { - Text(this.submitValue) - Text(this.changeValue) - Search({value: this.changeValue, placeholder: 'Type to search', controller: this.controller}) - .searchButton('Search') + Column() { + Text('onSubmit:' + this.submitValue).fontSize(18).margin(15) + Text('onChange:' + this.changeValue).fontSize(18).margin(15) + Search({ value: this.changeValue, placeholder: 'Type to search...', controller: this.controller }) + .searchButton('SEARCH') .width(400) - .height(35) + .height(40) .backgroundColor(Color.White) .placeholderColor(Color.Grey) - .placeholderFont({ size: 26, weight: 10, family: 'serif', style: FontStyle.Normal }) + .placeholderFont({ size: 14, weight: 400 }) + .textFont({ size: 14, weight: 400 }) .onSubmit((value: string) => { - this.submitValue = value + this.submitValue = value; }) .onChange((value: string) => { - this.changeValue = value + this.changeValue = value; + }) + .margin(20) + Button('Set caretPosition 1') + .onClick(() => { + // 设置光标位置到输入的第一个字符后 + this.controller.caretPosition(1); }) - .margin({ top: 30, left:10, right:10 }) - } + }.width('100%') } } ``` -![search](figures/search.png) \ No newline at end of file +![search](figures/search.gif) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md index e85fce2c9778bc87ddd1915dbace0f1289f516e4..8cf446c398c106cff0a04543be75a5888506ff75 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-select.md @@ -12,34 +12,35 @@ ## 接口 -Select(options: Array\) +Select(options: Array\<[SelectOption](#selectoption对象说明)\>) -**SelectOption对象说明:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| ----- | ----------------------------------- | ---- | ------- | -| value | [ResourceStr](ts-types.md#resourcestr8) | 是 | 下拉选项内容。 | -| icon | [ResourceStr](ts-types.md#resourcestr8) | 否 | 下拉选项图片。 | +## SelectOption对象说明 + +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ------ | ----------------------------------- | ---- | -------------- | +| value | [ResourceStr](ts-types.md#resourcestr) | 是 | 下拉选项内容。 | +| icon | [ResourceStr](ts-types.md#resourcestr) | 否 | 下拉选项图片。 | ## 属性 -| 名称 | 参数类型 | 描述 | -| ----------------------- | ------------------------------------------- | --------------------------------------------- | -| selected | number | 设置下拉菜单初始选项的索引,第一项的索引为0。 | -| value | string | 设置下拉按钮本身的文本显示。 | -| font | [Font](ts-types.md#font) | 设置下拉按钮本身的文本样式。 | -| fontColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置下拉按钮本身的文本颜色。 | -| selectedOptionBgColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置下拉菜单选中项的背景色。 | -| selectedOptionFont | [Font](ts-types.md#font) | 设置下拉菜单选中项的文本样式。 | -| selectedOptionFontColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置下拉菜单选中项的文本颜色。 | -| optionBgColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置下拉菜单项的背景色。 | -| optionFont | [Font](ts-types.md#font) | 设置下拉菜单项的文本样式。 | -| optionFontColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置下拉菜单项的文本颜色。 | +| 名称 | 参数类型 | 描述 | +| ----------------------- | ------------------------------------- | --------------------------------------------- | +| selected | number | 设置下拉菜单初始选项的索引,第一项的索引为0。 | +| value | string | 设置下拉按钮本身的文本内容。 | +| font | [Font](ts-types.md#font) | 设置下拉按钮本身的文本样式。 | +| fontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉按钮本身的文本颜色。 | +| selectedOptionBgColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉菜单选中项的背景色。 | +| selectedOptionFont | [Font](ts-types.md#font) | 设置下拉菜单选中项的文本样式。 | +| selectedOptionFontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉菜单选中项的文本颜色。 | +| optionBgColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉菜单项的背景色。 | +| optionFont | [Font](ts-types.md#font) | 设置下拉菜单项的文本样式。 | +| optionFontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置下拉菜单项的文本颜色。 | ## 事件 -| 名称 | 功能描述 | -| ---------------------------------------- | -------------------------------------- | -| onSelect(callback: (index: number, value?:string) => void) | 下拉菜单选中某一项的回调。index:选中项的索引。value:选中项的值。 | +| 名称 | 功能描述 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| onSelect(callback: (index: number, value?: string) => void) | 下拉菜单选中某一项的回调。
index:选中项的索引。
value:选中项的值。 | ## 示例 @@ -50,16 +51,16 @@ Select(options: Array\) struct SelectExample { build() { Column() { - Select([{value:'aaa',icon: "/common/1.png"}, - {value:'bbb',icon: "/common/2.png"}, - {value:'ccc',icon: "/common/3.png"}, - {value:'ddd',icon: "/common/4.png"}]) + Select([{ value: 'aaa', icon: "/common/1.png" }, + { value: 'bbb', icon: "/common/2.png" }, + { value: 'ccc', icon: "/common/3.png" }, + { value: 'ddd', icon: "/common/4.png" }]) .selected(2) .value('TTT') - .font({size: 30, weight:400, family: 'serif', style: FontStyle.Normal }) - .selectedOptionFont({size: 40, weight: 500, family: 'serif', style: FontStyle.Normal }) - .optionFont({size: 30, weight: 400, family: 'serif', style: FontStyle.Normal }) - .onSelect((index:number)=>{ + .font({ size: 30, weight: 400, family: 'serif', style: FontStyle.Normal }) + .selectedOptionFont({ size: 40, weight: 500, family: 'serif', style: FontStyle.Normal }) + .optionFont({ size: 30, weight: 400, family: 'serif', style: FontStyle.Normal }) + .onSelect((index: number) => { console.info("Select:" + index) }) } diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-slider.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-slider.md index e9de0a7fa0698da2ff19fe10516192f7675896ae..4fe6b16be395ba66a3cdf6effd5abe3e6a796aa9 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-slider.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-slider.md @@ -1,6 +1,6 @@ # Slider -滑动条组件,用来快速调节设置值,如音量、亮度等。 +滑动条组件,通常用于快速调节设置值,如音量调节、亮度调节等应用场景。 > **说明:** > @@ -23,10 +23,10 @@ Slider(options?:{value?: number, min?: number, max?: number, step?: number, styl | value | number | 否 | 当前进度值。
默认值:0 | | min | number | 否 | 设置最小值。
默认值:0 | | max | number | 否 | 设置最大值。
默认值:100 | -| step | number | 否 | 设置滑动条滑动步长。
默认值:1 | -| style | SliderStyle | 否 | 设置滑动条的滑块样式。
默认值:SliderStyle.OutSet | +| step | number | 否 | 设置Slider滑动步长。
默认值:1 | +| style | SliderStyle | 否 | 设置Slider的滑块与滑轨显示样式。
默认值:SliderStyle.OutSet | | direction8+ | [Axis](ts-appendix-enums.md#axis) | 否 | 设置滑动条滑动方向为水平或竖直方向。
默认值:Axis.Horizontal | -| reverse8+ | boolean | 否 | 设置滑动条取值范围是否反向。
**说明:**设置为false时,水平方向滑动条为从左向右滑动,竖直方向滑动条从上向下滑动,设置为true时,水平方向滑动条为从右向左滑动,竖直方向滑动条从下向上滑动。
默认值:false | +| reverse8+ | boolean | 否 | 设置滑动条取值范围是否反向,横向Slider默认为从左往右滑动,竖向Slider默认为从上往下滑动。
默认值:false | ## SliderStyle枚举说明 @@ -37,7 +37,7 @@ Slider(options?:{value?: number, min?: number, max?: number, step?: number, styl ## 属性 -不支持触摸热区设置。 +支持除触摸热区以外的通用属性设置。 | 名称 | 参数类型 | 描述 | | ------------- | ------- | ----------------- | @@ -45,7 +45,7 @@ Slider(options?:{value?: number, min?: number, max?: number, step?: number, styl | trackColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置滑轨的背景颜色。 | | selectedColor | [ResourceColor](ts-types.md#resourcecolor8) | 设置滑轨的已滑动颜色。 | | showSteps | boolean | 设置当前是否显示步长刻度值。
默认值:false | -| showTips | boolean | 设置滑动时是否显示气泡提示百分比。
默认值:false | +| showTips | boolean | 设置滑动时是否显示百分比气泡提示。
默认值:false | | trackThickness | [Length](ts-types.md#length) | 设置滑轨的粗细。 | | maxLabel | string | 设置最大标签。 | | minLabel | string | 设置最小标签。 | @@ -53,20 +53,20 @@ Slider(options?:{value?: number, min?: number, max?: number, step?: number, styl ## 事件 -通用事件仅支持:OnAppear,OnDisAppear。 +通用事件仅支持挂载卸载事件:OnAppear,OnDisAppear。 -| 名称 | 功能描述 | -| ---------------------------------------- | ---------------------------------------- | -| onChange(callback: (value: number, mode: SliderChangeMode) => void) | Slider滑动时触发事件回调。
value:当前进度值。
mode:拖动状态。 | +| 名称 | 功能描述 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| onChange(callback: (value: number, mode: SliderChangeMode) => void) | Slider滑动时触发事件回调。
value:当前滑动进度值。若返回值有小数,可使用Math.toFixed()方法将数据处理为预期的精度。
mode:拖动状态。 | ## SliderChangeMode枚举说明 | 名称 | 值 | 描述 | | ------ | ---- | --------- | -| Begin | 0 | 用户开始拖动滑块。 | -| Moving | 1 | 用户拖动滑块中。 | -| End | 2 | 用户结束拖动滑块。 | -| Click | 3 | 用户点击滑动条使滑块位置移动。 | +| Begin | 0 | 开始拖动滑块。 | +| Moving | 1 | 正在拖动滑块中。 | +| End | 2 | 结束拖动滑块。 | +| Click | 3 | 点击滑动条使滑块位置移动。 | ## 示例 @@ -75,105 +75,150 @@ Slider(options?:{value?: number, min?: number, max?: number, step?: number, styl @Entry @Component struct SliderExample { - @State outSetValue: number = 40 - @State inSetValue: number = 40 - @State outVerticalSetValue: number = 40 - @State inVerticalSetValue: number = 40 + @State outSetValueOne: number = 40; + @State inSetValueOne: number = 40; + @State outSetValueTwo: number = 40; + @State inSetValueTwo: number = 40; + @State vOutSetValueOne: number = 40; + @State vInSetValueOne: number = 40; + @State vOutSetValueTwo: number = 40; + @State vInSetValueTwo: number = 40; build() { - Column({ space: 5 }) { - Text('slider out set').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column({ space: 8 }) { + Text('outset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15) Row() { Slider({ - value: this.outSetValue, + value: this.outSetValueOne, min: 0, max: 100, - step: 1, style: SliderStyle.OutSet }) - .blockColor(Color.Blue) - .trackColor(Color.Gray) - .selectedColor(Color.Blue) - .showSteps(true) - .showTips(true) - .onChange((value: number, mode: SliderChangeMode) => { - this.outSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) + .showTips(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.outSetValueOne = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + // toFixed(0)将滑动条返回值处理为整数精度 + Text(this.outSetValueOne.toFixed(0)).fontSize(12) + } + .width('80%') + Row() { + Slider({ + value: this.outSetValueTwo, + step: 10, + style: SliderStyle.OutSet }) - Text(this.outSetValue.toFixed(0)).fontSize(16) + .showSteps(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.outSetValueTwo = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + Text(this.outSetValueTwo.toFixed(0)).fontSize(12) } - .padding({ top: 50 }) .width('80%') - Text('slider in set').fontSize(9).fontColor(0xCCCCCC).width('90%') + Text('inset slider').fontSize(9).fontColor(0xCCCCCC).width('90%').margin(15) Row() { Slider({ - value: this.inSetValue, + value: this.inSetValueOne, min: 0, max: 100, - step: 1, style: SliderStyle.InSet }) - .blockColor(0xCCCCCC) - .trackColor(Color.Black) - .selectedColor(0xCCCCCC) - .showSteps(false) - .showTips(false) - .onChange((value: number, mode: SliderChangeMode) => { - this.inSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) - }) - Text(this.inSetValue.toFixed(0)).fontSize(16) + .blockColor('#191970') + .trackColor('#ADD8E6') + .selectedColor('#4169E1') + .showTips(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.inSetValueOne = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + Text(this.inSetValueOne.toFixed(0)).fontSize(12) } .width('80%') - Row() { - Column() { - Text('slider out direction set').fontSize(9).fontColor(0xCCCCCC).width('50%') - Slider({ - value: this.outVerticalSetValue, - min: 0, - max: 100, - step: 1, - style: SliderStyle.OutSet, - direction: Axis.Vertical - }) - .blockColor(Color.Blue) - .trackColor(Color.Gray) - .selectedColor(Color.Blue) + Slider({ + value: this.inSetValueTwo, + step: 10, + style: SliderStyle.InSet + }) + .blockColor('#191970') + .trackColor('#ADD8E6') + .selectedColor('#4169E1') .showSteps(true) - .showTips(true) .onChange((value: number, mode: SliderChangeMode) => { - this.outVerticalSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) + this.inSetValueTwo = value; + console.info('value:' + value + 'mode:' + mode.toString()); }) - Text(this.outVerticalSetValue.toFixed(0)).fontSize(16) + Text(this.inSetValueTwo.toFixed(0)).fontSize(12) + } + .width('80%') + + Row() { + Column() { + Text('vertical outset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15) + Row() { + Slider({ + value: this.vOutSetValueOne, + style: SliderStyle.OutSet, + direction: Axis.Vertical + }) + .blockColor('#191970') + .trackColor('#ADD8E6') + .selectedColor('#4169E1') + .showTips(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.vOutSetValueOne = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + Slider({ + value: this.vOutSetValueTwo, + step: 10, + style: SliderStyle.OutSet, + direction: Axis.Vertical + }) + .blockColor('#191970') + .trackColor('#ADD8E6') + .selectedColor('#4169E1') + .showSteps(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.vOutSetValueTwo = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + } }.width('50%').height(300) Column() { - Text('slider in direction set').fontSize(9).fontColor(0xCCCCCC).width('50%') - Slider({ - value: this.inVerticalSetValue, - min: 0, - max: 100, - step: 1, - style: SliderStyle.InSet, - direction: Axis.Vertical - }) - .blockColor(0xCCCCCC) - .trackColor(Color.Black) - .selectedColor(0xCCCCCC) - .showSteps(false) - .showTips(false) - .onChange((value: number, mode: SliderChangeMode) => { - this.inVerticalSetValue = value - console.info('value:' + value + 'mode:' + mode.toString()) - }) - Text(this.inVerticalSetValue.toFixed(0)).fontSize(16) + Text('vertical inset slider').fontSize(9).fontColor(0xCCCCCC).width('50%').margin(15) + Row() { + Slider({ + value: this.vInSetValueOne, + style: SliderStyle.InSet, + direction: Axis.Vertical, + reverse: true // 竖向的Slider默认是上端是min值,下端是max值,因此想要从下往上滑动,需要设置reverse为true + }) + .showTips(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.vInSetValueOne = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + Slider({ + value: this.vInSetValueTwo, + step: 10, + style: SliderStyle.InSet, + direction: Axis.Vertical, + reverse: true + }) + .showSteps(true) + .onChange((value: number, mode: SliderChangeMode) => { + this.vInSetValueTwo = value; + console.info('value:' + value + 'mode:' + mode.toString()); + }) + } }.width('50%').height(300) } - - }.width('100%').margin({ top: 5 }) + }.width('100%') } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-span.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-span.md index 7b25eb03b5e76a193ca614c23110c6118e69d7f8..5e615e7033fbe11e87ff2746df9547684a56f2d9 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-span.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-span.md @@ -1,6 +1,6 @@ # Span -文本段落,只能作为Text子组件,呈现一段文本信息。 +作为Text组件的子组件,用于显示行内文本的组件。 > **说明:** > @@ -16,26 +16,27 @@ Span(value: string | Resource) -**参数:** +**参数:** + +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| value | string \| [Resource](ts-types.md#resource) | 是 | 文本内容。 | -| 参数名 | 参数类型 | 必填 | 参数描述 | -| ------ | ---------------------------------------------------- | ---- | ---------- | -| value | string \| [Resource](ts-types.md#resource) | 是 | 文本内容。 | ## 属性 -通用属性方法仅支持通用文本样式,不支持触摸热区设置。 +通用属性方法仅支持[通用文本样式](ts-universal-attributes-text-style.md)。 -| 名称 | 参数类型 | 描述 | -| ---------- | ---------------------------------------- | -------------- | -| decoration | {
type: [TextDecorationType](ts-appendix-enums.md#textdecorationtype),
color?: [ResourceColor](ts-types.md#resourcecolor8)
} | 设置文本装饰线样式及其颜色。
默认值:{
type: TextDecorationType.None
color:Color.Black
} | -| letterSpacing | number \| string | 设置文本字符间距。 | -| textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。
默认值:Normal | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| decoration | {
type: [TextDecorationType](ts-appendix-enums.md#textdecorationtype),
color?: [ResourceColor](ts-types.md#resourcecolor)
} | 设置文本装饰线样式及其颜色。
默认值:{
type: TextDecorationType.None
color:Color.Black
} | +| letterSpacing | number \| string | 设置文本字符间距。取值小于0,字符聚集重叠,取值大于0且随着数值变大,字符间距越来越大,稀疏分布。 | +| textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。
默认值:TextCase.Normal | ## 事件 -通用事件仅支持点击事件。 +通用事件仅支持[点击事件](ts-universal-attributes-click.md)。 > **说明:** > @@ -57,29 +58,59 @@ struct SpanExample { .decoration({ type: TextDecorationType.None, color: Color.Red }) } + // 文本横线添加 Text('Text Decoration').fontSize(9).fontColor(0xCCCCCC) Text() { Span('I am Underline-span').decoration({ type: TextDecorationType.Underline, color: Color.Red }).fontSize(12) } + Text() { - Span('I am LineThrough-span').decoration({ type: TextDecorationType.LineThrough, color: Color.Red }).fontSize(12) + Span('I am LineThrough-span') + .decoration({ type: TextDecorationType.LineThrough, color: Color.Red }) + .fontSize(12) } + Text() { Span('I am Overline-span').decoration({ type: TextDecorationType.Overline, color: Color.Red }).fontSize(12) } + // 文本字符间距 + Text('LetterSpacing').fontSize(9).fontColor(0xCCCCCC) + Text() { + Span('span letter spacing') + .letterSpacing(0) + .fontSize(12) + } + + Text() { + Span('span letter spacing') + .letterSpacing(-2) + .fontSize(12) + } + + Text() { + Span('span letter spacing') + .letterSpacing(3) + .fontSize(12) + } + + + // 文本大小写展示设置 Text('Text Case').fontSize(9).fontColor(0xCCCCCC) Text() { - Span('I am Lower-span').textCase(TextCase.LowerCase).fontSize(12) - .decoration({ type: TextDecorationType.None, color: Color.Red }) + Span('I am Lower-span').fontSize(12) + .textCase(TextCase.LowerCase) + .decoration({ type: TextDecorationType.None }) } + Text() { - Span('I am Upper-span').textCase(TextCase.UpperCase).fontSize(12) - .decoration({ type: TextDecorationType.None, color: Color.Red }) + Span('I am Upper-span').fontSize(12) + .textCase(TextCase.UpperCase) + .decoration({ type: TextDecorationType.None }) } }.width('100%').height(250).padding({ left: 35, right: 35, top: 35 }) } } ``` -![zh-cn_image_0000001219982709](figures/zh-cn_image_0000001219982709.gif) +![span](figures/span.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepper.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepper.md index e1f8add9d7b0626bd9aed7a97e55a6a14d94ac18..e6f5b3aca6fc7e95806dcae9c20259ad2458d826 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepper.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepper.md @@ -1,6 +1,6 @@ # Stepper -步骤导航器。 +步骤导航器组件,适用于引导用户按照步骤完成任务的导航场景。 > **说明:** @@ -8,11 +8,6 @@ > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 子组件 仅能包含子组件[StepperItem](ts-basic-components-stepperitem.md)。 @@ -24,9 +19,9 @@ Stepper(value?: { index?: number }) **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ----- | ------ | ---- | ---- | ------------------------ | -| index | number | 否 | 0 | 设置步骤导航器显示第几个StepperItem。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| ------ | -------- | ---- | ------ | ------------------------------------------- | +| index | number | 否 | 0 | 设置步骤导航器当前显示StepperItem的索引值。 | ## 属性 @@ -35,13 +30,13 @@ Stepper(value?: { index?: number }) ## 事件 -| 名称 | 描述 | -| ---------------------------------------- | ---------------------------------------- | -| onFinish(callback: () => void) | 步骤导航器最后一个StepperItem的nextLabel被点击时触发该回调 。 | -| onSkip(callback: () => void) | 当前显示的StepperItem状态为ItemState.Skip时,nextLabel被点击时触发该回调。 | -| onChange(callback: (prevIndex?: number, index?: number) => void) | 点击左边或者右边文本按钮进行步骤切换时触发该事件。
- prevIndex:切换前的步骤页索引值。
- index:切换后的步骤页(前一页或者下一页)索引值。 | -| onNext(callback: (index?: number, pendingIndex?: number) => void) | 点击切换下一步骤时触发该事件。
- index:当前步骤页索引值。
- pendingIndex:下一步骤页索引值。 | -| onPrevious(callback: (index?: number, pendingIndex?: number) => void) | 点击切换上一步骤时触发该事件。
- index:当前步骤页索引值。
- pendingIndex:上一步骤页索引值。 | +| 名称 | 描述 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| onFinish(callback: () => void) | 步骤导航器最后一个StepperItem的nextLabel被点击时触发该回调 。 | +| onSkip(callback: () => void) | 当前显示的StepperItem状态为ItemState.Skip时,nextLabel被点击时触发该回调。 | +| onChange(callback: (prevIndex?: number, index?: number) => void) | 点击当前StepperItem的prevLabel或nextLabel进行步骤切换时触发该回调。
- prevIndex:切换前的步骤页索引值。
- index:切换后的步骤页(前一页或者下一页)索引值。 | +| onNext(callback: (index?: number, pendingIndex?: number) => void) | 点击StepperItem的nextLabel切换下一步骤时触发该回调。
- index:当前步骤页索引值。
- pendingIndex:下一步骤页索引值。 | +| onPrevious(callback: (index?: number, pendingIndex?: number) => void) | 点击StepperItem的prevLabel切换上一步骤时触发该回调。
- index:当前步骤页索引值。
- pendingIndex:上一步骤页索引值。 | ## 示例 @@ -51,73 +46,86 @@ Stepper(value?: { index?: number }) @Entry @Component struct StepperExample { - @State currentIndex: number = 0 - @State firstState: ItemState = ItemState.Normal - @State secondState: ItemState = ItemState.Normal + @State currentIndex: number = 0; + @State firstState: ItemState = ItemState.Normal; + @State secondState: ItemState = ItemState.Normal; + @State thirdState: ItemState = ItemState.Normal; build() { Stepper({ index: this.currentIndex }) { + // 第一个步骤页 StepperItem() { - Text('Page One') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) + Column() { + Text('Page One') + .fontSize(35) + .fontColor(Color.Blue) + .lineHeight(50) + .margin({ top: 250, bottom: 50 }) + Button('change status:' + this.firstState) + .onClick(() => { + this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip; + }) + }.width('100%') } - .nextLabel('') - .position({x: '35%', y: 0}) + .nextLabel('Next') + .status(this.firstState) + // 第二个步骤页 StepperItem() { - Text('Page Two') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) - .onClick(()=>{ - this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip - }) + Column() { + Text('Page Two') + .fontSize(35) + .fontColor(Color.Blue) + .lineHeight(50) + .margin({ top: 250, bottom: 50 }) + Button('change status:' + this.secondState) + .onClick(() => { + this.secondState = this.secondState === ItemState.Disabled ? ItemState.Normal : ItemState.Disabled; + }) + }.width('100%') } .nextLabel('Next') .prevLabel('Previous') - .status(this.firstState) - .position({x: '35%', y: 0}) + .status(this.secondState) + // 第三个步骤页 StepperItem() { - Text('Page Three') - .fontSize(35) - .fontColor(Color.Blue) - .width(200) - .lineHeight(50) - .margin({top:250}) - .onClick(()=>{ - this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting - }) + Column() { + Text('Page Three') + .fontSize(35) + .fontColor(Color.Blue) + .lineHeight(50) + .margin({ top: 250, bottom: 50 }) + Button('change status:' + this.thirdState) + .onClick(() => { + this.thirdState = this.thirdState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting; + }) + }.width('100%') } - .position({x: '35%', y: 0}) - .status(this.secondState) + .status(this.thirdState) + // 第四个步骤页 StepperItem() { Text('Page four') .fontSize(35) .fontColor(Color.Blue) - .width(200) + .width('100%') + .textAlign(TextAlign.Center) .lineHeight(50) - .margin({top:250}) + .margin({ top: 250 }) } - .position({x: '35%', y: 0}) .nextLabel('Finish') } .onFinish(() => { - console.log('onFinish') + // 此处可处理点击最后一页的Finish时的逻辑,例如路由跳转等 + console.info('onFinish'); }) .onSkip(() => { - console.log('onSkip') + // 此处可处理点击跳过时的逻辑,例如动态修改Stepper的index值使其跳转到某一步骤页等 + console.info('onSkip'); }) .onChange((prevIndex: number, index: number) => { - this.currentIndex = index + this.currentIndex = index; }) - .align(Alignment.Center) } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepperitem.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepperitem.md index 3489c498f04106e62f7f06b2e2eb6759d2f73551..1ab2a36dbbcd0d7949a19858c34b34754da67914 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepperitem.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-stepperitem.md @@ -1,6 +1,6 @@ # StepperItem -步骤导航器元素。 +用作[Stepper](ts-basic-components-stepper.md)组件的页面子组件 > **说明:** @@ -8,11 +8,6 @@ > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 子组件 支持单个子组件。 @@ -25,20 +20,20 @@ StepperItem() ## 属性 -| 参数名 | 参数类型 | 默认值 | 参数描述 | -| --------- | --------- | ---------------- | ------------------------------------- | -| prevLabel | string | - | 当步骤导航器大于一页,除第一页默认值都为"返回"。 | -| nextLabel | string | - | 步骤导航器大于一页时,最后一页默认值为"开始",其余页默认值为"下一步"。 | -| status | ItemState | ItemState.Normal | 步骤导航器元素的状态。 | +| 参数名 | 参数类型 | 参数描述 | +| --------- | --------- | ------------------------------------------------------------ | +| prevLabel | string | 设置左侧文本按钮内容,第一页没有左侧文本按钮,当步骤导航器大于一页时,除第一页外默认值都为“返回”。 | +| nextLabel | string | 设置右侧文本按钮内容,最后一页默认值为“开始”,其余页默认值为“下一步”。 | +| status | ItemState | 步骤导航器nextLabel的显示状态。
默认值:ItemState.Normal | ## ItemState枚举说明 -| 名称 | 描述 | -| -------- | ---------------------------------------- | -| Normal | 正常状态,右侧文本按钮正常显示,可点击进入下一个StepperItem。 | -| Disabled | 不可用状态,右侧文本按钮灰度显示,不可点击进入下一个StepperItem。 | -| Waiting | 等待状态,右侧文本按钮不显示,使用等待进度条,不可点击进入下一个StepperItem。 | -| Skip | 跳过状态,表示跳过当前步骤, 进入下一个StepperItem。 | +| 名称 | 值 | 描述 | +| -------- | ---- | ------------------------------------------------------------ | +| Normal | 0 | 正常状态,右侧文本按钮正常显示,可点击进入下一个StepperItem。 | +| Disabled | 1 | 不可用状态,右侧文本按钮灰度显示,不可点击进入下一个StepperItem。 | +| Waiting | 2 | 等待状态,右侧文本按钮不显示,显示等待进度条,不可点击进入下一个StepperItem。 | +| Skip | 3 | 跳过状态,右侧文本按钮显示“跳过”,此时可在Stepper的onSkip回调中自定义相关逻辑。 | ## 示例 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-text.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-text.md index b79b655518acbd8c42c6425d063ac053de89baff..79498c8d67311ba7ff356a9c90e8358c80dd6c1d 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-text.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-text.md @@ -1,6 +1,6 @@ # Text -文本,用于呈现一段信息。 +显示一段文本的组件。 > **说明:** > @@ -18,33 +18,37 @@ Text(content?: string | Resource) **参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| ------- | ------------------------------------------ | ---- | ------------------------------------------------------------ | -| content | string \| [Resource](ts-types.md#resource) | 否 | 文本内容。包含子组件Span时不生效,显示Span内容,并且此时text组件的样式不生效。
默认值:' ' | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| content | string \| [Resource](ts-types.md#resource) | 否 | 文本内容。包含子组件Span时不生效,显示Span内容,并且此时text组件的样式不生效。
默认值:' ' | ## 属性 -| 名称 | 参数类型 | 描述 | -| -------------- | ---------------------------------------- | ---------------------------------------- | -| textAlign | [TextAlign](ts-appendix-enums.md#textalign) | 设置多行文本的文本对齐方式。
默认值:TextAlign.Start | -| textOverflow | {overflow: [TextOverflow](ts-appendix-enums.md#textoverflow)} | 设置文本超长时的显示方式。
默认值:{overflow: TextOverflow.Clip}
**说明:**
文本截断是按字截断。例如,英文以单词为最小单位进行截断,若需要以字母为单位进行截断,可在字母间添加零宽空格:\u200B。 | -| maxLines | number | 设置文本的最大行数。
默认值:Infinity | -| lineHeight | string \| number \| [Resource](ts-types.md#resource) | 设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。 | -| decoration | {
type: [TextDecorationType](ts-appendix-enums.md#textdecorationtype),
color?: [ResourceColor](ts-types.md#resourcecolor8)
} | 设置文本装饰线样式及其颜色。
默认值:{
type: TextDecorationType.None,
color:Color.Black
} | -| baselineOffset | number \| string | 设置文本基线的偏移量。 | -| letterSpacing | number \| string | 设置文本字符间距。 | -| minFontSize | number \| string \| [Resource](ts-types.md#resource) | 设置文本最小显示字号。 | -| maxFontSize | number \| string \| [Resource](ts-types.md#resource) | 设置文本最大显示字号。 | -| textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。
默认值:TextCase.Normal | - +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: + +| 名称 | 参数类型 | 描述 | +| ----------------------- | ----------------------------------- | ------------------------------------------- | +| textAlign | [TextAlign](ts-appendix-enums.md#textalign) | 设置文本在水平方向的对齐方式。
默认值:TextAlign.Start | +| textOverflow | {overflow: [TextOverflow](ts-appendix-enums.md#textoverflow)} | 设置文本超长时的显示方式。
默认值:{overflow: TextOverflow.Clip}
**说明:**
文本截断是按字截断。例如,英文以单词为最小单位进行截断,若需要以字母为单位进行截断,可在字母间添加零宽空格:\u200B。
需配合`maxLines`使用,单独设置不生效。 | +| maxLines | number | 设置文本的最大行数。
默认值:Infinity
**说明:**
默认情况下,文本是自动折行的,如果指定此参数,则文本最多不会超过指定的行。如果有多余的文本,可以通过 `textOverflow`来指定截断方式。 | +| lineHeight | string \| number \| [Resource](ts-types.md#resource) | 设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。 | +| decoration | {
type: [TextDecorationType](ts-appendix-enums.md#textdecorationtype),
color?: [ResourceColor](ts-types.md#resourcecolor)
} | 设置文本装饰线样式及其颜色。
默认值:{
type: TextDecorationType.None,
color:Color.Black
} | +| baselineOffset | number \| string | 设置文本基线的偏移量,默认值0。 | +| letterSpacing | number \| string | 设置文本字符间距。 | +| minFontSize | number \| string \| [Resource](ts-types.md#resource) | 设置文本最小显示字号。 | +| maxFontSize | number \| string \| [Resource](ts-types.md#resource) | 设置文本最大显示字号。 | +| textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。
默认值:TextCase.Normal | +| copyOption9+ | [CopyOptions](ts-appendix-enums.md#copyoptions9) | 组件支持设置文本是否可复制粘贴。
默认值:CopyOptions.None | > **说明:** > -> 不支持Text内同时存在文本内容和Span子组件。(如果同时存在,只显示Span内的内容)。 +> 不支持Text内同时存在文本内容和Span子组件。如果同时存在,只显示Span内的内容。 ## 示例 +### 示例1 +textAlign,textOverflow,maxLines,lineHeight使用示例。 ```ts // xxx.ets @Entry @@ -52,77 +56,184 @@ Text(content?: string | Resource) struct TextExample1 { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { - Text('lineHeight').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text with the line height set This is the text with the line height set This is the text with the line height set.') - .lineHeight(25).fontSize(12).border({ width: 1 }).padding(10) + // 文本水平方向对齐方式设置 + // 单行文本 + Text('textAlign').fontSize(9).fontColor(0xCCCCCC) + Text('TextAlign set to Center.') + .textAlign(TextAlign.Center) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('TextAlign set to Start.') + .textAlign(TextAlign.Start) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('TextAlign set to End.') + .textAlign(TextAlign.End) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + + // 多行文本 + Text('This is the text content with textAlign set to Center.') + .textAlign(TextAlign.Center) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('This is the text content with textAlign set to Start.') + .textAlign(TextAlign.Start) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('This is the text content with textAlign set to End.') + .textAlign(TextAlign.End) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + - Text('TextOverflow').fontSize(9).fontColor(0xCCCCCC) - Text('This is the setting of textOverflow to none text content This is the setting of textOverflow to none text content.') + // 文本超长时显示方式 + Text('TextOverflow+maxLines').fontSize(9).fontColor(0xCCCCCC) + // 超出maxLines截断内容展示 + Text('This is the setting of textOverflow to Clip text content This is the setting of textOverflow to None text content. This is the setting of textOverflow to Clip text content This is the setting of textOverflow to None text content.') .textOverflow({ overflow: TextOverflow.None }) - .fontSize(12).border({ width: 1 }).padding(10) - Text('This is the setting of textOverflow to Clip text content This is the setting of textOverflow to Clip text content.') - .textOverflow({ overflow: TextOverflow.Clip }) - .maxLines(1).fontSize(12).border({ width: 1 }).padding(10) - Text('This is set textOverflow to Ellipsis text content This is set textOverflow to Ellipsis text content.'.split('').join('\u200B')) + .maxLines(1) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + + // 超出maxLines展示省略号 + Text('This is set textOverflow to Ellipsis text content This is set textOverflow to Ellipsis text content.'.split('') + .join('\u200B')) .textOverflow({ overflow: TextOverflow.Ellipsis }) - .maxLines(1).fontSize(12).border({ width: 1 }).padding(10) + .maxLines(1) + .fontSize(12) + .border({ width: 1 }) + .padding(10) - Text('decoration').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with the decoration set to Underline and the color set to Red.') - .decoration({ type: TextDecorationType.Underline, color: Color.Red }) + Text('lineHeight').fontSize(9).fontColor(0xCCCCCC) + Text('This is the text with the line height set. This is the text with the line height set.') .fontSize(12).border({ width: 1 }).padding(10) - Text('This is the text content with the decoration set to LineThrough and the color set to Red.') - .decoration({ type: TextDecorationType.LineThrough, color: Color.Red }) - .fontSize(12).border({ width: 1 }).padding(10) - Text('This is the text content with the decoration set to Overline and the color set to Red.') - .decoration({ type: TextDecorationType.Overline, color: Color.Red }) + Text('This is the text with the line height set. This is the text with the line height set.') .fontSize(12).border({ width: 1 }).padding(10) + .lineHeight(20) }.height(600).width(350).padding({ left: 35, right: 35, top: 35 }) } } ``` +![textExp1](figures/textExp1.png) -![zh-cn_image_0000001219864155](figures/zh-cn_image_0000001219864155.gif) - +### 示例2 +decoration,baselineOffset,letterSpacing,textCase使用示例: ```ts -// xxx.ets @Entry @Component struct TextExample2 { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { + Text('decoration').fontSize(9).fontColor(0xCCCCCC) + Text('This is the text content with the decoration set to LineThrough and the color set to Red.') + .decoration({ + type: TextDecorationType.LineThrough, + color: Color.Red + }) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + + + Text('This is the text content with the decoration set to Overline and the color set to Red.') + .decoration({ + type: TextDecorationType.Overline, + color: Color.Red + }) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + + + Text('This is the text content with the decoration set to Underline and the color set to Red.') + .decoration({ + type: TextDecorationType.Underline, + color: Color.Red + }) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + + // 文本基线偏移 + Text('baselineOffset').fontSize(9).fontColor(0xCCCCCC) + Text('This is the text content with baselineOffset 0.') + .baselineOffset(0) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('This is the text content with baselineOffset 30.') + .baselineOffset(30) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('This is the text content with baselineOffset -20.') + .baselineOffset(-20) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + + // 文本字符间距 + Text('letterSpacing').fontSize(9).fontColor(0xCCCCCC) + Text('This is the text content with letterSpacing 0.') + .letterSpacing(0) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('This is the text content with letterSpacing 3.') + .letterSpacing(3) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('This is the text content with letterSpacing -1.') + .letterSpacing(-1) + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + Text('textCase').fontSize(9).fontColor(0xCCCCCC) Text('This is the text content with textCase set to Normal.') .textCase(TextCase.Normal) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + // 文本全小写展示 Text('This is the text content with textCase set to LowerCase.') .textCase(TextCase.LowerCase) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') + .fontSize(12) + .border({ width: 1 }) + .padding(10) + .width('100%') + // 文本全大写展示 Text('This is the text content with textCase set to UpperCase.') .textCase(TextCase.UpperCase) .fontSize(12).border({ width: 1 }).padding(10) - Text('textAlign').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with textAlign set to Center.') - .textAlign(TextAlign.Center) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with textAlign set to Start.') - .textAlign(TextAlign.Start) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with textAlign set to End.') - .textAlign(TextAlign.End) - .fontSize(12).border({ width: 1 }).padding(10).width('100%') - - Text('baselineOffset').fontSize(9).fontColor(0xCCCCCC) - Text('This is the text content with baselineOffset set to 10.') - .baselineOffset(10).fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with baselineOffset set to 30.') - .baselineOffset(30).fontSize(12).border({ width: 1 }).padding(10).width('100%') - Text('This is the text content with baselineOffset set to -10.') - .baselineOffset(-10).fontSize(12).border({ width: 1 }).padding(10).width('100%') }.height(700).width(350).padding({ left: 35, right: 35, top: 35 }) } } ``` - -![zh-cn_image_0000001174422918](figures/zh-cn_image_0000001174422918.gif) +![textExp1](figures/textExp2.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md index d9561b1169809ef4cca57c40d654acd311ee6ef6..95e25422c9c3ac4c55e19a18fdabd33427b42ff0 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textclock.md @@ -1,14 +1,10 @@ # TextClock -TextClock通过文本显示当前系统时间,支持不同时区的时间显示,时间显示最高精度到秒级。 +TextClock组件通过文本将当前系统时间显示在设备上。支持不同时区的时间显示,最高精度到秒级。 -> **说明:** +>**说明:** > -> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 +>该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 子组件 @@ -16,26 +12,15 @@ TextClock通过文本显示当前系统时间,支持不同时区的时间显 ## 接口 -TextClock(options?: {timeZoneOffset?: number, controller?: TextClockController}) +TextClock(options?: { timeZoneOffset?: number, controller?: TextClockController }) -**参数:** +**参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| -------------- | ------------------------------------------- | ---- | ---------- | ------------------------------------------------------------ | -| timeZoneOffset | number | 否 | 时区偏移量 | 设置时区偏移量。取值范围为[-14, 12],表示东十二区到西十二区,其中负值表示东时区,正值表示西时区,比如东八区为-8;对横跨国际日界线的国家或地区,用-13(UTC+13)和-14(UTC+14)来保证整个国家或者区域处在相同的时间。 | -| controller | [TextClockController](#textclockcontroller) | 否 | null | 绑定一个控制器,用来控制文本时钟的状态。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------------- | -------- | ------ | --------------------------------------------------------------------------- | +| timeZoneOffset | number | 否 | 设置时区偏移量。
取值范围为[-14, 12],表示东十二区到西十二区,其中负值表示东时区,正值表示西时区,比如东八区为-8。
对横跨国际日界线的国家或地区,用-13(UTC+13)和-14(UTC+14)来保证整个国家或者区域处在相同的时间,当设置的值不在取值范围内时,将使用当前系统的时区偏移量。
默认值:当前系统的时区偏移量 | +| controller | [TextClockController](#textclockcontroller) | 否 | 绑定一个控制器,用来控制文本时钟的状态。| -## 属性 - -| 名称 | 参数类型 | 默认值 | 描述 | -| ------ | -------- | ------ | ------------------------------------------------------------ | -| format | string | 'hms' | 设置显示时间格式。
日期间隔符固定为"/",时间间隔符为":"。
如yyyyMMdd,yyyy-MM-dd显示为yyyy/MM/dd,
hhmmss显示为hh:mm:ss。
时间格式只用写一位即可,如"hhmmss"等同于"hms"。
支持的时间格式化字符串:
- YYYY/yyyy:完整年份。
- YY/yy:年份后两位。
- M:月份(若想使用01月则使用MM)。
- d:日期(若想使用01日则使用dd)。
- D:年中日(一年中的第几天)。
- H:24小时制。
- h:12小时制。
- m:分钟。
- s:秒。
- SSS:毫秒。 | - -## 事件 - -| 名称 | 功能描述 | -| ---------------------------------------- | ---------------------------------------- | -| onDateChange(event: (value: number) => void) | 提供时间变化回调,该事件最小回调间隔为秒。
value: Unix Time Stamp,即自1970年1月1日(UTC)起经过的毫秒数。 | ## TextClockController @@ -43,9 +28,8 @@ TextClock容器组件的控制器,可以将此对象绑定到TextClock组件 ### 导入对象 -``` -controller: TextClockController = new TextClockController() - +```ts +controller: TextClockController = new TextClockController(); ``` ### start @@ -61,41 +45,60 @@ stop() 停止文本时钟。 +## 属性 + +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: + +| 名称 | 参数类型 | 描述 | +| ------ | --------------- | ------------------------------------------------------------ | +| format | string | 设置显示时间格式。
日期间隔符固定为"/",时间间隔符为":"。
如yyyyMMdd,yyyy-MM-dd显示为yyyy/MM/dd,
hhmmss显示为hh:mm:ss。
时间格式只用写一位即可,如"hhmmss"等同于"hms"。
支持的时间格式化字符串:
- YYYY/yyyy:完整年份。
- YY/yy:年份后两位。
- M:月份(若想使用01月则使用MM)。
- d:日期(若想使用01日则使用dd)。
- D:年中日(一年中的第几天)。
- H:24小时制。
- h:12小时制。
- m:分钟。
- s:秒。
- SSS:毫秒。
默认值: 'hms'| + +## 事件 + +除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件: + +| 名称 | 功能描述 | +| -------------------------------------------- | ------------------------------------------------------------ | +| onDateChange(event: (value: number) => void) | 提供时间变化回调,该事件最小回调间隔为秒。
value: Unix Time Stamp,即自1970年1月1日(UTC)起经过的毫秒数。 | + + ## 示例 ```ts -// xxx.ets @Entry @Component struct Second { - @State accumulateTime: number = 0 - controller: TextClockController = new TextClockController() - + @State accumulateTime: number = 0; + // 导入对象 + controller: TextClockController = new TextClockController(); build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center}) { - Text('current milliseconds is' + this.accumulateTime) - .fontSize(20) - TextClock({timeZoneOffset: -8, controller: this.controller}) - .format('hhmmss') - .onDateChange((value: number) => { - this.accumulateTime = value - }) - .margin(20) - .fontSize(30) - Button("start TextClock") - .margin({ bottom: 10 }) - .onClick(()=>{ - this.controller.start() - }) - Button("stop TextClock") - .onClick(()=>{ - this.controller.stop() - }) - } + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Current milliseconds is ' + this.accumulateTime) + .fontSize(20) + // 以12小时制显示东八区的系统时间,精确到秒。 + TextClock({ timeZoneOffset: -8, controller: this.controller }) + .format('hms') + .onDateChange((value: number) => { + this.accumulateTime = value; + }) + .margin(20) + .fontSize(30) + Button("start TextClock") + .margin({ bottom: 10 }) + .onClick(() => { + // 启动文本时钟 + this.controller.start(); + }) + Button("stop TextClock") + .onClick(() => { + // 停止文本时钟 + this.controller.stop(); + }) + } .width('100%') .height('100%') } } ``` -![](figures/text_clock.png) +![text_clock](figures/text_clock.gif) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md index 33d9d449208361ec6c1ee2ba3e7e34245390015c..feea880eb6a5486c8bbf2263ecfdc93bcb520ed6 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-textpicker.md @@ -1,6 +1,6 @@ # TextPicker -文本类滑动选择器组件。 +滚动选择文本的组件。 > **说明:** > @@ -14,29 +14,30 @@ ## 接口 -TextPicker(options?: {range: string[] | [Resource](ts-types.md#resource), selected?: number, value?: string}) +TextPicker(options?: {range: string[]|Resource, selected?: number, value?: string}) 根据range指定的选择范围创建文本选择器。 **参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| -------- | -------- | ---- | --------------- | -| range | string[] \| [Resource](ts-types.md#resource) | 是 | 选择器的数据选择范围。 | -| selected | number | 否 | 选中项在数组中的index值。
默认值:0 | -| value | string | 否 | 选中项的值,优先级低于selected。
默认值:第一个元素值 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| range | string[] \| [Resource](ts-types.md#resource类型) | 是 | 选择器的数据选择列表。 | +| selected | number | 否 | 设置默认选中项在数组中的index值。
默认值:0 | +| value | string | 否 | 设置默认选中项的值,优先级低于selected。
默认值:第一个元素值 | ## 属性 -| 名称 | 参数类型 | 描述 | -| ----------------------- | ---------------- | -------------------------- | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | | defaultPickerItemHeight | number \| string | 默认Picker内容项元素高度。 | - ## 事件 -| 名称 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | +除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件: + +| 名称 | 描述 | +| -------- | -------- | | onChange(callback: (value: string, index: number) => void) | 滑动选中TextPicker文本内容后,触发该回调。
- value: 当前选中项的文本。
- index: 当前选中项的索引值。 | diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md index 9cb2c0c6c2c1bd960946495cc7ce73f6f86fabc4..e8921962c2303f39645514f50a748721587803aa 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-longpressgesture.md @@ -32,24 +32,31 @@ LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number @Entry @Component struct LongPressGestureExample { - @State count: number = 0 + @State count: number = 0; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('LongPress onAction:' + this.count) + Column() { + Text('LongPress onAction:' + this.count).fontSize(28) + // 单指长按文本触发该手势事件 + .gesture( + LongPressGesture({ repeat: true }) + // 由于repeat设置为true,长按动作存在时会连续触发,触发间隔为duration(默认值500ms) + .onAction((event: GestureEvent) => { + if (event.repeat) { + this.count++; + } + }) + // 长按动作一结束触发 + .onActionEnd(() => { + this.count = 0; + }) + ) } - .height(200).width(300).padding(60).border({ width:1 }).margin(30) - .gesture( - LongPressGesture({ repeat: true }) - //长按动作存在会连续触发 - .onAction((event: GestureEvent) => { - if (event.repeat) { this.count++ } - }) - //长按动作一结束触发 - .onActionEnd(() => { - this.count = 0 - }) - ) + .height(200) + .width(300) + .padding(20) + .border({ width: 3 }) + .margin(30) } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md index cc9e5454901204c10a0d132a1e62a62a3f13f3ab..a12e81990fbae5ca7132a4c8e61e367ca605c97e 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pangesture.md @@ -20,16 +20,16 @@ PanGesture(value?: { fingers?: number, direction?: PanDirection, distance?: numb ## PanDirection枚举说明 - | 名称 | 描述 | - | -------- | -------- | - | All | 所有方向。 | - | Horizontal | 水平方向。 | - | Vertical | 竖直方向。 | - | Left | 向左拖动。 | - | Right | 向右拖动。 | - | Up | 向上拖动。 | - | Down | 向下拖动。 | - | None | 任何方向都不可触发拖动手势事件。 | +| 名称 | 描述 | +| -------- | -------- | +| All | 所有方向。 | +| Horizontal | 水平方向。 | +| Vertical | 竖直方向。 | +| Left | 向左拖动。 | +| Right | 向右拖动。 | +| Up | 向上拖动。 | +| Down | 向下拖动。 | +| None | 任何方向都不可触发拖动手势事件。 | ## PanGestureOptions @@ -44,11 +44,11 @@ PanGestureOptions(options?: { fingers?: number, direction?: PanDirection, distan **接口:** - | 名称 | 功能描述 | - | -------- | -------- | - | setDirection(value: PanDirection) | 设置direction属性。 | - | setDistance(value: number) | 设置distance属性。 | - | setFingers(value: number) | 设置fingers属性。 | +| 名称 | 功能描述 | +| -------- | -------- | +| setDirection(value: PanDirection) | 设置direction属性。 | +| setDistance(value: number) | 设置distance属性。 | +| setFingers(value: number) | 设置fingers属性。 | ## 事件 @@ -68,30 +68,57 @@ PanGestureOptions(options?: { fingers?: number, direction?: PanDirection, distan @Entry @Component struct PanGestureExample { - @State offsetX: number = 0 - @State offsetY: number = 0 + @State offsetX: number = 0; + @State offsetY: number = 0; + @State positionX: number = 0; + @State positionY: number = 0; + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Left | PanDirection.Right }); build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('PanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) - } - .height(100).width(200).padding(20).border({ width: 1 }).margin(80) - .translate({ x: this.offsetX, y: this.offsetY, z: 5 }) - .gesture( - PanGesture({}) + Column() { + Column() { + Text('PanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) + } + .height(200) + .width(300) + .padding(20) + .border({ width: 3 }) + .margin(50) + .translate({ x: this.offsetX, y: this.offsetY, z: 0 }) + // 左右拖动触发该手势事件 + .gesture( + PanGesture(this.panOption) .onActionStart((event: GestureEvent) => { - console.info('Pan start') + console.info('Pan start'); }) .onActionUpdate((event: GestureEvent) => { - this.offsetX = event.offsetX - this.offsetY = event.offsetY + this.offsetX = this.positionX + event.offsetX; + this.offsetY = this.positionY + event.offsetY; }) .onActionEnd(() => { - console.info('Pan end') + this.positionX = this.offsetX; + this.positionY = this.offsetY; + console.info('Pan end'); + }) + ) + + Button('修改PanGesture触发条件') + .onClick(() => { + // 将PanGesture手势事件触发条件改为双指以任意方向拖动 + this.panOption.setDirection(PanDirection.All); + this.panOption.setFingers(2); }) - ) + } } } ``` -![zh-cn_image_0000001174264374](figures/zh-cn_image_0000001174264374.gif) +示意图: + +向左拖动: + +![zh-cn_image_0000001174264374](figures/zh-cn_image_0000001174264374.png) + +点击按钮修改PanGesture触发条件,双指向左下方拖动: + + ![zh-cn_image1_0000001174264374](figures/zh-cn_image1_0000001174264374.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md index d9127d6d716188129a0beb4e1f88ed35dda82148..a901229e1cd9905336327cf8df0bbdcf326a5f7c 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-pinchgesture.md @@ -32,28 +32,42 @@ PinchGesture(value?: { fingers?: number, distance?: number }) @Entry @Component struct PinchGestureExample { - @State scaleValue: number = 1 + @State scaleValue: number = 1; + @State pinchValue: number = 1; + @State pinchX: number = 0; + @State pinchY: number = 0; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('PinchGesture scale:' + this.scale) - } - .height(100).width(200).padding(20).border({ width: 1 }).margin(80) - .scale({ x: this.scaleValue, y: this.scaleValue, z: this.scaleValue }) - .gesture( - PinchGesture() + Column() { + Column() { + Text('PinchGesture scale:\n' + this.scaleValue) + Text('PinchGesture center:\n(' + this.pinchX + ',' + this.pinchY + ')') + } + .height(200) + .width(300) + .padding(20) + .border({ width: 3 }) + .margin({ top: 100 }) + .scale({ x: this.scaleValue, y: this.scaleValue, z: 1 }) + // 三指捏合触发该手势事件 + .gesture( + PinchGesture({ fingers: 3 }) .onActionStart((event: GestureEvent) => { - console.info('Pinch start') + console.info('Pinch start'); }) .onActionUpdate((event: GestureEvent) => { - this.scaleValue = event.scale + this.scaleValue = this.pinchValue * event.scale; + this.pinchX = event.pinchCenterX; + this.pinchY = event.pinchCenterY; }) .onActionEnd(() => { - console.info('Pinch end') + this.pinchValue = this.scaleValue; + console.info('Pinch end'); }) - ) + ) + }.width('100%') } } ``` -![zh-cn_image_0000001174582848](figures/zh-cn_image_0000001174582848.gif) +![zh-cn_image_0000001174582848](figures/zh-cn_image_0000001174582848.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md index 2438f474128d9f66883484bb39bc6745367355d1..8c2e8326f92f31ffd44a76c2058ca675eb3923de 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-rotationgesture.md @@ -32,28 +32,37 @@ RotationGesture(value?: { fingers?: number, angle?: number }) @Entry @Component struct RotationGestureExample { - @State angle: number = 0 + @State angle: number = 0; + @State rotateValue: number = 0; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('RotationGesture angle:' + this.angle) - } - .height(100).width(200).padding(20).border({ width:1 }) - .margin(80).rotate({ x:1, y:2, z:3, angle: this.angle }) - .gesture( + Column() { + Column() { + Text('RotationGesture angle:' + this.angle) + } + .height(200) + .width(300) + .padding(20) + .border({ width: 3 }) + .margin(80) + .rotate({ angle: this.angle }) + // 双指旋转触发该手势事件 + .gesture( RotationGesture() .onActionStart((event: GestureEvent) => { - console.log('Rotation start') + console.info('Rotation start'); }) .onActionUpdate((event: GestureEvent) => { - this.angle = event.angle + this.angle = this.rotateValue + event.angle; }) .onActionEnd(() => { - console.log('Rotation end') + this.rotateValue = this.angle; + console.info('Rotation end'); }) - ) + ) + }.width('100%') } } ``` -![zh-cn_image_0000001174264372](figures/zh-cn_image_0000001174264372.gif) +![zh-cn_image_0000001174264372](figures/zh-cn_image_0000001174264372.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md index 9c7c53050b9077afa4df1898d2ae92abe281c430..6e80bd15f0f135cadbcde99bbdeafaf9fa8cd73a 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-swipegesture.md @@ -10,20 +10,20 @@ SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: num **参数:** - | 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 | - | -------- | -------- | -------- | -------- | -------- | - | fingers | number | 否 | 1 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。 | - | direction | SwipeDirection | 否 | SwipeDirection.All | 触发滑动手势的滑动方向。 | - | speed | number | 否 | 100 | 识别滑动的最小速度(默认为100vp/秒)。 | +| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| fingers | number | 否 | 1 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。 | +| direction | [SwipeDirection](#swipedirection枚举说明) | 否 | SwipeDirection.All | 触发滑动手势的滑动方向。 | +| speed | number | 否 | 100 | 识别滑动的最小速度(默认为100vp/秒)。 | ## SwipeDirection枚举说明 - | 名称 | 描述 | - | -------- | -------- | - | All | 所有方向。 | - | Horizontal | 水平方向。 | - | Vertical | 竖直方向。 | - | None | 任何方向均不可触发。 | +| 名称 | 描述 | +| -------- | -------- | +| All | 所有方向。 | +| Horizontal | 水平方向。 | +| Vertical | 竖直方向。 | +| None | 任何方向均不可触发。 | ## 事件 @@ -32,8 +32,6 @@ SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: num | -------- | -------- | | onAction(event:(event?: [GestureEvent](ts-gesture-settings.md)) => void) | 滑动手势识别成功回调。 | - -![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374661.png) ## 示例 ```ts @@ -41,27 +39,31 @@ SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: num @Entry @Component struct SwipeGestureExample { - @State rotateAngle : number = 0 - @State speed : number = 1 + @State rotateAngle: number = 0; + @State speed: number = 1; build() { Column() { - Text("SwipGesture speed : " + this.speed) - Text("SwipGesture angle : " + this.rotateAngle) - } - .position({x: 80, y: 200}) - .border({width:2}) - .width(260).height(260) - .rotate({x: 0, y: 0, z: 1, angle: this.rotateAngle}) - .gesture( - SwipeGesture({fingers: 1, direction: SwipeDirection.Vertical}) + Column() { + Text("SwipeGesture speed\n" + this.speed) + Text("SwipeGesture angle\n" + this.rotateAngle) + } + .border({ width: 3 }) + .width(300) + .height(200) + .margin(100) + .rotate({ angle: this.rotateAngle }) + // 单指竖直方向滑动时触发该事件 + .gesture( + SwipeGesture({ direction: SwipeDirection.Vertical }) .onAction((event: GestureEvent) => { - this.speed = event.speed - this.rotateAngle = event.angle - }) - ) + this.speed = event.speed; + this.rotateAngle = event.angle; + }) + ) + }.width('100%') } } ``` -![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374559.gif) +![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374559.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md index b21fd010632a8cb75f46d635d557c0f32e8abdc8..834012a1e94ae6c3c1d337e7cc2a5869b13c5702 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-basic-gestures-tapgesture.md @@ -29,20 +29,25 @@ TapGesture(value?: { count?: number, fingers?: number }) @Entry @Component struct TapGestureExample { - @State value: string = '' + @State value: string = ''; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Text('Click twice') + Column() { + // 单指双击文本触发手势事件 + Text('Click twice').fontSize(28) + .gesture( + TapGesture({ count: 2 }) + .onAction((event: GestureEvent) => { + this.value = JSON.stringify(event.fingerList[0]); + }) + ) Text(this.value) } - .height(200).width(300).padding(60).border({ width: 1 }).margin(30) - .gesture( - TapGesture({ count: 2 }) - .onAction(() => { - this.value = 'TapGesture onAction' - }) - ) + .height(200) + .width(300) + .padding(20) + .border({ width: 3 }) + .margin(30) } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md b/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md index 925922055cdb99cffba81d22763239222e36801b..21fae4b0b4ccbb6642685d9193cd676aee6737d1 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-canvasrenderingcontext2d.md @@ -773,7 +773,7 @@ clearRect(x: number, y: number, w: number, h: number): void Canvas(this.context) .width('100%') .height('100%') - .backgroundColor('#ffff00') + .backgroundColor('#ffffff') .onReady(() =>{ this.context.fillStyle = 'rgb(0,0,255)' this.context.fillRect(0,0,500,500) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-combined-gestures.md b/zh-cn/application-dev/reference/arkui-ts/ts-combined-gestures.md index 391e14147694953eddcc178a7b91708a9d860670..dc5029f9e3ba5eea1a5b7c8c85d6c52fec32a218 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-combined-gestures.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-combined-gestures.md @@ -43,43 +43,67 @@ GestureGroup(mode: GestureMode, ...gesture: GestureType[]) @Entry @Component struct GestureGroupExample { - @State count: number = 0 - @State offsetX: number = 0 - @State offsetY: number = 0 - @State borderStyles: BorderStyle = BorderStyle.Solid + @State count: number = 0; + @State offsetX: number = 0; + @State offsetY: number = 0; + @State positionX: number = 0; + @State positionY: number = 0; + @State borderStyles: BorderStyle = BorderStyle.Solid; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { + Column() { Text('sequence gesture\n' + 'LongPress onAction:' + this.count + '\nPanGesture offset:\nX: ' + this.offsetX + '\n' + 'Y: ' + this.offsetY) - }.translate({ x: this.offsetX, y: this.offsetY, z: 5 }) - .height(100).width(200).padding(10).margin(80).border({ width: 1, style: this.borderStyles }) + } + .translate({ x: this.offsetX, y: this.offsetY, z: 0 }) + .height(150) + .width(200) + .padding(20) + .margin(20) + .border({ width: 3, style: this.borderStyles }) .gesture( - GestureGroup(GestureMode.Sequence, - LongPressGesture({ repeat: true }) - .onAction((event: GestureEvent) => { - if (event.repeat) {this.count++} - console.log('LongPress onAction') - }) - .onActionEnd(() => { - console.log('LongPress end') - }), - PanGesture({}) - .onActionStart(() => { - this.borderStyles = BorderStyle.Dashed - console.log('pan start') - }) - .onActionUpdate((event: GestureEvent) => { - this.offsetX = event.offsetX - this.offsetY = event.offsetY - console.log('pan update') - }) - ) + //以下组合手势为顺序识别,当长按手势事件未正常触发时则不会触发拖动手势事件 + GestureGroup(GestureMode.Sequence, + LongPressGesture({ repeat: true }) + .onAction((event: GestureEvent) => { + if (event.repeat) { + this.count++; + } + console.info('LongPress onAction'); + }) + .onActionEnd(() => { + console.info('LongPress end'); + }), + PanGesture() + .onActionStart(() => { + this.borderStyles = BorderStyle.Dashed; + console.info('pan start'); + }) + .onActionUpdate((event: GestureEvent) => { + this.offsetX = this.positionX + event.offsetX; + this.offsetY = this.positionY + event.offsetY; + console.info('pan update'); + }) + .onActionEnd(() => { + this.positionX = this.offsetX; + this.positionY = this.offsetY; + this.borderStyles = BorderStyle.Solid; + console.info('pan end'); + }) + ) .onCancel(() => { - console.log('sequence gesture canceled') + console.info('sequence gesture canceled'); }) ) } } ``` -![zh-cn_image_0000001174104384](figures/zh-cn_image_0000001174104384.gif) +示意图: + +按顺序首先触发长按事件: + +![zh-cn_image_0000001174104384](figures/zh-cn_image_0000001174104384.png) + +按顺序首先触发长按事件,长按事件识别结束之后,其次触发拖动事件,向右下方拖动: + + ![zh-cn_image1_0000001174104384](figures/zh-cn_image1_0000001174104384.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-badge.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-badge.md index cb779332a2b342efe59ce460d9f61601fba990e2..6db7e8dbfb219c2538725ccb8fd908f902ccc5b0 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-badge.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-badge.md @@ -1,16 +1,9 @@ # Badge -> **说明:** -> -> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -新事件标记组件,在组件上提供事件信息展示能力。 +可以附加在单个组件上用于信息标记的容器组件。 - -## 权限列表 - -无 +> **说明:** +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 子组件 @@ -20,47 +13,45 @@ ## 接口 -方法1:Badge(value: {count: number, position?: BadgePosition, maxCount?: number, style: BadgeStyle}) +**方法1:** Badge(value: {count: number, position?: BadgePosition, maxCount?: number, style: BadgeStyle}) 创建数字标记组件。 **参数:** +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| count | number | 是 | - | 设置提醒消息数。 | +| position | [BadgePosition](#badgeposition枚举说明) | 否 | BadgePosition.RightTop | 设置提示点显示位置。 | +| maxCount | number | 否 | 99 | 最大消息数,超过最大消息时仅显示maxCount+。 | +| style | [BadgeStyle](#badgestyle对象说明) | 是 | - | Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。 | -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| -------- | ------------- | ---- | ---------------------- | --------------------------------- | -| count | number | 是 | - | 设置提醒消息数。 | -| position | BadgePosition | 否 | BadgePosition.RightTop | 设置提示点显示位置。 | -| maxCount | number | 否 | 99 | 最大消息数,超过最大消息时仅显示maxCount+。 | -| style | BadgeStyle | 是 | - | Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。 | - -方法2: Badge(value: {value: string, position?: BadgePosition, style: BadgeStyle}) +**方法2:** Badge(value: {value: string, position?: BadgePosition, style: BadgeStyle}) 根据字符串创建标记组件。 **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| -------- | ------------- | ---- | ---------------------- | --------------------------------- | -| value | string | 是 | - | 提示内容的文本字符串。 | -| position | BadgePosition | 否 | BadgePosition.RightTop | 设置提示点显示位置。 | -| style | BadgeStyle | 是 | - | Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。 | - -## BadgeStyle对象说明 - -| 名称 | 类型 | 必填 | 默认值 | 描述 | -| ---------- | ------------------------------------------- | ---- | ----------- | ------------- | -| color | [ResourceColor](ts-types.md#resourcecolor8) | 否 | Color.White | 文本颜色。 | -| fontSize | number \| string | 否 | 10 | 文本大小。 | -| badgeSize | number \| string | 否 | - | badge的大小。 | -| badgeColor | [ResourceColor](ts-types.md#resourcecolor8) | 否 | Color.Red | badge的颜色。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| value | string | 是 | - | 提示内容的文本字符串。 | +| position | [BadgePosition](#badgeposition枚举说明) | 否 | BadgePosition.RightTop | 设置提示点显示位置。 | +| style | [BadgeStyle](#badgestyle对象说明) | 是 | - | Badge组件可设置样式,支持设置文本颜色、尺寸、圆点颜色和尺寸。 | ## BadgePosition枚举说明 -| 名称 | 描述 | -| -------- | ------------ | -| RightTop | 圆点显示在右上角。 | -| Right | 圆点显示在右侧纵向居中。 | -| Left | 圆点显示在左侧纵向居中。 | +| 名称 | 描述 | +| -------- | -------- | +| RightTop | 圆点显示在右上角。 | +| Right | 圆点显示在右侧纵向居中。 | +| Left | 圆点显示在左侧纵向居中。 | + +## BadgeStyle对象说明 +| 名称 | 类型 | 必填 | 默认值 | 描述 | + | -------- | -------- | -------- | -------- | -------- | +| color | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.White | 文本颜色。 | +| fontSize | number \| string | 否 | 10 | 文本大小。 | +| badgeSize | number \| string | 是 | - | badge的大小。 | +| badgeColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | Color.Red | badge的颜色。 | ## 示例 @@ -69,44 +60,92 @@ @Entry @Component struct BadgeExample { - @State counts: number = 1 - @State message: string = 'new' + @State counts: number = 1; + @State message: string = 'new'; build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - Badge({ - count: this.counts, - maxCount: 99, - style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red } - }) { - Button('message') - .onClick(() => { - this.counts++ - }) - .width(100).height(50).backgroundColor(0x317aff) - }.width(100).height(50) - - Badge({ - value: this.message, - style: { color: 0xFFFFFF, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue } - }) { - Text('message') - .width(80).height(50).fontSize(16).lineHeight(37) - .borderRadius(10).textAlign(TextAlign.Center).backgroundColor(0xF3F4ED) - }.width(80).height(50) - - Badge({ - value: '', - position: BadgePosition.Right, - style: { badgeSize: 6, badgeColor: Color.Red } - }) { - Text('message') - .width(90).height(50).fontSize(16).lineHeight(37) - .borderRadius(10).textAlign(TextAlign.Center).backgroundColor(0xF3F4ED) - }.width(90).height(50) - }.width('100%').margin({ top: 5 }) + Column() { + Text('numberBadge').width('80%') + Row({ space: 10 }) { + // 数字上标,maxCount默认99,超过99展示99+ + Badge({ + count: this.counts, + maxCount: 99, + position: BadgePosition.RightTop, + style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red } + }) { + Button('message') + .onClick(() => { + this.counts++; + }) + .width(100).height(50).backgroundColor(0x317aff) + }.width(100).height(50) + + // 数字上标 + Badge({ + count: this.counts, + maxCount: 99, + position: BadgePosition.Left, + style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red } + }) { + Button('message') + .onClick(() => { + this.counts++; + }) + .width(100).height(50).backgroundColor(0x317aff) + }.width(100).height(50) + + + // 数字上标 + Badge({ + count: this.counts, + maxCount: 99, + position: BadgePosition.Right, + style: { color: 0xFFFFFF, fontSize: 16, badgeSize: 20, badgeColor: Color.Red } + }) { + Button('message') + .onClick(() => { + this.counts++; + }) + .width(100).height(50).backgroundColor(0x317aff) + }.width(100).height(50) + }.margin(10) + + Text('stringBadge').width('80%') + Row({ space: 30 }) { + Badge({ + value: this.message, + style: { color: 0xFFFFFF, fontSize: 9, badgeSize: 20, badgeColor: Color.Blue } + }) { + Text('message') + .width(80) + .height(50) + .fontSize(16) + .lineHeight(37) + .borderRadius(10) + .textAlign(TextAlign.Center) + .backgroundColor(0xF3F4ED) + }.width(80).height(50) + + // value为空,设置圆点标记 + Badge({ + value: '', + position: BadgePosition.Right, + style: { badgeSize: 6, badgeColor: Color.Red } + }) { + Text('message') + .width(90) + .height(50) + .fontSize(16) + .lineHeight(37) + .borderRadius(10) + .textAlign(TextAlign.Center) + .backgroundColor(0xF3F4ED) + }.width(90).height(50) + }.margin(10) + } } } ``` -![zh-cn_image_0000001219864147](figures/zh-cn_image_0000001219864147.gif) +![badge](figures/badge.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-column.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-column.md index 63a7bb01652e2ca66c6d26e23fa044b206a258d8..6b34c3cee54a5b1d6094505abe506a6b9e2bc00b 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-column.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-column.md @@ -7,11 +7,6 @@ > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 子组件 可以包含子组件。 @@ -19,21 +14,22 @@ ## 接口 -Column(value?:{space?: string | number}) +Column(value?: {space?: string | number}) **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ----- | -------------- | ---- | ---- | --------- | -| space | string\|number | 否 | 0 | 纵向布局元素间距。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| space | string \| number | 否 | 纵向布局元素垂直方向间距。
默认值:0 | ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| --------------------------- | ---------------------------------------- | ---------------------- | ----------------- | -| alignItems | [HorizontalAlign](ts-appendix-enums.md#horizontalalign) | HorizontalAlign.Center | 设置子组件在水平方向上的对齐格式。 | -| justifyContent8+ | [FlexAlign](ts-appendix-enums.md#flexalign) | FlexAlign.Start | 设置子组件在垂直方向上的对齐格式。 | +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| alignItems | [HorizontalAlign](ts-appendix-enums.md#horizontalalign) | 设置子组件在水平方向上的对齐格式。
默认值:HorizontalAlign.Center | +| justifyContent8+ | [FlexAlign](ts-container-flex.md) | 设置子组件在垂直方向上的对齐格式。
默认值:FlexAlign.Start | ## 示例 @@ -44,38 +40,47 @@ Column(value?:{space?: string | number}) struct ColumnExample { build() { Column() { - Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column({ space: 5 }) { - Column().width('100%').height(30).backgroundColor(0xAFEEEE) - Column().width('100%').height(30).backgroundColor(0x00FFFF) - }.width('90%').height(100).border({ width: 1 }) - - Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('50%').height(30).backgroundColor(0xAFEEEE) - Column().width('50%').height(30).backgroundColor(0x00FFFF) - }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 }) - - Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('50%').height(30).backgroundColor(0xAFEEEE) - Column().width('50%').height(30).backgroundColor(0x00FFFF) - }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 }) - - Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('30%').height(30).backgroundColor(0xAFEEEE) - Column().width('30%').height(30).backgroundColor(0x00FFFF) - }.height('15%').border({ width: 1 }).justifyContent(FlexAlign.Center) - - Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Column() { - Column().width('30%').height(30).backgroundColor(0xAFEEEE) - Column().width('30%').height(30).backgroundColor(0x00FFFF) - }.height('15%').border({ width: 1 }).justifyContent(FlexAlign.End) + // 设置子元素垂直方向间距为5 + Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column({ space: 5 }) { + Column().width('100%').height(30).backgroundColor(0xAFEEEE) + Column().width('100%').height(30).backgroundColor(0x00FFFF) + }.width('90%').height(100).border({ width: 1 }) + + // 设置子元素水平方向对齐方式 + Text('alignItems(Start)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column() { + Column().width('50%').height(30).backgroundColor(0xAFEEEE) + Column().width('50%').height(30).backgroundColor(0x00FFFF) + }.alignItems(HorizontalAlign.Start).width('90%').border({ width: 1 }) + + Text('alignItems(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column() { + Column().width('50%').height(30).backgroundColor(0xAFEEEE) + Column().width('50%').height(30).backgroundColor(0x00FFFF) + }.alignItems(HorizontalAlign.End).width('90%').border({ width: 1 }) + + Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column() { + Column().width('50%').height(30).backgroundColor(0xAFEEEE) + Column().width('50%').height(30).backgroundColor(0x00FFFF) + }.alignItems(HorizontalAlign.Center).width('90%').border({ width: 1 }) + + // 设置子元素垂直方向的对齐方式 + Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column() { + Column().width('90%').height(30).backgroundColor(0xAFEEEE) + Column().width('90%').height(30).backgroundColor(0x00FFFF) + }.height(100).border({ width: 1 }).justifyContent(FlexAlign.Center) + + Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Column() { + Column().width('90%').height(30).backgroundColor(0xAFEEEE) + Column().width('90%').height(30).backgroundColor(0x00FFFF) + }.height(100).border({ width: 1 }).justifyContent(FlexAlign.End) }.width('100%').padding({ top: 5 }) } } ``` -![zh-cn_image_0000001219982721](figures/Column.png) +![column](figures/column.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-columnsplit.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-columnsplit.md index 22351db03f2ec17d82abc55efc5326868acad0fd..dd96432e8b7f5368ad47c9fc9b1823a362a2b75c 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-columnsplit.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-columnsplit.md @@ -3,13 +3,8 @@ 将子组件纵向布局,并在每个子组件之间插入一根横向的分割线。 > **说明:** -> -> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -## 权限列表 +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -无 ## 子组件 @@ -24,13 +19,14 @@ ColumnSplit() ## 属性 -| 名称 | 参数类型 | 描述 | -| ---------- | ------- | ------------------ | -| resizeable | boolean | 分割线是否可拖拽,默认为false。 | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| resizeable | boolean | 分割线是否可拖拽,默认为false。 | > **说明:** -> 与RowSplit相同,ColumnSplit的分割线最小能拖动到刚好包含子组件。 - +> 与RowSplit相同,ColumnSplit的分割线最小能拖动到刚好包含子组件。 +> +> 在真机中查看拖动效果,预览器中不支持拖动。 ## 示例 @@ -49,7 +45,7 @@ struct ColumnSplitExample { Text('4').width('100%').height(50).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) Text('5').width('100%').height(50).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) } - .resizeable(true) + .resizeable(true) // 可拖动 .width('90%').height('60%') }.width('100%') } diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-counter.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-counter.md index 4eb113fba9c3f3a8cc0ae37aad2cc63875c61aa9..27fbd173f704132eb302d27c2191d258761e8533 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-counter.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-counter.md @@ -1,16 +1,13 @@ # Counter -> **说明:** -> -> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +计数器组件,提供相应的增加或者减少的计数操作。 +> **说明:** +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -计数器组件,提供相应的增加或者减少的计数操作。 -## 权限列表 -无 ## 子组件 @@ -27,10 +24,10 @@ Counter() 不支持通用事件和手势, 仅支持如下事件: -| 名称 | 功能描述 | -| ---------------------------------------- | --------- | -| onInc(event: () => void) | 监听数值增加事件。 | -| onDec(event: () => void) | 监听数值减少事件。 | +| 名称 | 功能描述 | +| -------- | -------- | +| onInc(event: () => void) | 监听数值增加事件。 | +| onDec(event: () => void) | 监听数值减少事件。 | ## 示例 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-flex.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-flex.md index 569882254a2bc592117862a3d89884eb95d00ac7..15bc947bc3a963e017ecef5a85cbb78eecda1dc9 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-flex.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-flex.md @@ -243,7 +243,6 @@ struct FlexExample4 { ![zh-cn_image_0000001174422904](figures/zh-cn_image_0000001174422904.jpg) -![zh-cn_image_0000001219662653](figures/zh-cn_image_0000001219662653.gif) ``` // Example 05 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-navigator.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-navigator.md index 2ef3440f88da8494b85d8700cbebe6db816bf6a3..895184056c41747c9a5f970c89882c7cf4b7cc6e 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-navigator.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-navigator.md @@ -2,9 +2,9 @@ 路由容器组件,提供路由跳转能力。 -> **说明:** +> **说明:** > -> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 子组件 @@ -16,14 +16,12 @@ Navigator(value?: {target: string, type?: NavigationType}) -创建路由组件。 - **参数:** | 参数名 | 参数类型 | 必填 | 参数描述 | | ------ | -------------- | ---- | ---------------------------------------------- | -| target | string | 是 | 指定跳转目标页面的路径。 | -| type | NavigationType | 否 | 指定路由方式。
默认值:NavigationType.Push | +| target | string | 是 | 指定跳转目标页面的路径。 | +| type | [NavigationType](#navigationtype枚举说明) | 否 | 指定路由方式。
默认值:NavigationType.Push | ## NavigationType枚举说明 @@ -33,22 +31,25 @@ Navigator(value?: {target: string, type?: NavigationType}) | Replace | 用应用内的某个页面替换当前页面,并销毁被替换的页面。 | | Back | 返回上一页面或指定的页面。 | + ## 属性 | 名称 | 参数 | 描述 | | ------ | ------- | ------------------------------------------------------------ | | active | boolean | 当前路由组件是否处于激活状态,处于激活状态时,会生效相应的路由操作。 | -| params | object | 跳转时要同时传递到目标页面的数据,可在目标页面使用router.getParams()获得。 | +| params | object | 跳转时要同时传递到目标页面的数据,可在目标页面使用[router.getParams()](../apis/js-api-router.md#routergetparams)获得。 | +| target | string | 设置跳转目标页面的路径。 目标页面需加入main_pages.json文件中。 | +| type | [NavigationType](#navigationtype枚举说明) | 设置路由方式。
默认值:NavigationType.Push | ## 示例 -``` -// Navigator Page +```ts +// Navigator.ets @Entry @Component struct NavigatorExample { - @State active: boolean = false + @State active: boolean = false; @State Text: object = {name: 'news'} build() { @@ -56,27 +57,28 @@ struct NavigatorExample { Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) { Text('Go to ' + this.Text['name'] + ' page') .width('100%').textAlign(TextAlign.Center) - }.params({ text: this.Text }) + }.params({ text: this.Text }) // 传参数到Detail页面 Navigator() { Text('Back to previous page').width('100%').textAlign(TextAlign.Center) }.active(this.active) .onClick(() => { - this.active = true + this.active = true; }) }.height(150).width(350).padding(35) } } ``` -``` -// Detail Page -import router from '@system.router' +```ts +// Detail.ets +import router from '@ohos.router' @Entry @Component struct DetailExample { - @State text: any = router.getParams().text + // 接收Navigator.ets的传参 + @State text: any = router.getParams().text; build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { @@ -93,8 +95,8 @@ struct DetailExample { ``` -``` -// Back Page +```ts +// Back.ets @Entry @Component struct BackExample { diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-panel.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-panel.md index 13988b9e9727ccd2c19f4f8e5bbb94f1a7a63baa..2ab08be9ae38dac6a899cf62474e4d54cdb39650 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-panel.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-panel.md @@ -1,6 +1,6 @@ # Panel -可滑动面板。提供一种轻量的内容展示的窗口,可方便的在不同尺寸中切换,属于弹出式组件。 +可滑动面板,提供一种轻量的内容展示窗口,方便在不同尺寸中切换。 > **说明:** > @@ -18,43 +18,46 @@ Panel(show: boolean) **参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| ------ | -------- | ---- | --------------------- | -| show | boolean | 是 | 控制Panel显示或隐藏。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| show | boolean | 是 | 控制Panel显示或隐藏。 | + ## 属性 -| 名称 | 参数类型 | 描述 | -| ---------- | -------------- | ------------------------------------------------------------ | -| type | PanelType | 设置可滑动面板的类型。
默认值:PanelType.Foldable | -| mode | PanelMode | 设置可滑动面板的初始状态。 | -| dragBar | boolean | 设置是否存在dragbar,true表示存在,false表示不存在。
默认值:true | -| fullHeight | number\|string | 指定PanelMode.Full状态下的高度。 | -| halfHeight | number\|string | 指定PanelMode.Half状态下的高度,默认为屏幕尺寸的一半。 | -| miniHeight | number\|string | 指定PanelMode.Mini状态下的高度。 | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| type | [PanelType](#paneltype枚举说明) | 设置可滑动面板的类型。
默认值:PanelType.Foldable | +| mode | [PanelMode](#panelmode枚举说明) | 设置可滑动面板的初始状态。 | +| dragBar | boolean | 设置是否存在dragbar,true表示存在,false表示不存在。
默认值:true | +| fullHeight | string \| number | 指定PanelMode.Full状态下的高度。 | +| halfHeight | string \| number | 指定PanelMode.Half状态下的高度,默认为屏幕尺寸的一半。 | +| miniHeight | string \| number | 指定PanelMode.Mini状态下的高度。 | +| show | boolean | 当滑动面板弹出时调用。 | ## PanelType枚举说明 -| 名称 | 描述 | -| --------- | ------------------------------------ | -| Minibar | 提供minibar和类全屏展示切换效果。 | -| Foldable | 内容永久展示类,提供大(类全屏)、中(类半屏)、小三种尺寸展示切换效果。 | -| Temporary | 内容临时展示区,提供大(类全屏)、中(类半屏)两种尺寸展示切换效果。 | +| 名称 | 描述 | +| -------- | -------- | +| Minibar | 提供minibar和类全屏展示切换效果。 | +| Foldable | 内容永久展示类,提供大(类全屏)、中(类半屏)、小三种尺寸展示切换效果。 | +| Temporary | 内容临时展示区,提供大(类全屏)、中(类半屏)两种尺寸展示切换效果。 | ## PanelMode枚举说明 -| 名称 | 描述 | -| ---- | ---------------------------------------- | +| 名称 | 描述 | +| -------- | -------- | | Mini | 类型为minibar和foldable时,为最小状态;类型为temporary,则不生效。 | | Half | 类型为foldable和temporary时,为类半屏状态;类型为minibar,则不生效。 | -| Full | 类全屏状态。 | +| Full | 类全屏状态。 | + ## 事件 -| 名称 | 功能描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | +| 名称 | 功能描述 | +| -------- | -------- | | onChange(event: (width: number, height: number, mode: PanelMode) => void) | 当可滑动面板发生状态变化时触发, 返回的height值为内容区高度值,当dragbar属性为true时,panel本身的高度值为dragbar高度加上内容区高度。 | - +| onHeightChange(callback: (value: number) => void)9+ |当可滑动面板发生高度变化时触发,返回的height值为内容区高度值,当dragbar属性为true时,panel本身的高度值为dragbar高度加上内容区高度。因用户体验设计原因,panel最高只能滑到 fullHeight-8vp。 | ## 示例 @@ -66,7 +69,7 @@ struct PanelExample { @State show: boolean = false build() { - Column() { + Stack() { Text('2021-09-30 Today Calendar: 1.afternoon......Click for details') .width('90%').height(50).borderRadius(10) .backgroundColor(0xFFFFFF).padding({ left: 20 }) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-refresh.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-refresh.md index c6abd718b6ac60b948c47320bf58849d9a255476..d03a2a041999f38c12d8dad5d2cd1f70e8656a7d 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-refresh.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-refresh.md @@ -1,49 +1,47 @@ # Refresh -下拉刷新容器。 + 可以进行页面下拉操作并显示刷新动效的容器组件。 > **说明:** > > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - ## 子组件 支持单个子组件。 ## 接口 -Refresh\(value: \{refreshing: boolean, offset?: number | string, friction?: number | string\}\) +Refresh\(value: \{ refreshing: boolean, offset?: number | string , friction?: number | string \}\) **参数:** -| 参数 | 参数名 | 必填 | 默认值 | 参数描述 | -| ---------- | -------------------------- | ---- | ---- | ---------------------------------------- | -| refreshing | boolean | 是 | - | 当前组件是否正在刷新。 | -| offset | Length | 否 | 16 | 刷新组件静止时距离父组件顶部的距离。 | -| friction | number \| string | 否 | 62 | 下拉摩擦系数,取值范围为0到100。
- 0表示下拉刷新容器不跟随手势下拉而下拉。
- 100表示下拉刷新容器紧紧跟随手势下拉而下拉。
- 数值越大,下拉刷新容器跟随手势下拉的反应越灵敏。 | +| 参数 | 参数名 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| refreshing | boolean | 是 | 当前组件是否正在刷新。
该参数支持[$$](../../ui/ts-syntactic-sugar.md)双向绑定变量。 | +| offset | string \| number | 否 | 刷新组件静止时距离父组件顶部的距离。
默认值:16,单位vp | +| friction | number \| string | 否 | 下拉摩擦系数,取值范围为0到100。
默认值:62
- 0表示下拉刷新容器不跟随手势下拉而下拉。
- 100表示下拉刷新容器紧紧跟随手势下拉而下拉。
- 数值越大,下拉刷新容器跟随手势下拉的反应越灵敏。 | + ## 事件 -| 名称 | 描述 | -| ---------------------------------------- | ------------------------------- | -| onStateChange(callback: (state: RefreshStatus) => void) | 当前刷新状态变更时,触发回调。
state:刷新状态。 | -| onRefreshing(callback: () => void) | 进入刷新状态时触发回调。 | +| 名称 | 描述 | +| -------- | -------- | +| onStateChange(callback: (state: [RefreshStatus](#refreshstatus枚举说明)) => void)| 当前刷新状态变更时,触发回调。
- state:刷新状态。 | +| onRefreshing(callback: () => void)| 进入刷新状态时触发回调。 | ## RefreshStatus枚举说明 -| 名称 | 描述 | -| -------- | -------------------- | -| Inactive | 默认未下拉状态。 | -| Drag | 下拉中,下拉距离小于刷新距离。 | -| OverDrag | 下拉中,下拉距离超过刷新距离。 | -| Refresh | 下拉结束,回弹至刷新距离,进入刷新状态。 | -| Done | 刷新结束,返回初始状态(顶部)。 | +| 名称 | 描述 | +| -------- | -------- | +| Inactive | 默认未下拉状态。 | +| Drag | 下拉中,下拉距离小于刷新距离。 | +| OverDrag | 下拉中,下拉距离超过刷新距离。 | +| Refresh | 下拉结束,回弹至刷新距离,进入刷新状态。 | +| Done | 刷新结束,返回初始状态(顶部)。 | + ## 示例 @@ -57,7 +55,7 @@ struct RefreshExample { build() { Column() { - Refresh({refreshing: this.isRefreshing, offset: 120, friction: 100}) { + Refresh({ refreshing: $$this.isRefreshing, offset: 120, friction: 100 }) { Text('Pull Down and refresh: ' + this.counter) .fontSize(30) .margin(10) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-row.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-row.md index de86851e93ce7a5151f28aeebd706788c6af0442..ba536c338ffb88ce73f1a0619d722f8b1c2743c0 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-row.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-row.md @@ -7,11 +7,6 @@ > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 子组件 可以包含子组件。 @@ -19,20 +14,22 @@ ## 接口 -Row(value?:{space?: string | number}) +Row(value?:{space?: number | string }) **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ------ | -------------------------- | ---- | ------ | ------------------ | -| space | string \| number | 否 | 0 | 横向布局元素间距。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| -------- | -------- | -------- | -------- | +| space | string \| number | 否 | 横向布局元素间距。
默认值:0,单位vp | + ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ---------------- | --------------------------------- | -------------------- | ----------------- | -| alignItems | [VerticalAlign](ts-appendix-enums.md#verticalalign) | VerticalAlign.Center | 在垂直方向上子组件的对齐格式。 | -| justifyContent8+ | [FlexAlign](ts-appendix-enums.md#flexalign) | FlexAlign.Start | 设置子组件在水平方向上的对齐格式。 | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| alignItems | [VerticalAlign](ts-appendix-enums.md#verticalalign) | 设置子组件在垂直方向上的对齐格式。
默认值:VerticalAlign.Center | +| justifyContent8+ | [FlexAlign](ts-appendix-enums.md#flexalign) | 设置子组件在水平方向上的对齐格式。
FlexAlign.Start | + ## 示例 @@ -43,38 +40,41 @@ Row(value?:{space?: string | number}) struct RowExample { build() { Column({ space: 5 }) { + // 设置子组件水平方向的间距为5 Text('space').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row({ space: 5 }) { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.width('90%').height(107).border({ width: 1 }) - - Text('alignItems(Top)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.alignItems(VerticalAlign.Top).height('15%').border({ width: 1 }) - - Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.alignItems(VerticalAlign.Center).height('15%').border({ width: 1 }) - - Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.End) - - Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') - Row() { - Row().width('30%').height(50).backgroundColor(0xAFEEEE) - Row().width('30%').height(50).backgroundColor(0x00FFFF) - }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.Center) + Row({ space: 5 }) { + Row().width('30%').height(50).backgroundColor(0xAFEEEE) + Row().width('30%').height(50).backgroundColor(0x00FFFF) + }.width('90%').height(107).border({ width: 1 }) + + // 设置子元素垂直方向对齐方式 + Text('alignItems(Bottom)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Row() { + Row().width('30%').height(50).backgroundColor(0xAFEEEE) + Row().width('30%').height(50).backgroundColor(0x00FFFF) + }.width('90%').alignItems(VerticalAlign.Bottom).height('15%').border({ width: 1 }) + + Text('alignItems(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Row() { + Row().width('30%').height(50).backgroundColor(0xAFEEEE) + Row().width('30%').height(50).backgroundColor(0x00FFFF) + }.width('90%').alignItems(VerticalAlign.Center).height('15%').border({ width: 1 }) + + // 设置子元素水平方向对齐方式 + Text('justifyContent(End)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Row() { + Row().width('30%').height(50).backgroundColor(0xAFEEEE) + Row().width('30%').height(50).backgroundColor(0x00FFFF) + }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.End) + + Text('justifyContent(Center)').fontSize(9).fontColor(0xCCCCCC).width('90%') + Row() { + Row().width('30%').height(50).backgroundColor(0xAFEEEE) + Row().width('30%').height(50).backgroundColor(0x00FFFF) + }.width('90%').border({ width: 1 }).justifyContent(FlexAlign.Center) }.width('100%') } } ``` -![zh-cn_image_0000001174422908](figures/Row.png) +![row](figures/row.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-rowsplit.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-rowsplit.md index de31180e75a5cdfe34c2f45b50d3832fc2c1cc69..ae460606c107c01221789228b458b7160e66d93a 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-rowsplit.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-rowsplit.md @@ -1,15 +1,11 @@ # RowSplit -将子组件横向布局,并在每个子组件之间插入一根纵向的分割线。 - > **说明:** -> -> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 +将子组件横向布局,并在每个子组件之间插入一根纵向的分割线。 -无 ## 子组件 @@ -24,12 +20,14 @@ RowSplit() ## 属性 -| 名称 | 参数类型 | 描述 | -| ---------- | ------- | ------------------ | -| resizeable | boolean | 分割线是否可拖拽,默认为false。 | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| resizeable | boolean | 分割线是否可拖拽,默认为false。 | > **说明:** -> RowSplit的分割线最小能拖动到刚好包含子组件。 +> RowSplit的分割线最小能拖动到刚好包含子组件。 +> +> 在真机中查看拖动效果,预览器中不支持拖动。 ## 示例 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-container-scroll.md b/zh-cn/application-dev/reference/arkui-ts/ts-container-scroll.md index cab4ac8ce512aa5b504c76c8a7002d7a631abee7..e0a02896e93d84a2134a740731beae086e0f71d3 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-container-scroll.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-container-scroll.md @@ -1,11 +1,12 @@ # Scroll -可滑动的容器组件,当子组件的布局尺寸超过父组件的视口时,内容可以滑动。 +可滚动的容器组件,当子组件的布局尺寸超过父组件的尺寸时,内容可以滚动。 > **说明:** -> > - 该组件从API version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -> - 该组件回弹的前提是要有滑动。内容小于一屏时,没有回弹效果。 +> - 该组件嵌套List子组件滚动时,若List不设置宽高,则默认全部加载,在对性能有要求的场景下建议指定List的宽高。 +> - 该组件滚动的前提是主轴方向大小小于内容大小。 +> - 该组件回弹的前提是要有滚动。内容小于一屏时,没有回弹效果。 ## 子组件 @@ -17,37 +18,42 @@ Scroll(scroller?: Scroller) - ## 属性 -| 名称 | 参数类型 | 描述 | -| -------------- | ---------------------------------------- | ---------------------------------------- | -| scrollable | ScrollDirection | 设置滑动方法。
默认值:ScrollDirection.Vertical | -| scrollBar | [BarState](ts-appendix-enums.md#barstate) | 设置滑动条状态。
默认值:BarState.Off | -| scrollBarColor | string \| number \| Color | 设置滑动条的颜色。 | -| scrollBarWidth | string \| number | 设置滑动条的宽度。 | -| edgeEffect | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | 设置滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。
默认值:EdgeEffect.Spring | +除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -## ScrollDirection枚举说明 +| 名称 | 参数类型 | 描述 | +| -------------- | ---------------------------------------- | --------- | +| scrollable | [ScrollDirection](#scrolldirection枚举说明) | 设置滚动方向。
默认值:ScrollDirection.Vertical | +| scrollBar | [BarState](ts-appendix-enums.md#barstate) | 设置滚动条状态。
默认值:BarState.Off | +| scrollBarColor | string \| number \| [Color](ts-appendix-enums.md#color) | 设置滚动条的颜色。 | +| scrollBarWidth | string \| number | 设置滚动条的宽度。 | +| edgeEffect | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | 设置滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。
默认值:EdgeEffect.None | -| 名称 | 描述 | -| ---------- | ------------ | -| Horizontal | 仅支持水平方向滚动。 | -| Vertical | 仅支持竖直方向滚动。 | -| None | 不可滚动。 | -| Free | 支持竖直或水平方向滚动。 | +## ScrollDirection枚举说明 +| 名称 | 描述 | +| ---------- | ------------------------ | +| Horizontal | 仅支持水平方向滚动。 | +| Vertical | 仅支持竖直方向滚动。 | +| None | 不可滚动。 | +| Free(deprecated) | 支持竖直或水平方向滚动
从API version 9开始废弃| ## 事件 -| 名称 | 功能描述 | -| ---------------------------------------- | ----------------------------- | -| onScroll(event: (xOffset: number, yOffset: number) => void) | 滚动事件回调, 返回滚动时水平、竖直方向偏移量。 | -| onScrollEdge(event: (side: Edge) => void) | 滚动到边缘事件回调。 | -| onScrollEnd(event: () => void) | 滚动停止事件回调。 | +| 名称 | 功能描述 | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| onScrollBegin9+(event: (dx: number, dy: number) => { dxRemain: number, dyRemain: number }) | 滚动开始事件回调。
参数:
- dx:即将发生的水平方向滚动量。
- dy:即将发生的竖直方向滚动量。
返回值:
- dxRemain:水平方向滚动剩余量。
- dyRemain:竖直方向滚动剩余量。 | +| onScroll(event: (xOffset: number, yOffset: number) => void) | 滚动事件回调, 返回滚动时水平、竖直方向偏移量。 | +| onScrollEdge(event: (side: Edge) => void) | 滚动到边缘事件回调。 | +| onScrollEnd(event: () => void) | 滚动停止事件回调。 | + +> **说明:** +> +> 若通过onScrollBegin事件和scrollBy方法实现容器嵌套滚动,需设置子滚动节点的EdgeEffect为None。如Scroll嵌套List滚动时,List组件的edgeEffect属性需设置为EdgeEffect.None。 ## Scroller -可滑动容器组件的控制器,可以将此组件绑定至容器组件,然后通过它控制容器组件的滑动,目前支持绑定到List、Scroll、ScrollBar上。 +可滚动容器组件的控制器,可以将此组件绑定至容器组件,然后通过它控制容器组件的滚动,同一个控制器不可以控制多个容器组件,目前支持绑定到List、Scroll、ScrollBar上。 ### 导入对象 @@ -66,38 +72,54 @@ scrollTo(value: { xOffset: number | string, yOffset: number | string, animation? **参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| --------- | ---------------------------------------- | ---- | ---------------------------------------- | -| xOffset | number \| string | 是 | 水平滑动偏移。 | -| yOffset | number \| string | 是 | 竖直滑动偏移。 | -| animation | {
duration: number,
curve: [Curve](ts-appendix-enums.md#curve) 
} | 否 | 动画配置:
- duration: 滑动时长设置。
- curve: 滑动曲线设置。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| xOffset | Length | 是 | 水平滑动偏移。 | +| yOffset | Length | 是 | 竖直滑动偏移。 | +| animation | {
duration: number,
curve: [Curve](ts-animatorproperty.md)
} | 否 | 动画配置:
- duration: 滚动时长设置。
- curve: 滚动曲线设置。 | + ### scrollEdge -scrollEdge(value: [Edge](ts-appendix-enums.md#edge)): void +scrollEdge(value: Edge): void + + +滚动到容器边缘。 +**参数:** + +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ----- | ---- | ---- | --------- | +| value | [Edge](ts-appendix-enums.md#edge) | 是 | 滚动到的边缘位置。 | -滑动到容器边缘。 ### scrollPage scrollPage(value: { next: boolean, direction?: Axis }): void -滑动到下一页或者上一页。 +滚动到下一页或者上一页。 **参数:** -| 参数名 | 参数类型 | 必填 | 参数描述 | -| --------- | --------------------------------- | ---- | ------------------------------ | -| next | boolean | 是 | 是否向下翻页。true表示向下翻页,false表示向上翻页。 | -| direction | [Axis](ts-appendix-enums.md#axis) | 否 | 设置滑动方向为水平或竖直方向。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| --------- | ------- | ---- | ------------------------------ | +| next | boolean | 是 | 是否向下翻页。true表示向下翻页,false表示向上翻页。 | +| direction(deprecated) | [Axis](ts-appendix-enums.md#axis) | 否 | 设置滚动方向为水平或竖直方向。
从API version 9开始废弃 | + ### currentOffset currentOffset() -返回当前的滑动偏移量。 +返回当前的滚动偏移量。 + +**返回值** + +| 类型 | 描述 | +| ---------------------------------------- | ---------------------------------------- | +| {
xOffset: number,
yOffset: number
} | xOffset: 水平滑动偏移;
yOffset: 竖直滑动偏移。 | + ### scrollToIndex @@ -108,23 +130,46 @@ scrollToIndex(value: number): void > **说明:** +> > 仅支持list组件。 **参数:** +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ------ | -------- | ---- | ---------------------------------- | +| value | number | 是 | 要滑动到的列表项在列表中的索引值。 | + + +### scrollBy9+ + +scrollBy(dx: Length, dy: Length): void + + +滑动指定距离。 + + +> **说明:** +> +> 仅支持Scroll组件。 + +**参数:** + | 参数名 | 参数类型 | 必填 | 参数描述 | | ----- | ------ | ---- | ----------------- | -| value | number | 是 | 要滑动到的列表项在列表中的索引值。 | +| dx | Length | 是 | 水平方向滚动距离,不支持百分比形式。 | +| dy | Length | 是 | 竖直方向滚动距离,不支持百分比形式。 | + ## 示例 +### 示例1 ```ts // xxx.ets @Entry @Component struct ScrollExample { - scroller: Scroller = new Scroller() - private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] + scroller: Scroller = new Scroller(); + private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; build() { Stack({ alignContent: Alignment.TopStart }) { @@ -142,38 +187,99 @@ struct ScrollExample { }, item => item) }.width('100%') } - .scrollable(ScrollDirection.Vertical) - .scrollBar(BarState.On) - .scrollBarColor(Color.Gray) - .scrollBarWidth(30) + .scrollable(ScrollDirection.Vertical) // 滚动方向纵向 + .scrollBar(BarState.On) // 滚动条常驻显示 + .scrollBarColor(Color.Gray) // 滚动条颜色 + .scrollBarWidth(30) // 滚动条宽度 + .edgeEffect(EdgeEffect.None) .onScroll((xOffset: number, yOffset: number) => { - console.info(xOffset + ' ' + yOffset) + console.info(xOffset + ' ' + yOffset); }) .onScrollEdge((side: Edge) => { - console.info('To the edge') + console.info('To the edge'); }) .onScrollEnd(() => { - console.info('Scroll Stop') + console.info('Scroll Stop'); }) - Button('scroll 100') - .onClick(() => { // 点击后下滑100.0距离 - this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 }) + Button('scroll 150') + .onClick(() => { // 点击后下滑指定距离150.0vp + this.scroller.scrollBy(0,150); }) .margin({ top: 10, left: 20 }) + Button('scroll 100') + .onClick(() => { // 点击后滑动到指定位置,即下滑100.0vp的距离 + this.scroller.scrollTo({ xOffset: 0, yOffset: this.scroller.currentOffset().yOffset + 100 }); + }) + .margin({ top: 60, left: 20 }) Button('back top') .onClick(() => { // 点击后回到顶部 - this.scroller.scrollEdge(Edge.Top) + this.scroller.scrollEdge(Edge.Top); }) - .margin({ top: 60, left: 20 }) + .margin({ top: 110, left: 20 }) Button('next page') - .onClick(() => { // 点击后下滑到底部 - this.scroller.scrollPage({ next: true }) + .onClick(() => { // 点击后滑到下一页 + this.scroller.scrollPage({ next: true }); }) - .margin({ top: 110, left: 20 }) + .margin({ top: 170, left: 20 }) }.width('100%').height('100%').backgroundColor(0xDCDCDC) } } ``` ![zh-cn_image_0000001174104386](figures/zh-cn_image_0000001174104386.gif) + +### 示例2 +```ts +@Entry +@Component +struct NestedScroll { + @State listPosition: number = 0; // 0代表滚动到List顶部,1代表中间值,2代表滚动到List底部。 + private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + private scroller: Scroller = new Scroller(); + + build() { + Flex() { + Scroll(this.scroller) { + Column() { + Text("Scroll Area") + .width("100%").height("40%").backgroundColor(0X330000FF) + .fontSize(16).textAlign(TextAlign.Center) + + List({ space: 20 }) { + ForEach(this.arr, (item) => { + ListItem() { + Text("ListItem" + item) + .width("100%").height("100%").borderRadius(15) + .fontSize(16).textAlign(TextAlign.Center).backgroundColor(Color.White) + }.width("100%").height(100) + }, item => item) + } + .width("100%").height("50%").edgeEffect(EdgeEffect.None) + .onReachStart(() => { + this.listPosition = 0; + }) + .onReachEnd(() => { + this.listPosition = 2; + }) + .onScrollBegin((dx: number, dy: number) => { + if ((this.listPosition == 0 && dy >= 0) || (this.listPosition == 2 && dy <= 0)) { + this.scroller.scrollBy(0, -dy); + return { dxRemain: dx, dyRemain: 0 }; + } + this.listPosition = 1; + return { dxRemain: dx, dyRemain: dy }; + }) + + Text("Scroll Area") + .width("100%").height("40%").backgroundColor(0X330000FF) + .fontSize(16).textAlign(TextAlign.Center) + } + } + .width("100%").height("100%") + }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding(20) + } +} +``` + +![NestedScroll](figures/NestedScroll.gif) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md index c638706d9fae260e9485cab1b6d48e5d8e665d60..965f8428d3bee2aa6c2a17d0b273abf830a2ebae 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-circle.md @@ -22,10 +22,10 @@ Circle(options?: {width?: string | number, height?: string | number}) ## 参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | -------- | -------- | -------- | -------- | -------- | - | width | string \| number | 否 | 0 | 宽度。 | - | height | string \| number | 否 | 0 | 高度。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| width | string \| number | 否 | 0 | 宽度。 | +| height | string \| number | 否 | 0 | 高度。 | ## 属性 @@ -36,14 +36,14 @@ Circle(options?: {width?: string | number, height?: string | number}) | -------- | -------- | -------- | -------- | -------- | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置线条颜色。 | -| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | -| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | -| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | -| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置边框颜色,不设置时,默认没有边框。 | +| strokeDashArray | Array<Length> | [] | 否 | 设置边框间隙。 | +| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 | +| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置边框端点绘制样式。 | +| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置边框拐角绘制样式。 | | strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 | -| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 | -| strokeWidth | Length | 1 | 否 | 设置线条宽度。 | +| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置边框透明度。 | +| strokeWidth | Length | 1 | 否 | 设置边框宽度。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | @@ -55,12 +55,18 @@ Circle(options?: {width?: string | number, height?: string | number}) @Component struct CircleExample { build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { + Column({ space: 10 }) { // 绘制一个直径为150的圆 Circle({ width: 150, height: 150 }) - // 绘制一个直径为150的圆 - Circle().width(150).height(150) - }.width('100%').margin({ top: 5 }) + // 绘制一个直径为150、线条为红色虚线的圆环(宽高设置不一致时以短边为直径) + Circle() + .width(150) + .height(200) + .fillOpacity(0) + .strokeWidth(3) + .stroke(Color.Red) + .strokeDashArray([1, 2]) + }.width('100%') } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md index 2fc055cb80c7cdf41160d15bd6b6b1fe1298e0ed..56b90bf489c99064fadb06c8d0f0e6321d6920b6 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-ellipse.md @@ -23,10 +23,10 @@ ellipse(options?: {width?: string | number, height?: string | number}) - 参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | + | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | - | width | string \| number | 否 | 0 | 宽度。 | - | height | string \| number | 否 | 0 | 高度。 | + | width | string \| number | 否 | 0 | 宽度。 | + | height | string \| number | 否 | 0 | 高度。 | ## 属性 @@ -37,14 +37,14 @@ ellipse(options?: {width?: string | number, height?: string | number}) | -------- | -------- | -------- | -------- | -------- | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 |设置线条颜色。 | -| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | -| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | -| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | -| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 |设置边框颜色,不设置时,默认没有边框。 | +| strokeDashArray | Array<Length> | [] | 否 | 设置边框间隙。 | +| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 | +| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置边框端点绘制样式。 | +| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置边框拐角绘制样式。 | | strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 | -| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 | -| strokeWidth | Length | 1 | 否 | 设置线条宽度。 | +| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置边框透明度。 | +| strokeWidth | Length | 1 | 否 | 设置边框宽度。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | @@ -56,12 +56,17 @@ ellipse(options?: {width?: string | number, height?: string | number}) @Component struct EllipseExample { build() { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 在一个 150 * 80 的矩形框中绘制一个椭圆 + Column({ space: 10 }) { + // 绘制一个 150 * 80 的椭圆 Ellipse({ width: 150, height: 80 }) - // 在一个 150 * 70 的矩形框中绘制一个椭圆 - Ellipse().width(150).height(80) - }.width('100%').margin({ top: 5 }) + // 绘制一个 150 * 100 、线条为蓝色的椭圆环 + Ellipse() + .width(150) + .height(100) + .fillOpacity(0) + .stroke(Color.Blue) + .strokeWidth(3) + }.width('100%') } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md index 4ec9dcfc8792e81be58f0c7fec06501d607c7828..db34c973330b229bf153399f14343550bed4247b 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-line.md @@ -22,17 +22,17 @@ Line(options?: {width?: string | number, height?: string | number}) - 参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | + | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | - | width | string \| number | 否 | 0 | 宽度。 | - | height | string \| number | 否 | 0 | 高度。 | + | width | string \| number | 否 | 0 | 宽度。 | + | height | string \| number | 否 | 0 | 高度。 | ## 属性 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | +| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | | startPoint | Array | [0, 0] | 是 | 直线起点坐标点(相对坐标)。 | | endPoint | Array | [0, 0] | 是 | 直线终点坐标点(相对坐标)。 | @@ -48,21 +48,92 @@ Line(options?: {width?: string | number, height?: string | number}) | strokeWidth | Length | 1 | 否 | 设置线条宽度。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | - ## 示例 +### 示例1 + ```ts // xxx.ets @Entry @Component struct LineExample { build() { - Column() { - Line({ width: 50, height: 100 }).startPoint([0, 0]).endPoint([50, 100]) - Line().width(200).height(200).startPoint([50, 50]).endPoint([150, 150]) - }.margin({ top: 5 }) + Column({ space: 10 }) { + // 线条绘制的起止点坐标均是相对于Line组件本身绘制区域的坐标 + Line() + .startPoint([0, 0]) + .endPoint([50, 100]) + .backgroundColor('#F5F5F5') + Line() + .width(200) + .height(200) + .startPoint([50, 50]) + .endPoint([150, 150]) + .strokeWidth(5) + .stroke(Color.Orange) + .strokeOpacity(0.5) + .backgroundColor('#F5F5F5') + // 当坐标点设置的值超出Line组件的宽高范围时,线条会画出组件绘制区域 + Line({ width: 50, height: 50 }) + .startPoint([0, 0]) + .endPoint([100, 100]) + .strokeWidth(3) + .strokeDashArray([10, 3]) + .backgroundColor('#F5F5F5') + // strokeDashOffset用于定义关联虚线strokeDashArray数组渲染时的偏移 + Line({ width: 50, height: 50 }) + .startPoint([0, 0]) + .endPoint([100, 100]) + .strokeWidth(3) + .strokeDashArray([10, 3]) + .strokeDashOffset(5) + .backgroundColor('#F5F5F5') + } + } +} +``` + +![zh-cn_image_0000001219982725](figures/zh-cn_image_0000001219982725.png) + +### 示例2 + +```ts +// xxx.ets +@Entry +@Component +struct LineExample1 { + build() { + Row({ space: 10 }) { + // 当LineCapStyle值为Butt时 + Line() + .width(100) + .height(200) + .startPoint([50, 50]) + .endPoint([50, 200]) + .strokeWidth(20) + .strokeLineCap(LineCapStyle.Butt) + .backgroundColor('#F5F5F5').margin(10) + // 当LineCapStyle值为Round时 + Line() + .width(100) + .height(200) + .startPoint([50, 50]) + .endPoint([50, 200]) + .strokeWidth(20) + .strokeLineCap(LineCapStyle.Round) + .backgroundColor('#F5F5F5') + // 当LineCapStyle值为Square时 + Line() + .width(100) + .height(200) + .startPoint([50, 50]) + .endPoint([50, 200]) + .strokeWidth(20) + .strokeLineCap(LineCapStyle.Square) + .backgroundColor('#F5F5F5') + } } } ``` -![zh-cn_image_0000001219982725](figures/zh-cn_image_0000001219982725.jpg) +![zh-cn_image1_0000001219982725](figures/zh-cn_image1_0000001219982725.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md index ccc28784eadcd7dbb21c9f49701a19d04455bd95..ab5fc7f60781604ec3507079aaee86ae2bad8b47 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-path.md @@ -35,7 +35,7 @@ Path(value?: { width?: number | string; height?: number | string; commands?: str | commands | string | '' | 否 | 路径绘制的命令字符串,单位为px。像素单位转换方法请参考[像素单位转换](../../ui/ts-pixel-units.md)。 | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置线条颜色。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置线条颜色。 | | strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | | strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | | strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | @@ -72,28 +72,75 @@ commands支持的绘制命令如下: @Component struct PathExample { build() { - Column({ space: 5 }) { - Text('Straight line').fontSize(9).fontColor(0xCCCCCC).width('90%') - Path().width(300).height(10).commands('M0 0 L900 0').stroke(Color.Black).strokeWidth(3) - - Text('Straight line graph').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 先后执行MoveTo(150, 0), LineTo(300, 300), LineTo(0, 300), ClosePath() - Path().width(100).height(100).commands('M150 0 L300 300 L0 300 Z') - // 先后执行MoveTo(0, 0), HorizontalLineto(300), VerticalLineto(300), HorizontalLineto(0), ClosePath() - Path().width(100).height(100).commands('M0 0 H300 V300 H0 Z') - // 先后执行MoveTo(150, 0), LineTo(0, 150), LineTo(60, 300), LineTo(240, 300), LineTo(300, 150), ClosePath() - Path().width(100).height(100).commands('M150 0 L0 150 L60 300 L240 300 L300 150 Z') + Column({ space: 10 }) { + Text('Straight line') + .fontSize(11) + .fontColor(0xCCCCCC) + .width('90%') + // 绘制一条长900px,宽3vp的直线 + Path() + .width(300) + .height(10) + .commands('M0 0 L900 0') + .stroke(Color.Black) + .strokeWidth(3) + + Text('Straight line graph') + .fontSize(11) + .fontColor(0xCCCCCC) + .width('90%') + // 绘制直线图形 + Row({ space: 20 }) { + Path() + .width(100) + .height(100) + .commands('M150 0 L300 300 L0 300 Z') + .fillOpacity(0) + .stroke(Color.Black) + .strokeWidth(3) + Path() + .width(100) + .height(100) + .commands('M0 0 H300 V300 H0 Z') + .fillOpacity(0) + .stroke(Color.Black) + .strokeWidth(3) + Path() + .width(100) + .height(100) + .commands('M150 0 L0 150 L60 300 L240 300 L300 150 Z') + .fillOpacity(0) + .stroke(Color.Black) + .strokeWidth(3) }.width('100%') - Text('Curve graphics').fontSize(9).fontColor(0xCCCCCC).width('90%') - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 先后执行MoveTo(0, 300),(150, 0)(300, 300)两点之间画曲线, ClosePath() - Path().width(100).height(100).commands("M0 300 S150 0 300 300 Z") - // 先后执行MoveTo(0, 150),(0, 150)(150, 0)(300, 150)三点之间依次画曲线, LineTo(150, 300),ClosePath() - Path().width(100).height(100).commands('M0 150 C0 150 150 0 300 150 L150 300 Z') + Text('Curve graphics').fontSize(11).fontColor(0xCCCCCC).width('90%') + // 绘制弧线图形 + Row({ space: 20 }) { + Path() + .width(100) + .height(100) + .commands("M0 300 S150 0 300 300 Z") + .fillOpacity(0) + .stroke(Color.Black) + .strokeWidth(3) + Path() + .width(100) + .height(100) + .commands('M0 150 C0 150 150 0 300 150 L150 300 Z') + .fillOpacity(0) + .stroke(Color.Black) + .strokeWidth(3) + Path() + .width(100) + .height(100) + .commands('M0 200 A30 20 20 0 0 250 200 Z') + .fillOpacity(0) + .stroke(Color.Black) + .strokeWidth(3) } - }.width('100%').margin({ top: 5 }) + }.width('100%') + .margin({ top: 5 }) } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md index 40438c691979ad9109b11c72ff5edbe1009aad07..4bd7415fb552ecdff72011f2f23c5a7a057f8b1b 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polygon.md @@ -22,29 +22,29 @@ Polygon(options?: {width?: string | number, height?: string | number}) - 参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | + | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | - | width | string \| number | 否 | 0 | 宽度。 | - | height | string \| number | 否 | 0 | 高度。 | + | width | string \| number | 否 | 0 | 宽度。 | + | height | string \| number | 否 | 0 | 高度。 | ## 属性 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | +| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | | points | Array<Point> | [] | 否 | 多边形的顶点坐标列表。 | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置线条颜色。 | -| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | -| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | -| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | -| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置边框颜色,不设置时,默认没有边框线条。 | +| strokeDashArray | Array<Length> | [] | 否 | 设置边框间隙。 | +| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 | +| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置边框端点绘制样式。 | +| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置边框拐角绘制样式。 | | strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 | -| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 | -| strokeWidth | Length | 1 | 否 | 设置线条宽度。 | +| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置边框透明度。 | +| strokeWidth | Length | 1 | 否 | 设置边框宽度。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | ## Point @@ -64,18 +64,25 @@ Polygon(options?: {width?: string | number, height?: string | number}) @Component struct PolygonExample { build() { - Column({ space: 5 }) { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 在 100 * 100 的矩形框中绘制一个三角形,起点(0, 0),经过(50, 100),终点(100, 0) - Polygon({ width: 100, height: 100 }).points([[0, 0], [50, 100], [100, 0]]) - // 在 100 * 100 的矩形框中绘制一个四边形,起点(0, 0),经过(0, 100)和(100, 100),终点(100, 0) - Polygon().width(100).height(100).points([[0, 0], [0, 100], [100, 100], [100, 0]]) - // 在 100 * 100 的矩形框中绘制一个五边形,起点(50, 0),依次经过(0, 50)、(20, 100)和(80, 100),终点(100, 50) - Polygon().width(100).height(100).points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]]) - }.width('100%') - }.margin({ top: 5 }) + Column({ space: 10 }) { + // 在 100 * 100 的矩形框中绘制一个三角形,起点(0, 0),经过(50, 100),终点(100, 0) + Polygon({ width: 100, height: 100 }) + .points([[0, 0], [50, 100], [100, 0]]) + .fill(Color.Green) + // 在 100 * 100 的矩形框中绘制一个四边形,起点(0, 0),经过(0, 100)和(100, 100),终点(100, 0) + Polygon().width(100).height(100) + .points([[0, 0], [0, 100], [100, 100], [100, 0]]) + .fillOpacity(0) + .strokeWidth(5) + .stroke(Color.Blue) + // 在 100 * 100 的矩形框中绘制一个五边形,起点(50, 0),依次经过(0, 50)、(20, 100)和(80, 100),终点(100, 50) + Polygon().width(100).height(100) + .points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]]) + .fill(Color.Red) + .fillOpacity(0.6) + }.width('100%').margin({ top: 10 }) } } ``` -![zh-cn_image_0000001174582856](figures/zh-cn_image_0000001174582856.gif) +![zh-cn_image_0000001174582856](figures/zh-cn_image_0000001174582856.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md index 75da55722969a84c2c659837c2da3b200b743de0..f30e88962c288d32832d3698edf3a2707c2c281d 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-polyline.md @@ -23,22 +23,22 @@ Polyline(options?: {width?: string | number, height?: string | number}) - 参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | + | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | - | width | string \| number | 否 | 0 | 宽度。 | - | height | string \| number | 否 | 0 | 高度。 | + | width | string \| number | 否 | 0 | 宽度。 | + | height | string \| number | 否 | 0 | 高度。 | ## 属性 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | +| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | -| points | Array<Point> | [] | 否 | 折线经过坐标点列表。 | +| points | Array<Point> | [] | 否 | 折线经过坐标点列表。 | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置线条颜色。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置线条颜色。 | | strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | | strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | | strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | @@ -65,16 +65,28 @@ Polyline(options?: {width?: string | number, height?: string | number}) @Component struct PolylineExample { build() { - Column({ space: 5 }) { - Flex({ justifyContent: FlexAlign.SpaceAround }) { - // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100) - Polyline({ width: 100, height: 100 }).points([[0, 0], [20, 60], [100, 100]]) - // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(0,100),到达终点(100, 100) - Polyline().width(100).height(100).points([[0, 0], [0, 100], [100, 100]]) - }.width('100%') - }.margin({ top: 5 }) + Column({ space: 10 }) { + // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100) + Polyline({ width: 100, height: 100 }) + .points([[0, 0], [20, 60], [100, 100]]) + .fillOpacity(0) + .stroke(Color.Blue) + .strokeWidth(3) + // 在 100 * 100 的矩形框中绘制一段折线,起点(20, 0),经过(0,100),到达终点(100, 90) + Polyline() + .width(100) + .height(100) + .fillOpacity(0) + .stroke(Color.Red) + .strokeWidth(8) + .points([[20, 0], [0, 100], [100, 90]]) + // 设置折线拐角处为圆弧 + .strokeLineJoin(LineJoinStyle.Round) + // 设置折线两端为半圆 + .strokeLineCap(LineCapStyle.Round) + }.width('100%') } } ``` -![zh-cn_image_0000001219744185](figures/zh-cn_image_0000001219744185.gif) +![zh-cn_image_0000001219744185](figures/zh-cn_image_0000001219744185.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md index 41bf4dabafe90bfefb6739d325dcb372097d39f8..7df16792ea3737414696c9a370cdc523d457d0db 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-rect.md @@ -24,34 +24,34 @@ Rect(options?: {width?: string | number,height?: string | number,radius?: string {width?: string | number,height?: string | number,radiusWidth?: string | number,radiusHeight?: string | number}) - 参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | + | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | - | width | string \| number | 否 | 0 | 宽度。 | - | height | string \| number | 否 | 0 | 高度。 | - | radius | string \| number \| Array<string \| number> | 否 | 0 | 圆角半径,支持分别设置四个角的圆角度数。 | - | radiusWidth | string \| number | 否 | 0 | 圆角宽度。 | - | radiusHeight | string \| number | 否 | 0 | 圆角高度。 | + | width | string \| number | 否 | 0 | 宽度。 | + | height | string \| number | 否 | 0 | 高度。 | + | radius | string \| number \| Array<string \| number> | 否 | 0 | 圆角半径,支持分别设置四个角的圆角度数。 | + | radiusWidth | string \| number | 否 | 0 | 圆角宽度。 | + | radiusHeight | string \| number | 否 | 0 | 圆角高度。 | ## 属性 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性: -| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | +| 参数名称 | 参数类型 | 默认值 | 必填 | 参数描述 | | -------- | -------- | -------- | -------- | -------- | -| radiusWidth | string \| number | 0 | 否 | 圆角的宽度,仅设置宽时宽高一致。 | -| radiusHeight | string \| number | 0 | 否 | 圆角的高度,仅设置高时宽高一致。 | +| radiusWidth | string \| number | 0 | 否 | 圆角的宽度,仅设置宽时宽高一致。 | +| radiusHeight | string \| number | 0 | 否 | 圆角的高度,仅设置高时宽高一致。 | | radius | string \| number \| Array<string \| number> | 0 | 否 | 圆角半径大小。 | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置线条颜色。 | -| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | -| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | -| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | -| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置边框颜色,不设置时,默认没有边框线条。 | +| strokeDashArray | Array<Length> | [] | 否 | 设置边框间隙。 | +| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 | +| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置边框端点绘制样式。 | +| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置边框拐角绘制样式。 | | strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 | -| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置线条透明度。 | -| strokeWidth | Length | 1 | 否 | 设置线条宽度。 | +| strokeOpacity | number \| string \| [Resource](../../ui/ts-types.md#resource类型) | 1 | 否 | 设置边框透明度。 | +| strokeWidth | Length | 1 | 否 | 设置边框宽度。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | @@ -63,19 +63,30 @@ Rect(options?: {width?: string | number,height?: string | number,radius?: string @Component struct RectExample { build() { - Column({ space: 5 }) { - Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%') - // 绘制90% * 50矩形 + Column({ space: 10 }) { + Text('normal').fontSize(11).fontColor(0xCCCCCC).width('90%') + // 绘制90% * 50的矩形 Rect({ width: '90%', height: 50 }) - // 绘制90% * 50矩形 - Rect().width('90%').height(50) - - Text('with rounded corners').fontSize(9).fontColor(0xCCCCCC).width('90%') - // 绘制90% * 50矩形, 圆角宽高20 - Rect({ width: '90%', height: 50 }).radiusHeight(20).radiusWidth(20) - // 绘制90% * 50矩形, 圆角宽高20 - Rect({ width: '90%', height: 50 }).radius(20) - }.width('100%').margin({ top: 5 }) + .fill(Color.Pink) + // 绘制90% * 50的矩形框 + Rect() + .width('90%') + .height(50) + .fillOpacity(0) + .stroke(Color.Red) + .strokeWidth(3) + + Text('with rounded corners').fontSize(11).fontColor(0xCCCCCC).width('90%') + // 绘制90% * 80的矩形, 圆角宽高分别为40、20 + Rect({ width: '90%', height: 80 }) + .radiusHeight(20) + .radiusWidth(40) + .fill(Color.Pink) + // 绘制90% * 80的矩形, 圆角宽高为20 + Rect({ width: '90%', height: 80 }) + .radius(20) + .fill(Color.Pink) + }.width('100%').margin({ top: 10 }) } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md index aabb49baf4fbfbd02b7469a0badf9a6b2e7445d0..c7675ae3c20054eb5ac0c32ecda23ca587627578 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-drawing-components-shape.md @@ -40,81 +40,199 @@ Shape(value?: PixelMap) | viewPort | {
x?: number \| string,
y?: number \| string,
width?: number \| string,
height?: number \| string
} | { x:0, y:0, width:0, height:0 } | 否 | 形状的视口。 | | fill | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置填充区域颜色。 | | fillOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置填充区域透明度。 | -| stroke | [ResourceColor](ts-types.md#resourcecolor8) | Color.Black | 否 | 设置线条颜色。 | -| strokeDashArray | Array<Length> | [] | 否 | 设置线条间隙。 | -| strokeDashOffset | number \| string | 0 | 否 | 线条绘制起点的偏移量。 | -| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置线条端点绘制样式。 | -| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置线条拐角绘制样式。 | +| stroke | [ResourceColor](ts-types.md#resourcecolor8) | - | 否 | 设置边框颜色,不设置时,默认没有边框线条。 | +| strokeDashArray | Array<Length> | [] | 否 | 设置边框间隙。 | +| strokeDashOffset | number \| string | 0 | 否 | 边框绘制起点的偏移量。 | +| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | 否 | 设置边框端点绘制样式。 | +| strokeLineJoin | [LineJoinStyle](ts-appendix-enums.md#linejoinstyle) | LineJoinStyle.Miter | 否 | 设置边框拐角绘制样式。 | | strokeMiterLimit | number \| string | 4 | 否 | 设置锐角绘制成斜角的极限值。 | -| strokeOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置线条透明度。 | -| strokeWidth | number \| string | 1 | 否 | 设置线条宽度。 | +| strokeOpacity | number \| string \| [Resource](ts-types.md#resource) | 1 | 否 | 设置边框透明度。 | +| strokeWidth | number \| string | 1 | 否 | 设置边框宽度。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | | mesh8+ | Array<number>,number,number | [],0,0 | 否 | 设置mesh效果。第一个参数为长度(column + 1)* (row + 1)* 2的数组,它记录了扭曲后的位图各个顶点位置,第二个参数为mesh矩阵列数column,第三个参数为mesh矩阵行数row。 | - ## 示例 +### 示例1 + ```ts // xxx.ets @Entry @Component struct ShapeExample { build() { - Column({ space: 5 }) { - Text('basic').fontSize(30).fontColor(0xCCCCCC).width(320) - // 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) - // 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317Af7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) - // 在Shape的(-2, 118)点绘制一个 300 * 10 线段,颜色0x317Af7,边框颜色黑色,宽度4,间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) + Column({ space: 10 }) { + Text('basic').fontSize(11).fontColor(0xCCCCCC).width(320) + // 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317AF7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启) + // 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317AF7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启) + // 在Shape的(-2, 118)点绘制一个 300 * 10 直线路径,颜色0x317AF7,边框颜色黑色,宽度4,间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启) Shape() { Rect().width(300).height(50) Ellipse().width(300).height(50).offset({ x: 0, y: 60 }) Path().width(300).height(10).commands('M0 0 L900 0').offset({ x: 0, y: 120 }) } .viewPort({ x: -2, y: -2, width: 304, height: 130 }) - .fill(0x317Af7).stroke(Color.Black).strokeWidth(4) - .strokeDashArray([20]).strokeDashOffset(10).strokeLineCap(LineCapStyle.Round) - .strokeLineJoin(LineJoinStyle.Round).antiAlias(true) - // 在Shape的(-1, -1)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度2 + .fill(0x317AF7) + .stroke(Color.Black) + .strokeWidth(4) + .strokeDashArray([20]) + .strokeDashOffset(10) + .strokeLineCap(LineCapStyle.Round) + .strokeLineJoin(LineJoinStyle.Round) + .antiAlias(true) + // 分别在Shape的(0, 0)、(-5, -5)点绘制一个 300 * 50 带边框的矩形,可以看出之所以将视口的起始位置坐标设为负值是因为绘制的起点默认为线宽的中点位置,因此要让边框完全显示则需要让视口偏移半个线宽 Shape() { Rect().width(300).height(50) - }.viewPort({ x: -1, y: -1, width: 302, height: 52 }).fill(0x317Af7).stroke(Color.Black).strokeWidth(2) + } + .viewPort({ x: 0, y: 0, width: 320, height: 70 }) + .fill(0x317AF7) + .stroke(Color.Black) + .strokeWidth(10) - Text('border').fontSize(30).fontColor(0xCCCCCC).width(320).margin({top:30}) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20 Shape() { - Path().width(300).height(10).commands('M0 0 L900 0') - }.viewPort({ x: 0, y: -5, width: 300, height: 20 }).stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10 + Rect().width(300).height(50) + } + .viewPort({ x: -5, y: -5, width: 320, height: 70 }) + .fill(0x317AF7) + .stroke(Color.Black) + .strokeWidth(10) + + Text('path').fontSize(11).fontColor(0xCCCCCC).width(320) + // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20 Shape() { Path().width(300).height(10).commands('M0 0 L900 0') } .viewPort({ x: 0, y: -5, width: 300, height: 20 }) - .stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]).strokeDashOffset(10) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,透明度0.5 + .stroke(0xEE8443) + .strokeWidth(10) + .strokeDashArray([20]) + // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,向左偏移10 Shape() { Path().width(300).height(10).commands('M0 0 L900 0') - }.viewPort({ x: 0, y: -5, width: 300, height: 20 }).stroke(0xEE8443).strokeWidth(10).strokeOpacity(0.5) - // 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10,尖端样式圆角 + } + .viewPort({ x: 0, y: -5, width: 300, height: 20 }) + .stroke(0xEE8443) + .strokeWidth(10) + .strokeDashArray([20]) + .strokeDashOffset(10) + // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,透明度0.5 Shape() { Path().width(300).height(10).commands('M0 0 L900 0') } .viewPort({ x: 0, y: -5, width: 300, height: 20 }) - .stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]).strokeLineCap(LineCapStyle.Round) - // 在Shape的(-5, -5)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框宽度10,边框颜色0xEE8443,拐角样式圆角 + .stroke(0xEE8443) + .strokeWidth(10) + .strokeOpacity(0.5) + // 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,线条两端样式为半圆 Shape() { - Rect().width(300).height(100) + Path().width(300).height(10).commands('M0 0 L900 0') } - .viewPort({ x: -5, y: -5, width: 310, height: 120 }) - .fill(0x317Af7).stroke(0xEE8443).strokeWidth(10).strokeLineJoin(LineJoinStyle.Round) + .viewPort({ x: 0, y: -5, width: 300, height: 20 }) + .stroke(0xEE8443) + .strokeWidth(10) + .strokeDashArray([20]) + .strokeLineCap(LineCapStyle.Round) + // 在Shape的(-80, -5)点绘制一个封闭路径,颜色0x317AF7,线条宽度10,边框颜色0xEE8443,拐角样式锐角(默认值) Shape() { - Path().width(300).height(60).commands('M0 0 L400 0 L400 200 Z') + Path().width(200).height(60).commands('M0 0 L400 0 L400 150 Z') } - .viewPort({ x: -80, y: -5, width: 310, height: 100 }) - .fill(0x317Af7).stroke(0xEE8443).strokeWidth(10) - .strokeLineJoin(LineJoinStyle.Miter).strokeMiterLimit(5) + .viewPort({ x: -80, y: -5, width: 310, height: 90 }) + .fill(0x317AF7) + .stroke(0xEE8443) + .strokeWidth(10) + .strokeLineJoin(LineJoinStyle.Miter) + .strokeMiterLimit(5) }.width('100%').margin({ top: 15 }) } } ``` ![zh-cn_image_0000001184628104](figures/zh-cn_image_0000001184628104.png) + +### 示例2 + +```ts +// xxx.ets +@Entry +@Component +struct ShapeMeshExample { + @State columnVal: number = 0; + @State rowVal: number = 0; + @State count: number = 0; + @State verts: Array = []; + @State shapeWidth: number = 600; + @State shapeHeight: number = 600; + + build() { + Column() { + Shape() { + Rect() + .width('250px') + .height('250px') + .radiusWidth('10px') + .radiusHeight('10px') + .stroke('10px') + .margin({ left: '10px', top: '10px' }) + .strokeWidth('10px') + .fill(Color.Blue) + Rect() + .width('250px') + .height('250px') + .radiusWidth('10px') + .radiusHeight('10px') + .stroke('10px') + .margin({ left: '270px', top: '10px' }) + .strokeWidth('10px') + .fill(Color.Red) + } + .mesh(this.verts, this.columnVal, this.rowVal) + .width(this.shapeWidth + 'px') + .height(this.shapeHeight + 'px') + // 手指触摸Shape组件时会显示mesh扭曲效果 + .onTouch((event: TouchEvent) => { + var touchX = event.touches[0].x * 2; + var touchY = event.touches[0].y * 2; + this.columnVal = 20; + this.rowVal = 20; + this.count = (this.columnVal + 1) * (this.rowVal + 1); + var orig = [this.count * 2]; + var index = 0; + for (var i = 0; i <= this.rowVal; i++) { + var fy = this.shapeWidth * i / this.rowVal; + for (var j = 0; j <= this.columnVal; j++) { + var fx = this.shapeWidth * j / this.columnVal; + orig[index * 2 + 0] = this.verts[index * 2 + 0] = fx; + orig[index * 2 + 1] = this.verts[index * 2 + 1] = fy; + index++; + } + } + for (var k = 0; k < this.count * 2; k += 2) { + var dx = touchX - orig[k + 0]; + var dy = touchY - orig[k + 1]; + var dd = dx * dx + dy * dy; + var d = Math.sqrt(dd); + var pull = 80000 / (dd * d); + if (pull >= 1) { + this.verts[k + 0] = touchX; + this.verts[k + 1] = touchY; + } else { + this.verts[k + 0] = orig[k + 0] + dx * pull; + this.verts[k + 1] = orig[k + 1] + dy * pull; + } + } + }) + } + .width('600px') + .height('600px') + .border({ width: 3, color: Color.Black }) + } +} +``` + +示意图: + +![zh-cn_image1_0000001184628104](figures/zh-cn_image1_0000001184628104.png) + +手指触摸Shape组件时会显示mesh扭曲效果: + +![zh-cn_image2_0000001184628104](figures/zh-cn_image2_0000001184628104.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md b/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md index 8fe61b8d874cf99ed9f63ed79ddd9ea49cadec63..4fb3733c1164da8a9e65d949a2fea0979b288a62 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-gesture-settings.md @@ -43,7 +43,7 @@ ## 响应手势事件 -组件通过gesture方法绑定手势对象,可以通过手势对象提供的事件相应响应手势操作。例如通过TapGesture对象的onAction事件响应点击事件。其余手势的事件定义见各个手势对象章节。 +组件通过gesture方法绑定手势对象,可以通过手势对象提供的事件相应响应手势操作。例如通过TapGesture对象的onAction事件响应点击事件。其余手势的事件定义见各个手势对象章节。若需绑定多种手势请使用 [组合手势](ts-combined-gestures.md)。 - TapGesture事件说明 | 名称 | 功能描述 | @@ -77,8 +77,8 @@ | 名称 | 类型 | 描述 | | -------- | -------- | -------- | | id | number | 手指的索引编号。 | - | globalX | number | 相对于设备屏幕左上角的x轴坐标。 | - | globalY | number | 相对于设备屏幕左上角的y轴坐标。 | + | globalX | number | 相对于应用窗口左上角的x轴坐标。 | + | globalY | number | 相对于应用窗口左上角的y轴坐标。 | | localX | number | 相对于当前组件元素左上角的x轴坐标。 | | localY | number | 相对于当前组件元素左上角的y轴坐标。 | @@ -90,28 +90,51 @@ @Entry @Component struct GestureSettingsExample { - @State value: string = '' + @State priorityTestValue: string = ''; + @State parallelTestValue: string = ''; build() { - Column(){ + Column() { Column() { - Text('Click\n' + this.value) + Text('TapGesture:' + this.priorityTestValue).fontSize(28) .gesture( TapGesture() .onAction(() => { - this.value = 'gesture onAction' + this.priorityTestValue += '\nText'; })) - }.height(200).width(300).padding(60).border({ width: 1 }) - //设置为priorityGesture时,会优先识别该绑定手势忽略内部gesture手势 + } + .height(200) + .width(250) + .padding(20) + .margin(20) + .border({ width: 3 }) + // 设置为priorityGesture时,点击文本会忽略Text组件的TapGesture手势事件,优先识别父组件Column的TapGesture手势事件 .priorityGesture( TapGesture() .onAction((event: GestureEvent) => { - this.value = 'priorityGesture onAction' + '\ncomponent globalPos:(' - + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:' - + event.target.area.width + '\nheight:' + event.target.area.height - }), GestureMask.IgnoreInternal - ) - }.padding(60) + this.priorityTestValue += '\nColumn'; + }), GestureMask.IgnoreInternal) + + Column() { + Text('TapGesture:' + this.parallelTestValue).fontSize(28) + .gesture( + TapGesture() + .onAction(() => { + this.parallelTestValue += '\nText'; + })) + } + .height(200) + .width(250) + .padding(20) + .margin(20) + .border({ width: 3 }) + // 设置为parallelGesture时,点击文本会同时触发子组件Text与父组件Column的TapGesture手势事件 + .parallelGesture( + TapGesture() + .onAction((event: GestureEvent) => { + this.parallelTestValue += '\nColumn'; + }), GestureMask.Normal) + } } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-media-components-video.md b/zh-cn/application-dev/reference/arkui-ts/ts-media-components-video.md index ce1f6992841af191f591ff9bdd65f7eb02693608..2c7587fcb30f5e455f8f099ca2dfba69fd3674dd 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-media-components-video.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-media-components-video.md @@ -155,7 +155,7 @@ setCurrentTime(value: number, seekMode: SeekMode) @Entry @Component struct VideoCreateComponent { - @State srcs: Resource = $rawfile('video1'); + @State srcs: Resource = $rawfile('video1.mp4'); @State previewUris: Resource = $r('app.media.img'); @State currentProgressRates: number = 1; @State autoPlays: boolean = false; @@ -197,7 +197,7 @@ struct VideoCreateComponent { }) Row() { Button("src").onClick(() => { - this.srcs = $rawfile('video2'); + this.srcs = $rawfile('video2.mp4'); }); Button("previewUri").onClick(() => { this.previewUris = $r('app.media.img1'); diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-methods-action-sheet.md b/zh-cn/application-dev/reference/arkui-ts/ts-methods-action-sheet.md index d240b7539f15bc40559e4c365447c737eebbb897..da58b8c0cd2e6baa7e6dc4a0f4256b67d38d1e8e 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-methods-action-sheet.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-methods-action-sheet.md @@ -19,24 +19,24 @@ show(value: { title: string | Resource, message: string  定义列表弹窗并弹出。 **参数:** - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | -------- | -------- | -------- | -------- | -------- | - | title | string \| [Resource](ts-types.md#resource) | 是 | - | 弹窗标题。 | - | message | string \| [Resource](ts-types.md#resource) | 是 | - | 弹窗内容。 | - | autoCancel | boolean | 否 | true | 点击遮障层时,是否关闭弹窗。 | - | confirm | {
value: string \| [Resource](ts-types.md#resource),
action: () => void
} | 否 | - | 确认按钮的文本内容和点击回调。
value:按钮文本内容。
action: 按钮选中时的回调。 | - | cancel | () => void | 否 | - | 点击遮障层关闭dialog时的回调。 | - | alignment | [DialogAlignment](ts-methods-custom-dialog-box.md) | 否 | DialogAlignment.Default | 弹窗在竖直方向上的对齐方式。 | - | offset | {
dx: number \| string \| [Resource](ts-types.md#resource),
dy: number \| string \| [Resource](ts-types.md#resource)
} | 否 | {
dx: 0,
dy: 0
} | 弹窗相对alignment所在位置的偏移量。 | - | sheets | Array<SheetInfo> | 是 | - | 设置选项内容,每个选择项支持设置图片、文本和选中的回调。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| title | string \| [Resource](ts-types.md#resource) | 是 | - | 弹窗标题。 | +| message | string \| [Resource](ts-types.md#resource) | 是 | - | 弹窗内容。 | +| autoCancel | boolean | 否 | true | 点击遮障层时,是否关闭弹窗。 | +| confirm | {
value: string \| [Resource](ts-types.md#resource),
action: () => void
} | 否 | - | 确认按钮的文本内容和点击回调。
value:按钮文本内容。
action: 按钮选中时的回调。 | +| cancel | () => void | 否 | - | 点击遮障层关闭dialog时的回调。 | +| alignment | [DialogAlignment](ts-methods-custom-dialog-box.md) | 否 | DialogAlignment.Default | 弹窗在竖直方向上的对齐方式。 | +| offset | {
dx: number \| string \| [Resource](ts-types.md#resource),
dy: number \| string \| [Resource](ts-types.md#resource)
} | 否 | {
dx: 0,
dy: 0
} | 弹窗相对alignment所在位置的偏移量。 | +| sheets | Array<SheetInfo> | 是 | - | 设置选项内容,每个选择项支持设置图片、文本和选中的回调。 | ## SheetInfo接口说明 - - | 参数名 | 参数类型 | 必填 | 参数描述 | - | ------ | ------------------------------------------------------------ | ---- | ----------------- | - | title | string \| [Resource](../../ui/ts-types.md#resource) | 是 | 选项的文本内容。 | - | icon | string \| [Resource](../../ui/ts-types.md#resource) | 否 | 选项的图标,默认无图标显示。 | - | action | ()=>void | 是 | 选项选中的回调。 | + +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ------ | ------------------------------------------------------------ | ---- | ----------------- | +| title | string \| [Resource](../../ui/ts-types.md#resource) | 是 | 选项的文本内容。 | +| icon | string \| [Resource](../../ui/ts-types.md#resource) | 否 | 选项的图标,默认无图标显示。 | +| action | ()=>void | 是 | 选项选中的回调。 | ## 示例 @@ -57,26 +57,26 @@ struct ActionSheetExapmle { confirm: { value: 'Confirm button', action: () => { - console.log('Get Alert Dialog handled') + console.log('Get Alert Dialog handled'); } }, sheets: [ { title: 'apples', action: () => { - console.error('apples') + console.log('apples'); } }, { title: 'bananas', action: () => { - console.error('bananas') + console.log('bananas'); } }, { title: 'pears', action: () => { - console.error('pears') + console.log('pears'); } } ] diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-methods-alert-dialog-box.md b/zh-cn/application-dev/reference/arkui-ts/ts-methods-alert-dialog-box.md index eadfff57f805c023f5f78c1b982e790559779819..fb033974e51836c49150826b3930fa0d8bfbe2f4 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-methods-alert-dialog-box.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-methods-alert-dialog-box.md @@ -14,29 +14,29 @@ | show | value: { AlertDialogParamWithConfirm \| AlertDialogParamWithButtons} | - | 定义并显示AlertDialog组件。 | ## AlertDialogParamWithConfirm对象说明 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | -------- | -------- | -------- | -------- | -------- | - | title | string \| [Resource](ts-types.md#resource) | 否 | - | 弹窗标题。 | - | message | string \| [Resource](ts-types.md#resource) | 是 | - | 弹窗内容。 | - | autoCancel | boolean | 否 | true | 点击遮障层时,是否关闭弹窗。 | - | confirm | {
value: string \| [Resource](ts-types.md#resource),
fontColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
backgroundColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
action: () => void
} | 否 | - | 确认按钮的文本内容、文本色、按钮背景色和点击回调。 | - | cancel | () => void | 否 | - | 点击遮障层关闭dialog时的回调。 | - | alignment | [DialogAlignment](ts-methods-custom-dialog-box.md#dialogalignment枚举说明) | 否 | DialogAlignment.Default | 弹窗在竖直方向上的对齐方式。 | - | offset | {
dx: Length \| [Resource](ts-types.md#resource),
dy: Length  \| [Resource](ts-types.md#resource)
} | 否 | - | 弹窗相对alignment所在位置的偏移量。 | - | gridCount | number | 否 | - | 弹窗容器宽度所占用栅格数。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| title | string \| [Resource](ts-types.md#resource) | 否 | - | 弹窗标题。 | +| message | string \| [Resource](ts-types.md#resource) | 是 | - | 弹窗内容。 | +| autoCancel | boolean | 否 | true | 点击遮障层时,是否关闭弹窗。 | +| confirm | {
value: string \| [Resource](ts-types.md#resource),
fontColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
backgroundColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
action: () => void
} | 否 | - | 确认按钮的文本内容、文本色、按钮背景色和点击回调。 | +| cancel | () => void | 否 | - | 点击遮障层关闭dialog时的回调。 | +| alignment | [DialogAlignment](ts-methods-custom-dialog-box.md#dialogalignment枚举说明) | 否 | DialogAlignment.Default | 弹窗在竖直方向上的对齐方式。 | +| offset | {
dx: Length \| [Resource](ts-types.md#resource),
dy: Length  \| [Resource](ts-types.md#resource)
} | 否 | - | 弹窗相对alignment所在位置的偏移量。 | +| gridCount | number | 否 | - | 弹窗容器宽度所占用栅格数。
**说明:**
当gridCount小于等于0时,弹窗宽度是固定的;大于0时,按照设置的数值显示宽度,最大值为4,若值为小数,则向下取整。 | ## AlertDialogParamWithButtons对象说明 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | -------- | -------- | -------- | -------- | -------- | - | title | string \|& [Resource](ts-types.md#resource) | 否 | - | 弹窗标题。 | - | message | string \|& [Resource](ts-types.md#resource) | 是 | - | 弹窗内容。 | - | autoCancel | boolean | 否 | true | 点击遮障层时,是否关闭弹窗。 | - | primaryButton | {
value: string \| [Resource](ts-types.md#resource),
fontColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
backgroundColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
action: () => void;
} | 否 | - | 按钮的文本内容、文本色、按钮背景色和点击回调。 | - | secondaryButton | {
value: string \| [Resource](ts-types.md#resource),
fontColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
backgroundColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
action: () => void;
} | 否 | - | 按钮的文本内容、文本色、按钮背景色和点击回调。 | - | cancel | () => void | 否 | - | 点击遮障层关闭dialog时的回调。 | - | alignment | [DialogAlignment](ts-methods-custom-dialog-box.md#dialogalignment枚举说明) | 否 | DialogAlignment.Default | 弹窗在竖直方向上的对齐方式。 | - | offset | {
dx: Length \| [Resource](ts-types.md#resource),
dy: Length  \| [Resource](ts-types.md#resource)
} | 否 | - | 弹窗相对alignment所在位置的偏移量。 | - | gridCount | number | 否 | - | 弹窗容器宽度所占用栅格数。 | +| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | +| -------- | -------- | -------- | -------- | -------- | +| title | string \|& [Resource](ts-types.md#resource) | 否 | - | 弹窗标题。 | +| message | string \|& [Resource](ts-types.md#resource) | 是 | - | 弹窗内容。 | +| autoCancel | boolean | 否 | true | 点击遮障层时,是否关闭弹窗。 | +| primaryButton | {
value: string \| [Resource](ts-types.md#resource),
fontColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
backgroundColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
action: () => void;
} | 否 | - | 按钮的文本内容、文本色、按钮背景色和点击回调。 | +| secondaryButton | {
value: string \| [Resource](ts-types.md#resource),
fontColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
backgroundColor?: Color \| number \| string \| [Resource](ts-types.md#resource),
action: () => void;
} | 否 | - | 按钮的文本内容、文本色、按钮背景色和点击回调。 | +| cancel | () => void | 否 | - | 点击遮障层关闭dialog时的回调。 | +| alignment | [DialogAlignment](ts-methods-custom-dialog-box.md#dialogalignment枚举说明) | 否 | DialogAlignment.Default | 弹窗在竖直方向上的对齐方式。 | +| offset | {
dx: Length \| [Resource](ts-types.md#resource),
dy: Length  \| [Resource](ts-types.md#resource)
} | 否 | - | 弹窗相对alignment所在位置的偏移量。 | +| gridCount | number | 否 | - | 弹窗容器宽度所占用栅格数。 | ## 示例 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-dialog-box.md b/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-dialog-box.md index 8f31d28b33b20faa55231275099e3459bce1f979..36241b460a044bf69851e5ffb8c079a31a612f7a 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-dialog-box.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-methods-custom-dialog-box.md @@ -24,18 +24,18 @@ CustomDialogController(value:{builder: CustomDialog, cancel?: () => void, aut | gridCount8+ | number | 否 | - | 弹窗宽度占栅格宽度的个数。 | ## DialogAlignment枚举说明 - | 名称 | 描述 | - | -------- | -------- | - | Top | 垂直顶部对齐。 | - | Center | 垂直居中对齐。 | - | Bottom | 垂直底部对齐。 | - | Default | 默认对齐。 | - | TopStart8+ | 左上对齐。 | - | TopEnd8+ | 右上对齐。 | - | CenterStart8+ | 左中对齐。 | - | CenterEnd8+ | 右中对齐。 | - | BottomStart8+ | 左下对齐。 | - | BottomEnd8+ | 右下对齐。 | +| 名称 | 描述 | +| -------- | -------- | +| Top | 垂直顶部对齐。 | +| Center | 垂直居中对齐。 | +| Bottom | 垂直底部对齐。 | +| Default | 默认对齐。
**说明:**
与枚举值Center效果相同。 | +| TopStart8+ | 左上对齐。 | +| TopEnd8+ | 右上对齐。 | +| CenterStart8+ | 左中对齐。 | +| CenterEnd8+ | 右中对齐。 | +| BottomStart8+ | 左下对齐。 | +| BottomEnd8+ | 右下对齐。 | ## CustomDialogController diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md b/zh-cn/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md index 2917d91350b4fd82e62f3a2c1092827f452f7c2d..0d0f378076512d41dfb2910f018d44f6f7bc7548 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-methods-timepicker-dialog.md @@ -5,10 +5,6 @@ 默认以00:00至23:59的时间区间创建滑动选择器,展示在弹窗上。 -## 权限列表 - -无 - ## TimePickerDialog.show show(options?: TimePickerDialogOptions) @@ -16,13 +12,13 @@ show(options?: TimePickerDialogOptions) 定义时间滑动选择器弹窗并弹出。 - options参数 - | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | - | -------- | -------- | -------- | -------- | -------- | - | selected | Date | 否 | 当前系统时间 | 设置选中项的时间。 | - | useMilitaryTime | boolean | 否 | false | 展示时间是否为24小时制。 | - | onAccept | (value: [TimePickerResult](ts-basic-components-timepicker.md#TimePickerResult对象说明)) => void | 否 | - | 点击弹窗中确定按钮时触发。 | - | onCancel | () => void | 否 | - | 点击弹窗中取消按钮时触发。 | - | onChange | (value: [TimePickerResult](ts-basic-components-timepicker.md#TimePickerResult对象说明)) => void | 否 | - | 滑动选择器,当前选择项改变时触发。 | + | 参数名 | 参数类型 | 必填 | 参数描述 | + | -------- | -------- | -------- | -------- | + | selected | Date | 否 | 设置选中项的时间。
默认值:当前系统时间 | + | useMilitaryTime | boolean | 否 | 展示时间是否为24小时制。
默认值:false | + | onAccept | (value: [TimePickerResult](ts-basic-components-timepicker.md#TimePickerResult对象说明)) => void | 否 | 点击弹窗中确定按钮时触发。 | + | onCancel | () => void | 否 | 点击弹窗中取消按钮时触发。 | + | onChange | (value: [TimePickerResult](ts-basic-components-timepicker.md#TimePickerResult对象说明)) => void | 否 | 滑动选择器,当前选择项改变时触发。 | ## 示例 @@ -32,7 +28,7 @@ show(options?: TimePickerDialogOptions) @Entry @Component struct TimePickerDialogExample01 { - @State isUseMilitaryTime: boolean = true + @State isUseMilitaryTime: boolean = true; build() { Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, @@ -41,13 +37,13 @@ struct TimePickerDialogExample01 { TimePickerDialog.show({ useMilitaryTime: this.isUseMilitaryTime, onAccept: (value: TimePickerResult) => { - console.info("TimePickerDialog:onAccept()" + JSON.stringify(value)) + console.info("TimePickerDialog:onAccept()" + JSON.stringify(value)); }, onCancel: () => { - console.info("TimePickerDialog:onCancel()") + console.info("TimePickerDialog:onCancel()"); }, onChange: (value: TimePickerResult) => { - console.info("TimePickerDialog:onChange()" + JSON.stringify(value)) + console.info("TimePickerDialog:onChange()" + JSON.stringify(value)); } }) }) @@ -55,13 +51,16 @@ struct TimePickerDialogExample01 { } } ``` + ![zh-cn_image_0000001118642010](figures/zh-cn_image_0000001118642010.gif) + ### 时间滑动选择器(12小时制)示例 + ```ts // xxx.ets @Entry @Component struct TimePickerDialogExample02 { - @State isUseMilitaryTime: boolean = false + @State isUseMilitaryTime: boolean = false; build() { Flex({direction: FlexDirection.Column, alignItems: ItemAlign.Center, @@ -70,13 +69,13 @@ struct TimePickerDialogExample02 { TimePickerDialog.show({ useMilitaryTime: this.isUseMilitaryTime, onAccept: (value: TimePickerResult) => { - console.info("TimePickerDialog:onAccept()" + JSON.stringify(value)) + console.info("TimePickerDialog:onAccept()" + JSON.stringify(value)); }, onCancel: () => { - console.info("TimePickerDialog:onCancel()") + console.info("TimePickerDialog:onCancel()"); }, onChange: (value: TimePickerResult) => { - console.info("TimePickerDialog:onChange()" + JSON.stringify(value)) + console.info("TimePickerDialog:onChange()" + JSON.stringify(value)); } }) }) @@ -84,3 +83,5 @@ struct TimePickerDialogExample02 { } } ``` + + ![zh-cn_image_0000001118642020](figures/zh-cn_image_0000001118642020.gif) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md b/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md index 29f42de35dc9438639a8b5fe09b9959b92871aed..708ffa6e29d21b398af43a3076f273f066ea8f74 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-offscreencanvasrenderingcontext2d.md @@ -4,7 +4,7 @@ > 从 API Version 8 开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -使用OffscreenCanvasRenderingContext2D在Canvas上进行离屏绘制,绘制对象可以是矩形、文本、图片等。离屏绘制是指将需要绘制的内容先绘制在缓存区,然后将其转换成图片,一次性绘制绘制到canvas上,加快了绘制速度。 +使用OffscreenCanvasRenderingContext2D在Canvas上进行离屏绘制,绘制对象可以是矩形、文本、图片等。离屏绘制是指将需要绘制的内容先绘制在缓存区,然后将其转换成图片,一次性绘制到canvas上,加快了绘制速度。 ## 接口 @@ -13,11 +13,11 @@ OffscreenCanvasRenderingContext2D(width: number, height: number, setting: Render **参数:** -| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | -| ------- | ---------------------------------------- | ---- | ---- | ------------------------------ | -| width | number | 是 | - | 离屏画布的宽度 | -| height | number | 是 | - | 离屏画布的高度 | -| setting | [RenderingContextSettings](ts-canvasrenderingcontext2d.md#renderingcontextsettings) | 是 | - | 见RenderingContextSettings接口描述。 | +| 参数名 | 参数类型 | 必填 | 参数描述 | +| ------- | ------------------------------------------------------------ | ---- | ------------------------------------ | +| width | number | 是 | 离屏画布的宽度 | +| height | number | 是 | 离屏画布的高度 | +| setting | [RenderingContextSettings](ts-canvasrenderingcontext2d.md#renderingcontextsettings) | 是 | 见RenderingContextSettings接口描述。 | ## 属性 @@ -703,12 +703,12 @@ fillRect(x: number, y: number, w: number, h: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 说明 | - | ------ | ------ | ---- | ---- | ------------- | - | x | number | 是 | 0 | 指定矩形左上角点的x坐标。 | - | y | number | 是 | 0 | 指定矩形左上角点的y坐标。 | - | width | number | 是 | 0 | 指定矩形的宽度。 | - | height | number | 是 | 0 | 指定矩形的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| ------ | ------ | ---- | ---- | ------------- | +| x | number | 是 | 0 | 指定矩形左上角点的x坐标。 | +| y | number | 是 | 0 | 指定矩形左上角点的y坐标。 | +| width | number | 是 | 0 | 指定矩形的宽度。 | +| height | number | 是 | 0 | 指定矩形的高度。 | **示例:** @@ -750,12 +750,12 @@ strokeRect(x: number, y: number, w: number, h: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 说明 | - | ------ | ------ | ---- | ---- | ------------ | - | x | number | 是 | 0 | 指定矩形的左上角x坐标。 | - | y | number | 是 | 0 | 指定矩形的左上角y坐标。 | - | width | number | 是 | 0 | 指定矩形的宽度。 | - | height | number | 是 | 0 | 指定矩形的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| ------ | ------ | ---- | ---- | ------------ | +| x | number | 是 | 0 | 指定矩形的左上角x坐标。 | +| y | number | 是 | 0 | 指定矩形的左上角y坐标。 | +| width | number | 是 | 0 | 指定矩形的宽度。 | +| height | number | 是 | 0 | 指定矩形的高度。 | **示例:** @@ -796,12 +796,12 @@ clearRect(x: number, y: number, w: number, h: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------ | ------ | ---- | ---- | ------------- | - | x | number | 是 | 0 | 指定矩形上的左上角x坐标。 | - | y | number | 是 | 0 | 指定矩形上的左上角y坐标。 | - | width | number | 是 | 0 | 指定矩形的宽度。 | - | height | number | 是 | 0 | 指定矩形的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ------ | ------ | ---- | ---- | ------------- | +| x | number | 是 | 0 | 指定矩形上的左上角x坐标。 | +| y | number | 是 | 0 | 指定矩形上的左上角y坐标。 | +| width | number | 是 | 0 | 指定矩形的宽度。 | +| height | number | 是 | 0 | 指定矩形的高度。 | **示例:** @@ -844,12 +844,12 @@ fillText(text: string, x: number, y: number, maxWidth?: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 说明 | - | ---- | ------ | ---- | ---- | --------------- | - | text | string | 是 | “” | 需要绘制的文本内容。 | - | x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 | - | y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 | - | maxWidth | number | 否 | - | 指定文本允许的最大宽度。 | +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| ---- | ------ | ---- | ---- | --------------- | +| text | string | 是 | “” | 需要绘制的文本内容。 | +| x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 | +| y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 | +| maxWidth | number | 否 | - | 指定文本允许的最大宽度。 | **示例:** @@ -891,12 +891,12 @@ strokeText(text: string, x: number, y: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | --------------- | - | text | string | 是 | “” | 需要绘制的文本内容。 | - | x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 | - | y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 | - | maxWidth | number | 否 | - | 需要绘制的文本的最大宽度 。| +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | --------------- | +| text | string | 是 | “” | 需要绘制的文本内容。 | +| x | number | 是 | 0 | 需要绘制的文本的左下角x坐标。 | +| y | number | 是 | 0 | 需要绘制的文本的左下角y坐标。 | +| maxWidth | number | 否 | - | 需要绘制的文本的最大宽度 。| **示例:** @@ -938,33 +938,33 @@ measureText(text: string): TextMetrics **参数:** - | 参数 | 类型 | 必填 | 默认值 | 说明 | - | ---- | ------ | ---- | ---- | ---------- | - | text | string | 是 | "" | 需要进行测量的文本。 | +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| ---- | ------ | ---- | ---- | ---------- | +| text | string | 是 | "" | 需要进行测量的文本。 | **返回值:** - | 类型 | 说明 | - | ----------- | ------- | - | TextMetrics | 文本的尺寸信息 | +| 类型 | 说明 | +| ----------- | ------- | +| TextMetrics | 文本的尺寸信息 | **TextMetrics类型描述:** - | 属性 | 类型 | 描述 | - | ----- | ------ | ------- | - | width | number | 字符串的宽度。 | - | height | number | 字符串的高度。 | - | actualBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界顶部的距离,当前值为0。 | - | actualBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界底部的距离,当前值为0。 | - | actualBoundingBoxLeft | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界左侧的距离,当前值为0。 | - | actualBoundingBoxRight | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界右侧的距离,当前值为0。| - | alphabeticBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 alphabetic 基线的距离,当前值为0。| - | emHeightAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块顶部的距离,当前值为0。| - | emHeightDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块底部的距离,当前值为0。| - | fontBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形最高边界顶部的距离,当前值为0。| - | fontBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形边界最底部的距离,当前值为0。| - | hangingBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 hanging 基线的距离,当前值为0。| - | ideographicBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 ideographic 基线的距离,当前值为0。| +| 属性 | 类型 | 描述 | +| ----- | ------ | ------- | +| width | number | 字符串的宽度。 | +| height | number | 字符串的高度。 | +| actualBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界顶部的距离,当前值为0。 | +| actualBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的矩形边界底部的距离,当前值为0。 | +| actualBoundingBoxLeft | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界左侧的距离,当前值为0。 | +| actualBoundingBoxRight | number | 平行于基线,从CanvasRenderingContext2D.textAlign 属性确定的对齐点到文本矩形边界右侧的距离,当前值为0。| +| alphabeticBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 alphabetic 基线的距离,当前值为0。| +| emHeightAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块顶部的距离,当前值为0。| +| emHeightDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框中 em 方块底部的距离,当前值为0。| +| fontBoundingBoxAscent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形最高边界顶部的距离,当前值为0。| +| fontBoundingBoxDescent | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到渲染文本的所有字体的矩形边界最底部的距离,当前值为0。| +| hangingBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 hanging 基线的距离,当前值为0。| +| ideographicBaseline | number | 从CanvasRenderingContext2D.textBaseline 属性标明的水平线到线框的 ideographic 基线的距离,当前值为0。| **示例:** @@ -1007,9 +1007,9 @@ stroke(path?: Path2D): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ---------------------------------------- | ---- | ---- | ------------ | - | path | [Path2D](ts-components-canvas-path2d.md) | 否 | null | 需要绘制的Path2D。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ---------------------------------------- | ---- | ---- | ------------ | +| path | [Path2D](ts-components-canvas-path2d.md) | 否 | null | 需要绘制的Path2D。 | **示例:** @@ -1095,10 +1095,10 @@ moveTo(x: number, y: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 说明 | - | ---- | ------ | ---- | ---- | --------- | - | x | number | 是 | 0 | 指定位置的x坐标。 | - | y | number | 是 | 0 | 指定位置的y坐标。 | +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| ---- | ------ | ---- | ---- | --------- | +| x | number | 是 | 0 | 指定位置的x坐标。 | +| y | number | 是 | 0 | 指定位置的y坐标。 | **示例:** @@ -1142,10 +1142,10 @@ lineTo(x: number, y: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | --------- | - | x | number | 是 | 0 | 指定位置的x坐标。 | - | y | number | 是 | 0 | 指定位置的y坐标。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | --------- | +| x | number | 是 | 0 | 指定位置的x坐标。 | +| y | number | 是 | 0 | 指定位置的y坐标。 | **示例:** @@ -1231,16 +1231,16 @@ createPattern(image: ImageBitmap, repetition: string | null): CanvasPattern | nu **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- | - | image | [ImageBitmap](ts-components-canvas-imagebitmap.md) | 是 | null | 图源对象,具体参考ImageBitmap对象。 | - | repetition | string | 是 | “” | 设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---------- | ---------------------------------------- | ---- | ---- | ---------------------------------------- | +| image | [ImageBitmap](ts-components-canvas-imagebitmap.md) | 是 | null | 图源对象,具体参考ImageBitmap对象。 | +| repetition | string | 是 | “” | 设置图像重复的方式,取值为:'repeat'、'repeat-x'、 'repeat-y'、'no-repeat'。 | **返回值:** - | 类型 | 说明 | - | ---------- | ---------------------------------------- | - | [CanvasPattern](#canvaspattern) | 通过指定图像和重复方式创建图片填充的模板对象。 | +| 类型 | 说明 | +| ---------- | ---------------------------------------- | +| [CanvasPattern](#canvaspattern) | 通过指定图像和重复方式创建图片填充的模板对象。 | **示例:** @@ -1284,14 +1284,14 @@ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | -------------- | - | cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 | - | cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 | - | cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 | - | cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 | - | x | number | 是 | 0 | 路径结束时的x坐标值。 | - | y | number | 是 | 0 | 路径结束时的y坐标值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | -------------- | +| cp1x | number | 是 | 0 | 第一个贝塞尔参数的x坐标值。 | +| cp1y | number | 是 | 0 | 第一个贝塞尔参数的y坐标值。 | +| cp2x | number | 是 | 0 | 第二个贝塞尔参数的x坐标值。 | +| cp2y | number | 是 | 0 | 第二个贝塞尔参数的y坐标值。 | +| x | number | 是 | 0 | 路径结束时的x坐标值。 | +| y | number | 是 | 0 | 路径结束时的y坐标值。 | **示例:** @@ -1335,12 +1335,12 @@ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | ----------- | - | cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 | - | cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 | - | x | number | 是 | 0 | 路径结束时的x坐标值。 | - | y | number | 是 | 0 | 路径结束时的y坐标值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | ----------- | +| cpx | number | 是 | 0 | 贝塞尔参数的x坐标值。 | +| cpy | number | 是 | 0 | 贝塞尔参数的y坐标值。 | +| x | number | 是 | 0 | 路径结束时的x坐标值。 | +| y | number | 是 | 0 | 路径结束时的y坐标值。 | **示例:** @@ -1384,14 +1384,14 @@ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------------- | ------- | ---- | ----- | ---------- | - | x | number | 是 | 0 | 弧线圆心的x坐标值。 | - | y | number | 是 | 0 | 弧线圆心的y坐标值。 | - | radius | number | 是 | 0 | 弧线的圆半径。 | - | startAngle | number | 是 | 0 | 弧线的起始弧度。 | - | endAngle | number | 是 | 0 | 弧线的终止弧度。 | - | counterclockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ------------- | ------- | ---- | ----- | ---------- | +| x | number | 是 | 0 | 弧线圆心的x坐标值。 | +| y | number | 是 | 0 | 弧线圆心的y坐标值。 | +| radius | number | 是 | 0 | 弧线的圆半径。 | +| startAngle | number | 是 | 0 | 弧线的起始弧度。 | +| endAngle | number | 是 | 0 | 弧线的终止弧度。 | +| counterclockwise | boolean | 否 | false | 是否逆时针绘制圆弧。 | **示例:** @@ -1434,13 +1434,13 @@ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------ | ------ | ---- | ---- | --------------- | - | x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 | - | y1 | number | 是 | 0 | 圆弧经过的第一个点的y坐标值。 | - | x2 | number | 是 | 0 | 圆弧经过的第二个点的x坐标值。 | - | y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 | - | radius | number | 是 | 0 | 圆弧的圆半径值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ------ | ------ | ---- | ---- | --------------- | +| x1 | number | 是 | 0 | 圆弧经过的第一个点的x坐标值。 | +| y1 | number | 是 | 0 | 圆弧经过的第一个点的y坐标值。 | +| x2 | number | 是 | 0 | 圆弧经过的第二个点的x坐标值。 | +| y2 | number | 是 | 0 | 圆弧经过的第二个点的y坐标值。 | +| radius | number | 是 | 0 | 圆弧的圆半径值。 | **示例:** @@ -1483,16 +1483,16 @@ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number **参数:** - | 参数 | 类型 | 必填 | 默认值 | 说明 | - | ------------- | ------- | ---- | ----- | ----------------- | - | x | number | 是 | 0 | 椭圆圆心的x轴坐标。 | - | y | number | 是 | 0 | 椭圆圆心的y轴坐标。 | - | radiusX | number | 是 | 0 | 椭圆x轴的半径长度。 | - | radiusY | number | 是 | 0 | 椭圆y轴的半径长度。 | - | rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 | - | startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 | - | endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 | - | counterclockwise | boolean | 否 | false | 是否以逆时针方向绘制椭圆。 | +| 参数 | 类型 | 必填 | 默认值 | 说明 | +| ------------- | ------- | ---- | ----- | ----------------- | +| x | number | 是 | 0 | 椭圆圆心的x轴坐标。 | +| y | number | 是 | 0 | 椭圆圆心的y轴坐标。 | +| radiusX | number | 是 | 0 | 椭圆x轴的半径长度。 | +| radiusY | number | 是 | 0 | 椭圆y轴的半径长度。 | +| rotation | number | 是 | 0 | 椭圆的旋转角度,单位为弧度。 | +| startAngle | number | 是 | 0 | 椭圆绘制的起始点角度,以弧度表示。 | +| endAngle | number | 是 | 0 | 椭圆绘制的结束点角度,以弧度表示。 | +| counterclockwise | boolean | 否 | false | 是否以逆时针方向绘制椭圆。 | **示例:** @@ -1535,12 +1535,12 @@ rect(x: number, y: number, w: number, h: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------ | ------ | ---- | ---- | ------------- | - | x | number | 是 | 0 | 指定矩形的左上角x坐标值。 | - | y | number | 是 | 0 | 指定矩形的左上角y坐标值。 | - | w | number | 是 | 0 | 指定矩形的宽度。 | - | h | number | 是 | 0 | 指定矩形的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ------ | ------ | ---- | ---- | ------------- | +| x | number | 是 | 0 | 指定矩形的左上角x坐标值。 | +| y | number | 是 | 0 | 指定矩形的左上角y坐标值。 | +| w | number | 是 | 0 | 指定矩形的宽度。 | +| h | number | 是 | 0 | 指定矩形的高度。 | **示例:** @@ -1661,9 +1661,9 @@ rotate(angle: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------ | ------ | ---- | ---- | ---------------------------------------- | - | angle | number | 是 | 0 | 设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ------ | ------ | ---- | ---- | ---------------------------------------- | +| angle | number | 是 | 0 | 设置顺时针旋转的弧度值,可以通过Math.PI / 180将角度转换为弧度值。 | **示例:** @@ -1705,10 +1705,10 @@ scale(x: number, y: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | ----------- | - | x | number | 是 | 0 | 设置水平方向的缩放值。 | - | y | number | 是 | 0 | 设置垂直方向的缩放值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | ----------- | +| x | number | 是 | 0 | 设置水平方向的缩放值。 | +| y | number | 是 | 0 | 设置垂直方向的缩放值。 | **示例:** @@ -1758,14 +1758,14 @@ transform方法对应一个变换矩阵,想对一个图形进行变化的时 **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---------- | ------ | ---- | ---- | -------- | - | a | number | 是 | 0 |scaleX: 指定水平缩放值。 | - | b | number | 是 | 0 |skewX: 指定水平倾斜值。 | - | c | number | 是 | 0 |skewY: 指定垂直倾斜值。 | - | d | number | 是 | 0 |scaleY: 指定垂直缩放值。 | - | e | number | 是 | 0 |translateX: 指定水平移动值。 | - | f | number | 是 | 0 |translateY: 指定垂直移动值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---------- | ------ | ---- | ---- | -------- | +| a | number | 是 | 0 |scaleX: 指定水平缩放值。 | +| b | number | 是 | 0 |skewX: 指定水平倾斜值。 | +| c | number | 是 | 0 |skewY: 指定垂直倾斜值。 | +| d | number | 是 | 0 |scaleY: 指定垂直缩放值。 | +| e | number | 是 | 0 |translateX: 指定水平移动值。 | +| f | number | 是 | 0 |translateY: 指定垂直移动值。 | **示例:** @@ -1813,14 +1813,14 @@ setTransfrom方法使用的参数和transform()方法相同,但setTransform() **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---------- | ------ | ---- | ---- | -------- | - | a | number | 是 | 0 |scaleX: 指定水平缩放值。 | - | b | number | 是 | 0 |skewX: 指定水平倾斜值。 | - | c | number | 是 | 0 |skewY: 指定垂直倾斜值。 | - | d | number | 是 | 0 |scaleY: 指定垂直缩放值。 | - | e | number | 是 | 0 |translateX: 指定水平移动值。 | - | f | number | 是 | 0 |translateY: 指定垂直移动值。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---------- | ------ | ---- | ---- | -------- | +| a | number | 是 | 0 |scaleX: 指定水平缩放值。 | +| b | number | 是 | 0 |skewX: 指定水平倾斜值。 | +| c | number | 是 | 0 |skewY: 指定垂直倾斜值。 | +| d | number | 是 | 0 |scaleY: 指定垂直缩放值。 | +| e | number | 是 | 0 |translateX: 指定水平移动值。 | +| f | number | 是 | 0 |translateY: 指定垂直移动值。 | **示例:** @@ -1865,10 +1865,10 @@ translate(x: number, y: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | -------- | - | x | number | 是 | 0 | 设置水平平移量。 | - | y | number | 是 | 0 | 设置竖直平移量。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | -------- | +| x | number | 是 | 0 | 设置水平平移量。 | +| y | number | 是 | 0 | 设置竖直平移量。 | **示例:** @@ -1915,17 +1915,17 @@ drawImage(image: ImageBitmap | PixelMap, sx: number, sy: number, sw: number, sh: **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------- | ---------------------------------------- | ---- | ---- | -------------------- | - | image | [ImageBitmap](ts-components-canvas-imagebitmap.md) 或[PixelMap](../apis/js-apis-image.md#pixelmap7)| 是 | null | 图片资源,请参考ImageBitmap或PixelMap。 | - | sx | number | 否 | 0 | 裁切源图像时距离源图像左上角的x坐标值。 | - | sy | number | 否 | 0 | 裁切源图像时距离源图像左上角的y坐标值。 | - | sw | number | 否 | 0 | 裁切源图像时需要裁切的宽度。 | - | sh | number | 否 | 0 | 裁切源图像时需要裁切的高度。 | - | dx | number | 是 | 0 | 绘制区域左上角在x轴的位置。 | - | dy | number | 是 | 0 | 绘制区域左上角在y 轴的位置。 | - | dw | number | 否 | 0 | 绘制区域的宽度。 | - | dh | number | 否 | 0 | 绘制区域的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ------- | ---------------------------------------- | ---- | ---- | -------------------- | +| image | [ImageBitmap](ts-components-canvas-imagebitmap.md) 或[PixelMap](../apis/js-apis-image.md#pixelmap7)| 是 | null | 图片资源,请参考ImageBitmap或PixelMap。 | +| sx | number | 否 | 0 | 裁切源图像时距离源图像左上角的x坐标值。 | +| sy | number | 否 | 0 | 裁切源图像时距离源图像左上角的y坐标值。 | +| sw | number | 否 | 0 | 裁切源图像时需要裁切的宽度。 | +| sh | number | 否 | 0 | 裁切源图像时需要裁切的高度。 | +| dx | number | 是 | 0 | 绘制区域左上角在x轴的位置。 | +| dy | number | 是 | 0 | 绘制区域左上角在y 轴的位置。 | +| dw | number | 否 | 0 | 绘制区域的宽度。 | +| dh | number | 否 | 0 | 绘制区域的高度。 | **示例:** @@ -1968,10 +1968,10 @@ createImageData(sw: number, sh: number): ImageData **参数:** - | 参数 | 类型 | 必填 | 默认 | 描述 | - | ------ | ------ | ---- | ---- | ------------- | - | sw | number | 是 | 0 | ImageData的宽度。 | - | sh | number | 是 | 0 | ImageData的高度。 | +| 参数 | 类型 | 必填 | 默认 | 描述 | +| ------ | ------ | ---- | ---- | ------------- | +| sw | number | 是 | 0 | ImageData的宽度。 | +| sh | number | 是 | 0 | ImageData的高度。 | ### createImageData @@ -1982,15 +1982,15 @@ createImageData(imageData: ImageData): ImageData **参数:** - | 参数 | 类型 | 必填 | 默认 | 描述 | - | --------- | ---------------------------------------- | ---- | ---- | ---------------- | - | imagedata | [ImageData](ts-components-canvas-imagebitmap.md) | 是 | null | 被复制的ImageData对象。 | +| 参数 | 类型 | 必填 | 默认 | 描述 | +| --------- | ---------------------------------------- | ---- | ---- | ---------------- | +| imagedata | [ImageData](ts-components-canvas-imagebitmap.md) | 是 | null | 被复制的ImageData对象。 | **返回值:** - | 类型 | 说明 | - | ---------- | ---------------------------------------- | - | [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象 | +| 类型 | 说明 | +| ---------- | ---------------------------------------- | +| [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象 | ### getPixelMap @@ -2000,18 +2000,18 @@ getPixelMap(sx: number, sy: number, sw: number, sh: number): PixelMap **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | -------- | -------- | -------- | -------- | -------- | - | sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 | - | sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 | - | sw | number | 是 | 0 | 需要输出的区域的宽度。 | - | sh | number | 是 | 0 | 需要输出的区域的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| -------- | -------- | -------- | -------- | -------- | +| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 | +| sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 | +| sw | number | 是 | 0 | 需要输出的区域的宽度。 | +| sh | number | 是 | 0 | 需要输出的区域的高度。 | **返回值:** - | 类型 | 说明 | - | ---------- | ---------------------------------------- | - | [PixelMap](../apis/js-apis-image.md#pixelmap7) | 新的PixelMap对象 | +| 类型 | 说明 | +| ---------- | ---------------------------------------- | +| [PixelMap](../apis/js-apis-image.md#pixelmap7) | 新的PixelMap对象 | ### getImageData @@ -2022,18 +2022,18 @@ getImageData(sx: number, sy: number, sw: number, sh: number): ImageData **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | --------------- | - | sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 | - | sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 | - | sw | number | 是 | 0 | 需要输出的区域的宽度。 | - | sh | number | 是 | 0 | 需要输出的区域的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | --------------- | +| sx | number | 是 | 0 | 需要输出的区域的左上角x坐标。 | +| sy | number | 是 | 0 | 需要输出的区域的左上角y坐标。 | +| sw | number | 是 | 0 | 需要输出的区域的宽度。 | +| sh | number | 是 | 0 | 需要输出的区域的高度。 | **返回值:** - | 类型 | 说明 | - | ---------- | ---------------------------------------- | - | [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象 | +| 类型 | 说明 | +| ---------- | ---------------------------------------- | +| [ImageData](ts-components-canvas-imagebitmap.md) | 新的ImageData对象 | ### putImageData @@ -2046,15 +2046,15 @@ putImageData(imageData: Object, dx: number, dy: number, dirtyX: number, dirtyY: **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ----------- | ------ | ---- | ------------ | ----------------------------- | - | imagedata | Object | 是 | null | 包含像素值的ImageData对象。 | - | dx | number | 是 | 0 | 填充区域在x轴方向的偏移量。 | - | dy | number | 是 | 0 | 填充区域在y轴方向的偏移量。 | - | dirtyX | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。 | - | dirtyY | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。 | - | dirtyWidth | number | 否 | imagedata的宽度 | 源图像数据矩形裁切范围的宽度。 | - | dirtyHeight | number | 否 | imagedata的高度 | 源图像数据矩形裁切范围的高度。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ----------- | ------ | ---- | ------------ | ----------------------------- | +| imagedata | Object | 是 | null | 包含像素值的ImageData对象。 | +| dx | number | 是 | 0 | 填充区域在x轴方向的偏移量。 | +| dy | number | 是 | 0 | 填充区域在y轴方向的偏移量。 | +| dirtyX | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的x轴偏移量。 | +| dirtyY | number | 否 | 0 | 源图像数据矩形裁切范围左上角距离源图像左上角的y轴偏移量。 | +| dirtyWidth | number | 否 | imagedata的宽度 | 源图像数据矩形裁切范围的宽度。 | +| dirtyHeight | number | 否 | imagedata的高度 | 源图像数据矩形裁切范围的高度。 | **示例:** @@ -2391,12 +2391,12 @@ createLinearGradient(x0: number, y0: number, x1: number, y1: number): void **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | -------- | - | x0 | number | 是 | 0 | 起点的x轴坐标。 | - | y0 | number | 是 | 0 | 起点的y轴坐标。 | - | x1 | number | 是 | 0 | 终点的x轴坐标。 | - | y1 | number | 是 | 0 | 终点的y轴坐标。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | -------- | +| x0 | number | 是 | 0 | 起点的x轴坐标。 | +| y0 | number | 是 | 0 | 起点的y轴坐标。 | +| x1 | number | 是 | 0 | 终点的x轴坐标。 | +| y1 | number | 是 | 0 | 终点的y轴坐标。 | **示例:** @@ -2443,14 +2443,14 @@ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, **参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | ----------------- | - | x0 | number | 是 | 0 | 起始圆的x轴坐标。 | - | y0 | number | 是 | 0 | 起始圆的y轴坐标。 | - | r0 | number | 是 | 0 | 起始圆的半径。必须是非负且有限的。 | - | x1 | number | 是 | 0 | 终点圆的x轴坐标。 | - | y1 | number | 是 | 0 | 终点圆的y轴坐标。 | - | r1 | number | 是 | 0 | 终点圆的半径。必须为非负且有限的。 | +| 参数 | 类型 | 必填 | 默认值 | 描述 | +| ---- | ------ | ---- | ---- | ----------------- | +| x0 | number | 是 | 0 | 起始圆的x轴坐标。 | +| y0 | number | 是 | 0 | 起始圆的y轴坐标。 | +| r0 | number | 是 | 0 | 起始圆的半径。必须是非负且有限的。 | +| x1 | number | 是 | 0 | 终点圆的x轴坐标。 | +| y1 | number | 是 | 0 | 终点圆的y轴坐标。 | +| r1 | number | 是 | 0 | 终点圆的半径。必须为非负且有限的。 | **示例:** diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-page-transition-animation.md b/zh-cn/application-dev/reference/arkui-ts/ts-page-transition-animation.md index 27d2a53cb1a35766dfe75d32ef2532dd91e386f5..65d1152557b7b665ba0bb56c8bf6c9db29fab3c5 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-page-transition-animation.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-page-transition-animation.md @@ -6,10 +6,10 @@ > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -| 名称 | 参数 | 参数描述 | -| ------------------- | ---------------------------------------- | ---------------------------------------- | -| PageTransitionEnter | {
type?: RouteType,
duration?: number,
curve?: Curve \| string,
delay?:number
} | 设置当前页面的自定义入场动效。
- type:不配置时表明pop为push时效果的逆播。
- duration:动画的时长,单位为毫秒。
- curve:动画曲线,有效值参见[Curve](ts-appendix-enums.md#curve) 。
 默认值:Curve.Linear
- delay:动画延迟时长,单位为毫秒,默认不延迟播放。 | -| PageTransitionExit | {
type?: RouteType,
duration?: number,
curve?: Curve \| string,
delay?: number
} | 设置当前页面的自定义退场动效。
- type:不配置时表明pop为push时效果的逆播
- duration:动画的时长,单位为毫秒。
- curve:动画曲线,有效值参见[Curve](ts-appendix-enums.md#curve) 。
 默认值:Curve.Linear
- delay:动画延迟时长,单位为毫秒,默认不延迟播放。 | +| 名称 | 参数 | 参数描述 | +| ------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| PageTransitionEnter | {
type: RouteType,
duration: number,
curve: [Curve](ts-appendix-enums.md#curve) \| string,
delay: number
} | 设置当前页面的自定义入场动效。
- type:不配置时表明pop为push时效果的逆播。
- duration:动画的时长,单位为毫秒。
- curve:动画曲线。string类型的取值支持"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"。
 默认值:Curve.Linear
- delay:动画延迟时长,单位为毫秒,默认不延迟播放。 | +| PageTransitionExit | {
type: RouteType,
duration: number,
curve: [Curve](ts-appendix-enums.md#curve) \| string,
delay: number
} | 设置当前页面的自定义退场动效。
- type:不配置时表明pop为push时效果的逆播
- duration:动画的时长,单位为毫秒。
- curve:动画曲线,string类型取值与PageTransitionEnter相同。
 默认值:Curve.Linear
- delay:动画延迟时长,单位为毫秒,默认不延迟播放。 | ## RouteType枚举说明 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md b/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md index dfdb662cfcb64833e190021263d4accc3c9fb767..2344c69cbea74ff42757f91152fc3aa9d3fc006b 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-transition-animation-shared-elements.md @@ -9,9 +9,9 @@ ## 属性 -| 名称 | 参数 | 参数描述 | -| ---------------- | ---------------------------------------- | ---------------------------------------- | -| 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)
} | 两个页面中id值相同且不为空字符串的组件即为共享元素,在页面转场时可显示共享元素转场动效。
-  id:设置组件的id。
-  duration:单位为毫秒,默认动画时长为1000毫秒。
- curve:默认曲线为Linear,有效值参见[Curve](ts-appendix-enums.md#curve) 说明。
- delay:单位为毫秒,默认不延时播放。
- motionPath:运动路径信息。
- path:设置路径。
- from:设置起始值。
- to:设置终止值。
- rotatable:是否旋转。
- zIndex:设置Z轴。
- type:动画类型。 | +| 名称 | 参数 | 参数描述 | +| ---------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| 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)
} | 两个页面中id值相同且不为空字符串的组件即为共享元素,在页面转场时可显示共享元素转场动效。
- id:设置组件的id。
- duration:单位为毫秒,默认动画时长为1000毫秒。
- curve:默认曲线为Linear,有效值参见[Curve](ts-appendix-enums.md#curve) 说明。
- delay:单位为毫秒,默认不延时播放。
- motionPath:运动路径信息。
- path:设置路径。
- from:设置起始值。
- to:设置终止值。
- rotatable:是否旋转。
- zIndex:设置Z轴。
- type:动画类型。 | ## 示例 diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-background.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-background.md index 123a5f48d8d9ba221c339b662e0b71861edd0d89..7213e77d845a93e31e123014b397b814d6b897e5 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-background.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-background.md @@ -1,22 +1,19 @@ # 背景设置 -设置组件的背景色。 +设置组件的背景样式。 > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - ## 属性 - | 名称 | 参数类型 | 描述 | | -------- | -------- | -------- | | backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | 设置组件的背景色。 | | backgroundImage | src: [ResourceStr](ts-types.md#resourcestr),
repeat?: [ImageRepeat](ts-appendix-enums.md#imagerepeat) | src:图片地址,支持网络图片资源和本地图片资源地址(不支持svg类型的图片)。
repeat:设置背景图片的重复样式,默认不重复。 | | backgroundImageSize | {
width?: [Length](ts-types.md#length),
height?: [Length](ts-types.md#length)
} \| [ImageSize](ts-appendix-enums.md#imagesize) | 设置背景图像的高度和宽度。当输入为{width: Length, height: Length}对象时,如果只设置一个属性,则第二个属性保持图片原始宽高比进行调整。默认保持原图的比例不变。
默认值:ImageSize.Auto | -| backgroundImagePosition | {
x?: [Length](ts-types.md#length),
y?: [Length](ts-types.md#length)
} \| [Alignment](ts-appendix-enums.md#alignment) | 设置背景图在组件中显示位置。
{
x: 0,
y: 0
} | - +| backgroundImagePosition | [Position](ts-types.md#position8) \| [Alignment](ts-appendix-enums.md#alignment) | 设置背景图在组件中显示位置。
默认值:
{
x: 0,
y: 0
} | ## 示例 @@ -25,6 +22,7 @@ @Entry @Component struct BackgroundExample { + build() { Column({ space: 5 }) { Text('background color').fontSize(9).width('90%').fontColor(0xCCCCCC) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md index 0f5d4793505cf5fb7d02d223ce5a421b5ef42807..badf1cfc7a9e15490b672cef05c2cc7f46cafaad 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-component-id.md @@ -4,19 +4,14 @@ id为组件的唯一标识,在整个应用内唯一。本模块提供组件标 > **说明:** > -> - 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -## 权限列表 - -无 +> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 属性 -| 名称 | 参数说明 | 默认值 | 描述 | -| ---- | ------ | ---- | ------------------ | -| id | string | '' | 组件的唯一标识,唯一性由使用者保证。 | +| 名称 | 参数说明 | 描述 | +| -----| -------- | ----------------------------- | +| id | string | 组件的唯一标识,唯一性由使用者保证。
默认值:'' | ## 接口 @@ -29,15 +24,17 @@ getInspectorByKey(id: string): string 获取指定id的组件的所有属性,不包括子组件信息。 此接口为系统接口。 -- 参数 - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ---- | ------ | ---- | ---- | ----------- | - | id | string | 是 | - | 要获取属性的组件id。 | +**参数:** + +| 参数 | 类型 | 必填 | 描述 | +| ---- | -------- | ---- | -------------| +| id | string | 是 | 要获取属性的组件id。 | -- 返回值 - | 类型 | 描述 | - | ------ | --------------- | - | string | 组件属性列表的JSON字符串。 | +**返回值:** + +| 类型 | 描述 | +| -------| -------------- | +| string | 组件属性列表的JSON字符串。 | ### getInspectorTree @@ -46,11 +43,11 @@ getInspectorTree(): string 获取组件树及组件属性。 此接口为系统接口。 -- 返回值 +**返回值:** - | 类型 | 描述 | - | ------ | ------------------- | - | string | 组件树及组件属性列表的JSON字符串。 | +| 类型 | 描述 | +| ------ | --------------------------- | +| string | 组件树及组件属性列表的JSON字符串。 | ### sendEventByKey @@ -59,17 +56,19 @@ sendEventByKey(id: string, action: number, params: string): boolean 给指定id的组件发送事件。 此接口为系统接口。 -- 参数 - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ------ | ------ | ---- | ---- | ---------------------------------------- | - | id | string | 是 | - | 要触发事件的组件的id。 | - | action | number | 是 | - | 要触发的事件类型,目前支持取值:
- 点击事件Click: 10
- 长按事件LongClick: 11。 | - | params | string | 是 | - | 事件参数,无参数传空字符串 ""。 | +**参数:** + +| 参数 | 类型 | 必填 | 描述 | +| ------ | -------| ---- | -------------------------- | +| id | string | 是 | 要触发事件的组件的id。 | +| action | number | 是 | 要触发的事件类型,目前支持取值:
- 点击事件Click: 10
- 长按事件LongClick: 11。 | +| params | string | 是 | 事件参数,无参数传空字符串 ""。 | + +**返回值:** -- 返回值 - | 类型 | 描述 | - | ------- | ------------------------------ | - | boolean | 找不到指定id的组件时返回false,其余情况返回true。 | +| 类型 | 描述 | +| -------- | --------------------------| +| boolean | 找不到指定id的组件时返回false,其余情况返回true。 | ### sendTouchEvent @@ -78,17 +77,17 @@ sendTouchEvent(event: TouchObject): boolean 发送触摸事件。 此接口为系统接口。 -- 参数 +**参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ----- | ----------- | ---- | ---- | ---------------------------------------- | - | event | TouchObject | 是 | - | 触发触摸事件的位置,event参数见[TouchEvent](ts-universal-events-touch.md#touchevent对象说明)中TouchObject的介绍。 | +| 参数 | 类型 | 必填 | 描述 | +| ----- | ----------- | ---- | ------------------------------------------------------------ | +| event | [TouchObject](ts-universal-events-touch.md#touchobject对象说明) | 是 | 触发触摸事件的位置,event参数见[TouchEvent](ts-universal-events-touch.md#touchevent对象说明)中TouchObject的介绍。 | -- 返回值 +**返回值:** - | 类型 | 描述 | - | ------- | -------------------------- | - | boolean | 事件发送失败时返回false,其余情况返回true。 | +| 类型 | 描述 | +| ------- | ---------------------------| +| boolean | 事件发送失败时返回false,其余情况返回true。 | ### sendKeyEvent @@ -97,17 +96,17 @@ sendKeyEvent(event: KeyEvent): boolean 发送按键事件。 此接口为系统接口。 -- 参数 +**参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ----- | -------- | ---- | ---- | ---------------------------------------- | - | event | KeyEvent | 是 | - | 按键事件,event参数见[KeyEvent](ts-universal-events-key.md#keyevent对象说明)介绍。 | +| 参数 | 类型 | 必填 | 描述 | +| ----- | -------- | ---- | ------------------------------------------------------------ | +| event | [KeyEvent](ts-universal-events-key.md#keyevent对象说明) | 是 | 按键事件,event参数见[KeyEvent](ts-universal-events-key.md#keyevent对象说明)介绍。 | -- 返回值 +**返回值:** - | 类型 | 描述 | - | ------- | --------------------------- | - | boolean | 事件发送失败时时返回false,其余情况返回true。 | +| 类型 | 描述 | +| ------- | ------------------------------| +| boolean | 事件发送失败时时返回false,其余情况返回true。 | ### sendMouseEvent @@ -116,17 +115,17 @@ sendMouseEvent(event: MouseEvent): boolean 发送鼠标事件。 此接口为系统接口。 -- 参数 +**参数:** - | 参数 | 类型 | 必填 | 默认值 | 描述 | - | ----- | ---------- | ---- | ---- | ---------------------------------------- | - | event | MouseEvent | 是 | - | 鼠标事件,event参数见[MouseEvent](ts-universal-mouse-key.md#mouseevent对象说明)介绍。 | +| 参数 | 类型 | 必填 | 描述 | +| ----- | ---------- | ---- | --------------------------------------- | +| event | [MouseEvent](ts-universal-mouse-key.md#mouseevent对象说明) | 是 | 鼠标事件,event参数见[MouseEvent](ts-universal-mouse-key.md#mouseevent对象说明)介绍。 | -- 返回值 +**返回值:** - | 类型 | 描述 | - | ------- | --------------------------- | - | boolean | 事件发送失败时时返回false,其余情况返回true。 | +| 类型 | 描述 | +| ------- | ---------------------------------- | +| boolean | 事件发送失败时返回false,其余情况返回true。 | ## 示例 @@ -139,6 +138,7 @@ class Utils { static rect_bottom; static rect_value; + //获取组件所占矩形区域坐标 static getComponentRect(key) { let strJson = getInspectorByKey(key); let obj = JSON.parse(strJson); @@ -178,32 +178,32 @@ struct IdExample { console.info(getInspectorTree()) this.text = "Button 'click to start' is clicked" setTimeout(() => { - sendEventByKey("longclick", 11, "") + sendEventByKey("longClick", 11, "") // 向id为"longClick"的组件发送长按事件 }, 2000) }).id('click') Button() { - Text('longclick').fontSize(25).fontWeight(FontWeight.Bold) + Text('longClick').fontSize(25).fontWeight(FontWeight.Bold) }.margin({ top: 20 }).backgroundColor('#0D9FFB') .gesture( LongPressGesture().onActionEnd(() => { console.info('long clicked') - this.text = "Button 'longclick' is longclicked" + this.text = "Button 'longClick' is longclicked" setTimeout(() => { - let rect = Utils.getComponentRect('onTouch') + let rect = Utils.getComponentRect('onTouch') // 获取id为"onTouch"组件的矩形区域坐标 let touchPoint: TouchObject = { id: 1, - x: rect.left + (rect.right - rect.left) / 2, - y: rect.top + (rect.bottom - rect.top) / 2, + x: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 + y: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 type: TouchType.Down, - screenX: rect.left + (rect.right - rect.left) / 2, - screenY: rect.left + (rect.right - rect.left) / 2, + screenX: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 + screenY: rect.left + (rect.right - rect.left) / 2, // 组件中心点y坐标 } - sendTouchEvent(touchPoint) + sendTouchEvent(touchPoint) // 发送触摸事件 touchPoint.type = TouchType.Up - sendTouchEvent(touchPoint) + sendTouchEvent(touchPoint) // 发送触摸事件 }, 2000) - })).id('longclick') + })).id('longClick') Button() { Text('onTouch').fontSize(25).fontWeight(FontWeight.Bold) @@ -212,14 +212,14 @@ struct IdExample { console.info('onTouch is clicked') this.text = "Button 'onTouch' is clicked" setTimeout(() => { - let rect = Utils.getComponentRect('onMouse') + let rect = Utils.getComponentRect('onMouse') // 获取id为"onMouse"组件的矩形区域坐标 let mouseEvent: MouseEvent = { button: MouseButton.Left, action: MouseAction.Press, - x: rect.left + (rect.right - rect.left) / 2, - y: rect.top + (rect.bottom - rect.top) / 2, - screenX: rect.left + (rect.right - rect.left) / 2, - screenY: rect.top + (rect.bottom - rect.top) / 2, + x: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 + y: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 + screenX: rect.left + (rect.right - rect.left) / 2, // 组件中心点x坐标 + screenY: rect.top + (rect.bottom - rect.top) / 2, // 组件中心点y坐标 timestamp: 1, target: { area: { @@ -237,7 +237,7 @@ struct IdExample { }, source: SourceType.Mouse } - sendMouseEvent(mouseEvent) + sendMouseEvent(mouseEvent) // 发送鼠标事件 }, 2000) }).id('onTouch') @@ -257,7 +257,7 @@ struct IdExample { metaKey: 0, timestamp: 0 } - sendKeyEvent(keyEvent) + sendKeyEvent(keyEvent) // 发送按键事件 }, 2000) }).id('onMouse') diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-flex-layout.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-flex-layout.md index e4392200aba5b7b71652061faffa46965eec73fc..6c80865dc312decd7299ce609ab8763eb6607d5a 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-flex-layout.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-flex-layout.md @@ -27,14 +27,21 @@ struct FlexExample { Column({ space: 5 }) { Text('flexBasis').fontSize(9).fontColor(0xCCCCCC).width('90%') // 基于主轴基准尺寸 - // flexBasis()值可以是'auto'(默认值)元素本来的大小 ,如果是数字则类似于.width()/.height() ,基于主轴 + // flexBasis()值可以是'auto',表示基准尺寸是元素本来的大小 ,也可以是长度设置,相当于.width()/.height() Flex() { Text('flexBasis(100)') - .flexBasis('100').height(100).lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) + .flexBasis('100') + .height(100) + .lineHeight(70) + .backgroundColor(0xF5DEB3) + .textAlign(TextAlign.Center) Text('flexBasis("auto")') - .flexBasis('auto').width('60%').height(100).lineHeight(70) - .backgroundColor(0xD2B48C).textAlign(TextAlign.Center) + .flexBasis('auto') + .width('60%') + .height(100) + .lineHeight(70) + .backgroundColor(0xD2B48C) + .textAlign(TextAlign.Center) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) Text('flexGrow').fontSize(9).fontColor(0xCCCCCC).width('90%') @@ -42,11 +49,17 @@ struct FlexExample { // flexGrow()剩余空间分配给该元素的比例 Flex() { Text('flexGrow(2)') - .flexGrow(2).height(100).lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) + .flexGrow(2) + .height(100) + .lineHeight(70) + .backgroundColor(0xF5DEB3) + .textAlign(TextAlign.Center) Text('flexGrow(1)') - .flexGrow(1).height(100).lineHeight(70) - .backgroundColor(0xD2B48C).textAlign(TextAlign.Center) + .flexGrow(1) + .height(100) + .lineHeight(70) + .backgroundColor(0xD2B48C) + .textAlign(TextAlign.Center) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) Text('flexShrink').fontSize(9).fontColor(0xCCCCCC).width('90%') @@ -54,13 +67,25 @@ struct FlexExample { // text1比例是0,其他都是默认值1,放不下时直接等比例缩放后两个,第一个不缩放 Flex({ direction: FlexDirection.Row }) { Text('flexShrink(0)') - .flexShrink(0).width('50%').height(100).lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) + .flexShrink(0) + .width('50%') + .height(100) + .lineHeight(70) + .backgroundColor(0xF5DEB3) + .textAlign(TextAlign.Center) Text('no flexShrink') - .width('40%').height(100).lineHeight(70).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) + .width('40%') + .height(100) + .lineHeight(70) + .backgroundColor(0xD2B48C) + .textAlign(TextAlign.Center) Text('flexShrink(2)') - .flexShrink(2).width('40%').height(100) .lineHeight(70) - .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) + .flexShrink(2) + .width('40%') + .height(100) + .lineHeight(70) + .backgroundColor(0xF5DEB3) + .textAlign(TextAlign.Center) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) Text('alignSelf').fontSize(9).fontColor(0xCCCCCC).width('90%') @@ -69,8 +94,12 @@ struct FlexExample { Text('no alignSelf,height:80').width('33%').height(80) .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) Text('alignSelf stretch') - .alignSelf(ItemAlign.Stretch).width('33%').height(80).lineHeight(70) - .backgroundColor(0xD2B48C).textAlign(TextAlign.Center) + .alignSelf(ItemAlign.Stretch) + .width('33%') + .height(80) + .lineHeight(70) + .backgroundColor(0xD2B48C) + .textAlign(TextAlign.Center) Text('no alignSelf,height:100').width('34%').height(100) .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-gradient-color.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-gradient-color.md index 756f1d9e0fbac50724aeecf2c8f916b939327939..0a14af72b6503b0b69acffe09f82e866c0c1e6b8 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-gradient-color.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-gradient-color.md @@ -1,22 +1,20 @@ # 颜色渐变 +设置组件的颜色渐变效果。 + > **说明:** +> > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| -------- | -------- | -------- | -------- | -| linearGradient | {
angle?: number \| string,
direction?: [GradientDirection](ts-appendix-enums.md#gradientdirection),
colors: Array<[ColorStop](ts-basic-components-gauge.md#colorstop)>,
repeating?: boolean
} | - | 线性渐变。
angle: 线性渐变的角度。
direction: 线性渐变的方向,设置angle后不生效。
colors: 为渐变的颜色描述。
repeating: 为渐变的颜色重复着色。 | -| sweepGradient | {
center: Point,
start?: number \| string,
end?: number \| string,
rotation?: number\|string,
colors: Array<[ColorStop](ts-basic-components-gauge.md#colorstop)>,
repeating?: boolean
} | - | 角度渐变。
center:为角度渐变的中心点。
start:角度渐变的起点。
end:角度渐变的终点。
rotation: 角度渐变的旋转角度。
colors: 为渐变的颜色描述。
repeating: 为渐变的颜色重复着色。 | -| radialGradient | {
center: Point,
radius: number \| string,
colors: Array<[ColorStop](ts-basic-components-gauge.md#colorstop)>,
repeating?: boolean
} | - | 径向渐变。
center:径向渐变的中心点。
radius:径向渐变的半径。
colors: 为渐变的颜色描述。
repeating: 为渐变的颜色重复着色。 | +| 名称 | 参数类型 | 描述 | +| -------------- | -------------------------------------------- | ----------------------------------- | +| linearGradient | {
angle?: number \| string,
direction?: [GradientDirection](ts-appendix-enums.md#gradientdirection),
colors: Array<[ColorStop](ts-basic-components-gauge.md#colorstop)>,
repeating?: boolean
} | 线性渐变。
- angle: 线性渐变的起始角度。0点方向顺时针旋转为正向角度。
默认值:180
- direction: 线性渐变的方向,设置angle后不生效。
默认值:GradientDirection.Bottom
- colors: 为渐变的颜色描述。
- repeating: 为渐变的颜色重复着色。
默认值:false | +| sweepGradient | {
center: Point,
start?: number \| string,
end?: number \| string,
rotation?: number\|string,
colors: Array<[ColorStop](ts-basic-components-gauge.md#colorstop)>,
repeating?: boolean
} | 角度渐变。
- center:为角度渐变的中心点,即相对于当前组件左上角的坐标。
- start:角度渐变的起点。
默认值:0
- end:角度渐变的终点。
默认值:0
- rotation: 角度渐变的旋转角度。
默认值:0
- colors: 为渐变的颜色描述。
- repeating: 为渐变的颜色重复着色。
默认值:false | +| radialGradient | {
center: Point,
radius: number \| string,
colors: Array<[ColorStop](ts-basic-components-gauge.md#colorstop)>,
repeating?: boolean
} | 径向渐变。
- center:径向渐变的中心点,即相对于当前组件左上角的坐标。
- radius:径向渐变的半径。
- colors: 为渐变的颜色描述。
- repeating: 为渐变的颜色重复着色。
默认值:false | ## 示例 @@ -34,8 +32,32 @@ struct ColorGradientExample { .height(50) .linearGradient({ angle: 90, - colors: [[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]] + colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]] + }) + Text('linearGradient Repeat').fontSize(12).width('90%').fontColor(0xCCCCCC) + Row() + .width('90%') + .height(50) + .linearGradient({ + direction: GradientDirection.Left, // 渐变方向 + repeating: true, // 渐变颜色是否重复 + colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 0.5]] // 数组末尾元素占比小于1时满足重复着色效果 }) + } + .width('100%') + .padding({ top: 5 }) + } +} +``` + +![zh-cn_image_0000001219864149](figures/gradientColor1.png) + +```ts +@Entry +@Component +struct ColorGradientExample { + build() { + Column({ space: 5 }) { Text('sweepGradient').fontSize(12).width('90%').fontColor(0xCCCCCC) Row() .width(100) @@ -44,8 +66,37 @@ struct ColorGradientExample { center: [50, 50], start: 0, end: 359, - colors: [[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]] + colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]] }) + + Text('sweepGradient Reapeat').fontSize(12).width('90%').fontColor(0xCCCCCC) + Row() + .width(100) + .height(100) + .sweepGradient({ + center: [50, 50], + start: 0, + end: 359, + rotation: 45, // 旋转角度 + repeating: true, // 渐变颜色是否重复 + colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 0.5]] // 数组末尾元素占比小于1时满足重复着色效果 + }) + } + .width('100%') + .padding({ top: 5 }) + } +} +``` + +![zh-cn_image_0000001219864149](figures/gradientColor2.png) + +```ts +// xxx.ets +@Entry +@Component +struct ColorGradientExample { + build() { + Column({ space: 5 }) { Text('radialGradient').fontSize(12).width('90%').fontColor(0xCCCCCC) Row() .width(100) @@ -53,7 +104,17 @@ struct ColorGradientExample { .radialGradient({ center: [50, 50], radius: 60, - colors:[[0xAEE1E1, 0.0], [0xD3E0DC, 0.3], [0xFCD1D1, 1.0]] + colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 1.0]] + }) + Text('radialGradient Repeat').fontSize(12).width('90%').fontColor(0xCCCCCC) + Row() + .width(100) + .height(100) + .radialGradient({ + center: [50, 50], + radius: 60, + repeating: true, + colors: [[0xff0000, 0.0], [0x0000ff, 0.3], [0xffff00, 0.5]] // 数组末尾元素占比小于1时满足重复着色效果 }) } .width('100%') @@ -62,4 +123,4 @@ struct ColorGradientExample { } ``` -![zh-cn_image_0000001219864149](figures/zh-cn_image_0000001219864149.png) +![zh-cn_image_0000001219864149](figures/gradientColor3.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-grid.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-grid.md index 6f43e1ef3d5a307b85fdedbe3668c357e79f80ca..a81f4e0390a61127903e9ca41168c6b2e8786c1a 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-grid.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-grid.md @@ -1,24 +1,20 @@ # 栅格设置 > **说明:** -> - 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -> -> - 栅格布局的列宽、列间距由距离最近的GridContainer父组件决定。使用栅格属性的组件树上至少需要有1个GridContainer容器组件。 - - -## 权限列表 - -无 +> +> - 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +> +> - 栅格布局的列宽、列间距由距离最近的GridContainer父组件决定。使用栅格属性的组件树上至少需要有1个GridContainer容器组件。 ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| -------- | -------- | -------- | -------- | -| useSizeType | {
xs?: number \| { span: number, offset: number },
sm?: number \| { span: number, offset: number },
md?: number \| { span: number, offset: number },
lg?: number \| { span: number, offset: number }
} | - | 设置在特定设备宽度类型下的占用列数和偏移列数,span: 占用列数; offset: 偏移列数。
当值为number类型时,仅设置列数, 当格式如{"span": 1, "offset": 0}时,指同时设置占用列数与偏移列数。
- xs: 指设备宽度类型为SizeType.XS时的占用列数和偏移列数。
- sm: 指设备宽度类型为SizeType.SM时的占用列数和偏移列数。
- md: 指设备宽度类型为SizeType.MD时的占用列数和偏移列数。
- lg: 指设备宽度类型为SizeType.LG时的占用列数和偏移列数。 | -| gridSpan | number | 1 | 默认占用列数,指useSizeType属性没有设置对应尺寸的列数(span)时,占用的栅格列数。
>  **说明:**
> 设置了栅格span属性,组件的宽度由栅格布局决定。 | -| gridOffset | number | 0 | 默认偏移列数,指useSizeType属性没有设置对应尺寸的偏移(offset)时, 当前组件沿着父组件Start方向,偏移的列数,也就是当前组件位于第n列。
>  **说明:**
> -配置该属性后,当前组件在父组件水平方向的布局不再跟随父组件原有的布局方式,而是沿着父组件的Start方向偏移一定位移。
> -偏移位移 = (列宽 + 间距)\* 列数。
> -设置了偏移(gridOffset)的组件之后的兄弟组件会根据该组件进行相对布局,类似相对布局。 | +| 名称 | 参数类型 | 描述 | +| ----------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| useSizeType | {
xs?: number \| { span: number, offset: number },
sm?: number \| { span: number, offset: number },
md?: number \| { span: number, offset: number },
lg?: number \| { span: number, offset: number }
} | 设置在特定设备宽度类型下的占用列数和偏移列数,span: 占用列数; offset: 偏移列数。
当值为number类型时,仅设置列数, 当格式如{"span": 1, "offset": 0}时,指同时设置占用列数与偏移列数。
- xs: 指设备宽度类型为SizeType.XS时的占用列数和偏移列数。
- sm: 指设备宽度类型为SizeType.SM时的占用列数和偏移列数。
- md: 指设备宽度类型为SizeType.MD时的占用列数和偏移列数。
- lg: 指设备宽度类型为SizeType.LG时的占用列数和偏移列数。 | +| gridSpan | number | 默认占用列数,指useSizeType属性没有设置对应尺寸的列数(span)时,占用的栅格列数。
**说明:**
设置了栅格span属性,组件的宽度由栅格布局决定。
默认值:1 | +| gridOffset | number | 默认偏移列数,指useSizeType属性没有设置对应尺寸的偏移(offset)时, 当前组件沿着父组件Start方向,偏移的列数,也就是当前组件位于第n列。
**说明:**
- 配置该属性后,当前组件在父组件水平方向的布局不再跟随父组件原有的布局方式,而是沿着父组件的Start方向偏移一定位移。
- 偏移位移 = (列宽 + 间距)\* 列数。
- 设置了偏移(gridOffset)的组件之后的兄弟组件会根据该组件进行相对布局,类似相对布局。
默认值:0 | ## 示例 @@ -28,41 +24,76 @@ @Entry @Component struct GridContainerExample1 { - build(){ - GridContainer() { - Row({}) { - Row() { - Text('Left').fontSize(25) - } - .useSizeType({ - xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 }, - md: { span: 1, offset: 0 }, lg: { span: 2, offset: 0 } - }) - .height("100%") - .backgroundColor(0x66bbb2cb) - Row() { - Text('Center').fontSize(25) + build() { + Column() { + Text('useSizeType').fontSize(15).fontColor(0xCCCCCC).width('90%') + GridContainer() { + Row({}) { + Row() { + Text('Left').fontSize(25) + } + .useSizeType({ + xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 }, + md: { span: 1, offset: 0 }, lg: { span: 2, offset: 0 } + }) + .height("100%") + .backgroundColor(0x66bbb2cb) + + Row() { + Text('Center').fontSize(25) + } + .useSizeType({ + xs: { span: 1, offset: 0 }, sm: { span: 2, offset: 1 }, + md: { span: 5, offset: 1 }, lg: { span: 7, offset: 2 } + }) + .height("100%") + .backgroundColor(0x66b6c5d1) + + Row() { + Text('Right').fontSize(25) + } + .useSizeType({ + xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 3 }, + md: { span: 2, offset: 6 }, lg: { span: 3, offset: 9 } + }) + .height("100%") + .backgroundColor(0x66bbb2cb) } - .useSizeType({ - xs: { span: 1, offset: 0 }, sm: { span: 2, offset: 1 }, - md: { span: 5, offset: 1 }, lg: { span: 7, offset: 2 } - }) - .height("100%") - .backgroundColor(0x66b6c5d1) + .height(200) + + } + .backgroundColor(0xf1f3f5) + .margin({ top: 10 }) + + // 单独设置组件的span和offset,在sm尺寸大小的设备上使用useSizeType中sm的数据实现一样的效果 + Text('gridSpan,gridOffset').fontSize(15).fontColor(0xCCCCCC).width('90%') + GridContainer() { Row() { - Text('Right').fontSize(25) - } - .useSizeType({ - xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 3 }, - md: { span: 2, offset: 6 }, lg: { span: 3, offset: 9 } - }) - .height("100%") - .backgroundColor(0x66bbb2cb) + Row() { + Text('Left').fontSize(25) + } + .gridSpan(1) + .height("100%") + .backgroundColor(0x66bbb2cb) + + Row() { + Text('Center').fontSize(25) + } + .gridSpan(2) + .gridOffset(1) + .height("100%") + .backgroundColor(0x66b6c5d1) + + Row() { + Text('Right').fontSize(25) + } + .gridSpan(1) + .gridOffset(3) + .height("100%") + .backgroundColor(0x66bbb2cb) + }.height(200) } - .height(200) } - .backgroundColor(0xf1f3f5) - .margin({ top: 10 }) } } ``` @@ -77,4 +108,8 @@ struct GridContainerExample1 { **图3** 设备宽度为LG -![zh-cn_image_0000001219982727](figures/zh-cn_image_0000001219982727.png) \ No newline at end of file +![zh-cn_image_0000001219982727](figures/zh-cn_image_0000001219982727.png) + +**图4** 单独设置gridSpan和gridOffset在特定屏幕大小下的效果与useSizeType效果一致 + +![gridSpan](figures/gridSpan.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-image-effect.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-image-effect.md index a6f839550ae1b3196f28458940a5d4be99bfb12c..3fc5257703195527dba8b5c37e8497b69fd9bb54 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-image-effect.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-image-effect.md @@ -1,5 +1,7 @@ # 图像效果 +设置组件的模糊,阴影效果以及设置图片的图像效果。 + > **说明:** > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -7,66 +9,117 @@ ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ----------------------------- | ---------------------------------------- | ------ | ---------------------------------------- | -| blur | number | - | 为当前组件添加内容模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 | -| backdropBlur | number | - | 为当前组件添加背景模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 | -| shadow | {
radius: number \| [Resource](ts-types.md#resource),
color?: Color \| string \| Resource,
offsetX?: number \| Resource,
offsetY?: number \| Resource
} | - | 为当前组件添加阴影效果,入参为模糊半径(必填)、阴影的颜色(可选,默认为灰色)、X轴的偏移量(可选,默认为0),Y轴的偏移量(可选,默认为0),偏移量单位为px。 | -| grayscale | number | 0.0 | 为当前组件添加灰度效果。值定义为灰度转换的比例,入参1.0则完全转为灰度图像,入参则0.0图像无变化,入参在0.0和1.0之间时,效果呈线性变化。(百分比) | -| brightness | number | 1.0 | 为当前组件添加高光效果,入参为高光比例,值为1时没有效果,小于1时亮度变暗,0为全黑;大于1时亮度增加,数值越大亮度越大。 | -| saturate | number | 1.0 | 为当前组件添加饱和度效果,饱和度为颜色中的含色成分和消色成分(灰)的比例,入参为1时,显示原图像,大于1时含色成分越大,饱和度越大;小于1时消色成分越大,饱和度越小。(百分比) | -| contrast | number | 1.0 | 为当前组件添加对比度效果,入参为对比度的值,值为1时,显示原图;大于1时,值越大对比度越高,图像越清晰醒目;小于1时,值越小对比度越低;当对比度为0时,图像变为全灰。(百分比) | -| invert | number | 0 | 反转输入的图像。入参为图像反转的比例。值为1时完全反转。值为0则图像无变化。(百分比) | -| colorBlend 8+ | Color | - | 为当前组件添加颜色叠加效果,入参为叠加的颜色。 | -| sepia | number | 0 | 将图像转换为深褐色。入参为图像反转的比例。值为1则完全是深褐色的,值为0图像无变化。 (百分比) | -| hueRotate | number \| string | '0deg' | 为当前组件添加色相旋转效果,入参为旋转的角度值,0deg时图像无变化。入参没有最大值,超过360deg时相当于又绕一圈,即,370deg和10deg的色相旋转效果相同。 | +| 名称 | 参数类型 | 默认值 | 描述 | +| ----------------------------- | ------------------------------------------------------------ | ------ | ------------------------------------------------------------ | +| blur | number | - | 为当前组件添加内容模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 | +| backdropBlur | number | - | 为当前组件添加背景模糊效果,入参为模糊半径,模糊半径越大越模糊,为0时不模糊。 | +| shadow | {
radius: number \| [Resource](ts-types.md#resource),
color?: [Color](ts-appendix-enums.md#color) \| string \| [Resource](ts-types.md#resource),
offsetX?: number \| [Resource](ts-types.md#resource),
offsetY?: number \| [Resource](ts-types.md#resource)
} | - | 为当前组件添加阴影效果,入参为模糊半径(必填)、阴影的颜色(可选,默认为灰色)、X轴的偏移量(可选,默认为0),Y轴的偏移量(可选,默认为0),偏移量单位为px。 | +| grayscale | number | 0.0 | 为当前组件添加灰度效果。值定义为灰度转换的比例,入参1.0则完全转为灰度图像,入参则0.0图像无变化,入参在0.0和1.0之间时,效果呈线性变化。(百分比) | +| brightness | number | 1.0 | 为当前组件添加高光效果,入参为高光比例,值为1时没有效果,小于1时亮度变暗,0为全黑;大于1时亮度增加,数值越大亮度越大。 | +| saturate | number | 1.0 | 为当前组件添加饱和度效果,饱和度为颜色中的含色成分和消色成分(灰)的比例,入参为1时,显示原图像,大于1时含色成分越大,饱和度越大;小于1时消色成分越大,饱和度越小。(百分比) | +| contrast | number | 1.0 | 为当前组件添加对比度效果,入参为对比度的值,值为1时,显示原图;大于1时,值越大对比度越高,图像越清晰醒目;小于1时,值越小对比度越低;当对比度为0时,图像变为全灰。(百分比) | +| invert | number | 0 | 反转输入的图像。入参为图像反转的比例。值为1时完全反转。值为0则图像无变化。(百分比) | +| colorBlend 8+ | [Color](ts-appendix-enums.md#color) \| string \| [Resource](ts-types.md#resource) | - | 为当前组件添加颜色叠加效果,入参为叠加的颜色。 | +| sepia | number | 0 | 将图像转换为深褐色。入参为图像反转的比例。值为1则完全是深褐色的,值为0图像无变化。 (百分比) | +| hueRotate | number \| string | '0deg' | 色相旋转效果,输入参数为旋转角度。 | ## 示例 -示例效果请以真机运行为准,当前IDE预览器不支持 - +### 示例1 +模糊属性的用法,blur内容模糊,backdropBlur背景模糊。 ```ts // xxx.ets @Entry @Component -struct ImageEffectsExample { +struct BlurEffectsExample { build() { - Column({space: 10}) { - // 对字体进行模糊 + Column({ space: 10 }) { + // 对字体进行模糊 Text('font blur').fontSize(15).fontColor(0xCCCCCC).width('90%') - Text('text').blur(3).width('90%').height(40) - .fontSize(16).backgroundColor(0xF9CF93).padding({ left: 5 }) + Flex({ alignItems: ItemAlign.Center }) { + Text('original text').margin(10) + Text('blur text') + .blur(1).margin(10) + Text('blur text') + .blur(2).margin(10) + Text('blur text') + .blur(3).margin(10) + }.width('90%').height(40) + .backgroundColor(0xF9CF93) + // 对背景进行模糊 Text('backdropBlur').fontSize(15).fontColor(0xCCCCCC).width('90%') - Text().width('90%').height(40).fontSize(16).backdropBlur(3) - .backgroundImage('/comment/bg.jpg') + Text() + .width('90%') + .height(40) + .fontSize(16) + .backdropBlur(3) + .backgroundImage('/pages/attrs/image/image.jpg') .backgroundImageSize({ width: 1200, height: 160 }) + }.width('100%').margin({ top: 5 }) + } +} +``` + +![textblur](figures/textblur.png) +### 示例2 +设置图片的效果,包括阴影,灰度,高光,饱和度,对比度,图像反转,叠色,色相旋转等。 +```ts +// xxx.ets +@Entry +@Component +struct ImageEffectsExample { + build() { + Column({ space: 10 }) { + // 添加阴影效果,图片效果不变 Text('shadow').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40) - .shadow({ radius: 10, color: Color.Gray, offsetX: 5, offsetY: 5 }) + Image($r('app.media.image')) + .width('90%') + .height(40) + .shadow({ radius: 10, color: Color.Green, offsetX: 20, offsetY: 30 }) + // 灰度效果0~1,越接近1,灰度越明显 Text('grayscale').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).grayscale(0.6) + Image($r('app.media.image')).width('90%').height(40).grayscale(0.3) + Image($r('app.media.image')).width('90%').height(40).grayscale(0.8) + // 高光效果,1为正常图片,<1变暗,>1亮度增大 Text('brightness').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).brightness(2.0) + Image($r('app.media.image')).width('90%').height(40).brightness(1.2) + // 饱和度,原图为1 Text('saturate').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).saturate(2.0) + Image($r('app.media.image')).width('90%').height(40).saturate(2.0) + Image($r('app.media.image')).width('90%').height(40).saturate(0.7) + // 对比度,1为原图,>1值越大越清晰,<1值越小越模糊 Text('contrast').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).contrast(2.0) + Image($r('app.media.image')).width('90%').height(40).contrast(2.0) + Image($r('app.media.image')).width('90%').height(40).contrast(0.8) + // 图像反转比例 Text('invert').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).invert(1) + Image($r('app.media.image')).width('90%').height(40).invert(0.2) + Image($r('app.media.image')).width('90%').height(40).invert(0.8) + + // 叠色添加 + Text('colorBlend').fontSize(15).fontColor(0xCCCCCC).width('90%') + Image($r('app.media.image')).width('90%').height(40).colorBlend(Color.Green) + Image($r('app.media.image')).width('90%').height(40).colorBlend(Color.Blue) + // 深褐色 + Text('sepia').fontSize(15).fontColor(0xCCCCCC).width('90%') + Image($r('app.media.image')).width('90%').height(40).sepia(0.8) + + // 色相旋转 Text('hueRotate').fontSize(15).fontColor(0xCCCCCC).width('90%') - Image($r('app.media.bg')).width('90%').height(40).hueRotate(90) + Image($r('app.media.image')).width('90%').height(40).hueRotate(90) }.width('100%').margin({ top: 5 }) } } ``` -image-effect \ No newline at end of file +![imageeffect](figures/imageeffect.png) + diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-layout-constraints.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-layout-constraints.md index 23a1f4329db73c2f9b262e2f56f49239d331df8c..0fb3e705c61d405b77d32d30d6ec48ac67bc1471 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-layout-constraints.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-layout-constraints.md @@ -1,21 +1,18 @@ # 布局约束 -> **说明:** -> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - +通过组件的宽高比和显示优先级约束组件显示效果。 -## 权限列表 - -无 +> **说明:** +> +> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 属性 - -| 名称 | 参数说明 | 默认值 | 描述 | -| -------- | -------- | -------- | -------- | -| aspectRatio | number | - | 指定当前组件的宽高比。 | -| displayPriority | number | - | 设置当前组件在布局容器中显示的优先级,当父容器空间不足时,低优先级的组件会被隐藏。
>  **说明:**
> 仅在Row/Column/Flex(单行)容器组件中生效。 | +| 名称 | 参数说明 | 描述 | +| --------------- | ------ | ---------------------------------------- | +| aspectRatio | number | 指定当前组件的宽高比,aspectRatio = width/height。 | +| displayPriority | number | 设置当前组件在布局容器中显示的优先级,当父容器空间不足时,低优先级的组件会被隐藏。
**说明:**
仅在Row/Column/Flex(单行)容器组件中生效。 | ## 示例 @@ -25,29 +22,32 @@ @Entry @Component struct AspectRatioExample { - private children : string[] = ['1', '2', '3', '4', '5', '6'] + private children: string[] = ['1', '2', '3', '4', '5', '6']; build() { - Column({space: 20}) { + Column({ space: 20 }) { Text('using container: row').fontSize(14).fontColor(0xCCCCCC).width('100%') - Row({space: 10}) { + Row({ space: 10 }) { ForEach(this.children, (item) => { + // 组件宽度 = 组件高度*1.5 = 90 Text(item) .backgroundColor(0xbbb2cb) .fontSize(20) .aspectRatio(1.5) .height(60) + // 组件高度 = 组件宽度/1.5 = 60/1.5 = 40 Text(item) .backgroundColor(0xbbb2cb) .fontSize(20) .aspectRatio(1.5) .width(60) - }, item=>item) + }, item => item) } - .size({width: "100%", height: 100}) + .size({ width: "100%", height: 100 }) .backgroundColor(0xd2cab3) .clip(true) + // grid子元素width/height=3/2 Text('using container: grid').fontSize(14).fontColor(0xCCCCCC).width('100%') Grid() { ForEach(this.children, (item) => { @@ -57,12 +57,12 @@ struct AspectRatioExample { .fontSize(40) .aspectRatio(1.5) } - }, item=>item) + }, item => item) } .columnsTemplate('1fr 1fr 1fr') .columnsGap(10) .rowsGap(10) - .size({width: "100%", height: 165}) + .size({ width: "100%", height: 165 }) .backgroundColor(0xd2cab3) }.padding(10) } @@ -75,40 +75,46 @@ struct AspectRatioExample { **图2** 横屏显示
![zh-cn_image_0000001174264382](figures/zh-cn_image_0000001174264382.gif) -``` +```ts class ContainerInfo { - label : string = '' - size : string = '' + label: string = ''; + size: string = ''; } class ChildInfo { - text : string = '' - priority : number = 0 + text: string = ''; + priority: number = 0; } @Entry @Component struct DisplayPriorityExample { - private container : ContainerInfo[] = [ - {label: 'Big container', size: '90%'}, - {label: 'Middle container', size: '50%'}, - {label: 'Small container', size: '30%'}] - private children : ChildInfo[] = [ - {text: '1\n(priority:2)', priority: 2}, - {text: '2\n(priority:1)', priority: 1}, - {text: '3\n(priority:3)', priority: 3}, - {text: '4\n(priority:1)', priority: 1}, - {text: '5\n(priority:2)', priority: 2}] - @State currentIndex : number = 0 + // 显示容器大小 + private container: ContainerInfo[] = [ + { label: 'Big container', size: '90%' }, + { label: 'Middle container', size: '50%' }, + { label: 'Small container', size: '30%' } + ] + private children: ChildInfo[] = [ + { text: '1\n(priority:2)', priority: 2 }, + { text: '2\n(priority:1)', priority: 1 }, + { text: '3\n(priority:3)', priority: 3 }, + { text: '4\n(priority:1)', priority: 1 }, + { text: '5\n(priority:2)', priority: 2 } + ] + @State currentIndex: number = 0; build() { - Column({space: 10}) { + Column({ space: 10 }) { + // 切换父级容器大小 Button(this.container[this.currentIndex].label).backgroundColor(0x317aff) - .onClick((event: ClickEvent) => { - this.currentIndex = (this.currentIndex + 1) % this.container.length + .onClick(() => { + this.currentIndex = (this.currentIndex + 1) % this.container.length; }) - Flex({justifyContent: FlexAlign.SpaceBetween}) { - ForEach(this.children, (item)=>{ + // 通过变量设置Flex父容器宽度 + Flex({ justifyContent: FlexAlign.SpaceBetween }) { + ForEach(this.children, (item) => { + // 使用displayPriority给子组件绑定显示优先级 Text(item.text) .width(120) .height(60) @@ -116,11 +122,11 @@ struct DisplayPriorityExample { .textAlign(TextAlign.Center) .backgroundColor(0xbbb2cb) .displayPriority(item.priority) - }, item=>item.text) + }, item => item.text) } .width(this.container[this.currentIndex].size) .backgroundColor(0xd2cab3) - }.width("100%").margin({top:50}) + }.width("100%").margin({ top: 50 }) } } diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-location.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-location.md index b3c1c170691fc31b48d5669824562275ac91a3e1..912a81a63445d0c95963190a7fc4d894346ed19c 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-location.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-location.md @@ -1,5 +1,7 @@ # 位置设置 +设置组件的对齐方式、布局方向和显示位置。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -8,25 +10,27 @@ ## 属性 -| 名称 | 参数类型 | 描述 | -| ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| align | [Alignment](ts-appendix-enums.md#alignment) | 设置元素内容的对齐方式,只有当设置的width和height大小超过元素本身内容大小时生效。
默认值:Alignment.Center | -| direction | [Direction](ts-appendix-enums.md#direction) | 设置元素水平方向的布局。
默认值:Direction.Auto | -| position | {
x: [Length](ts-types.md#length),
y: [Length](ts-types.md#length)
} | 使用绝对定位,设置元素锚点相对于父容器顶部起点的偏移位置。在布局容器中,设置该属性不影响父容器布局,仅在绘制时进行位置调整。 | -| markAnchor | {
x: [Length](ts-types.md#length),
y: [Length](ts-types.md#length)
} | 设置元素在位置定位时的锚点,以元素顶部起点作为基准点进行偏移。
默认值:
{
x: 0,
y: 1
} | -| offset | {
x: [Length](ts-types.md#length),
y: [Length](ts-types.md#length)
} | 相对布局完成位置坐标偏移量,设置该属性,不影响父容器布局,仅在绘制时进行位置调整。
默认值:
{
x: 0,
y: 1
} | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| align | [Alignment](ts-appendix-enums.md#alignment) | 设置元素内容的对齐方式,当元素的width和height大小大于元素本身内容大小时生效。
默认值:Alignment.Center | +| direction | [Direction](ts-appendix-enums.md#direction) | 设置元素水平方向的布局。
默认值:Direction.Auto | +| position | [Position](ts-types.md#position8) | 绝对定位,设置元素左上角相对于父容器左上角偏移位置。在布局容器中,设置该属性不影响父容器布局,仅在绘制时进行位置调整。 | +| markAnchor | [Position](ts-types.md#position8) | 设置元素在位置定位时的锚点,以元素左上角作为基准点进行偏移。通常配合position和offset属性使用,单独使用时,效果类似offset
默认值:
{
x: 0,
y: 0
} | +| offset | [Position](ts-types.md#position8) | 相对定位,设置元素相对于自身的偏移量。设置该属性,不影响父容器布局,仅在绘制时进行位置调整。
默认值:
{
x: 0,
y: 0
} | +| alignRules9+ | {
left?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };
right?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };
middle?: { anchor: string, align: [HorizontalAlign](ts-appendix-enums.md#horizontalalign) };
top?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) };
bottom?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) };
center?: { anchor: string, align: [VerticalAlign](ts-appendix-enums.md#verticalalign) }
} | 指定相对容器的对齐规则。
- left:设置左对齐参数。
- right:设置右对齐参数。
- middle:设置中间对齐的参数。
- top:设置顶部对齐的参数。
- bottom:设置底部对齐的参数。
- center:设置中心对齐的参数。
**说明:**
- anchor:设置作为锚点的组件的id值。
- align:设置相对于锚点组件的对齐方式。 | ## 示例 - +### 示例1 ```ts // xxx.ets @Entry @Component -struct PositionExample { +struct PositionExample1 { build() { Column() { - Column({space: 10}) { + Column({ space: 10 }) { + // 元素内容<元素宽高,设置内容在与元素内的对齐方式 Text('align').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('top start') .align(Alignment.TopStart) @@ -35,6 +39,14 @@ struct PositionExample { .fontSize(16) .backgroundColor(0xFFE4C4) + Text('Bottom end') + .align(Alignment.BottomEnd) + .height(50) + .width('90%') + .fontSize(16) + .backgroundColor(0xFFE4C4) + + // 父容器设置direction为Direction.Auto|Ltr|不设置,子元素从左到右排列 Text('direction').fontSize(9).fontColor(0xCCCCCC).width('90%') Row() { Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) @@ -43,6 +55,15 @@ struct PositionExample { Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) } .width('90%') + .direction(Direction.Auto) + // 父容器设置direction为Direction.Rtl,子元素从右到左排列 + Row() { + Text('1').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) + Text('2').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) + Text('3').height(50).width('25%').fontSize(16).backgroundColor(0xF5DEB3) + Text('4').height(50).width('25%').fontSize(16).backgroundColor(0xD2B48C) + } + .width('90%') .direction(Direction.Rtl) } } @@ -51,8 +72,9 @@ struct PositionExample { } ``` -![zh-cn_image_0000001174264368](figures/zh-cn_image_0000001174264368.gif) +![align.png](figures/align.png) +### 示例2 ```ts // xxx.ets @Entry @@ -60,44 +82,65 @@ struct PositionExample { struct PositionExample2 { build() { Column({ space: 20 }) { + // 设置子组件左上角相对于父组件左上角的偏移位置 Text('position').fontSize(12).fontColor(0xCCCCCC).width('90%') - Row({ space: 20 }) { - Text('1').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }) .fontSize(16) - Text('2 position(25, 15)') - .size({ width: '60%', height: '30' }).backgroundColor(0xbbb2cb).border({ width: 1 }) - .fontSize(16).align(Alignment.Start) - .position({ x: 25, y: 15 }) + Row() { + Text('1').size({ width: '30%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) + Text('2 position(30, 10)') + .size({ width: '60%', height: '30' }) + .backgroundColor(0xbbb2cb) + .border({ width: 1 }) + .fontSize(16) + .align(Alignment.Start) + .position({ x: 30, y: 10 }) Text('3').size({ width: '45%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) Text('4 position(50%, 70%)') - .size({ width: '50%', height: '50' }).backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16) + .size({ width: '50%', height: '50' }) + .backgroundColor(0xbbb2cb) + .border({ width: 1 }) + .fontSize(16) .position({ x: '50%', y: '70%' }) }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed }) + // 相对于起点偏移,其中x为最终定位点距离起点水平方向间距,x>0往左,反之向右。 + // y为最终定位点距离起点垂直方向间距,y>0向上,反之向下 Text('markAnchor').fontSize(12).fontColor(0xCCCCCC).width('90%') Stack({ alignContent: Alignment.TopStart }) { Row() .size({ width: '100', height: '100' }) .backgroundColor(0xdeb887) - Image($r('app.media.ic_health_heart')) + Text('text') .size({ width: 25, height: 25 }) + .backgroundColor(Color.Green) .markAnchor({ x: 25, y: 25 }) - Image($r('app.media.ic_health_heart')) + Text('text') .size({ width: 25, height: 25 }) - .markAnchor({ x: 25, y: 25 }) - .position({ x: '100%', y: '100%' }) + .backgroundColor(Color.Green) + .markAnchor({ x: -100, y: -25 }) + Text('text') + .size({ width: 25, height: 25 }) + .backgroundColor(Color.Green) + .markAnchor({ x: 25, y: -25 }) }.margin({ top: 25 }).border({ width: 1, style: BorderStyle.Dashed }) + // 相对定位,x>0向右偏移,反之向左,y>0向下偏移,反之向上 Text('offset').fontSize(12).fontColor(0xCCCCCC).width('90%') Row() { Text('1').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) - Text('2\noffset(15, 15)') - .size({ width: 120, height: '50' }).backgroundColor(0xbbb2cb).border({ width: 1 }) - .fontSize(16).align(Alignment.Start) - .offset({ x: 15, y: 15 }) + Text('2 offset(15, 30)') + .size({ width: 120, height: '50' }) + .backgroundColor(0xbbb2cb) + .border({ width: 1 }) + .fontSize(16) + .align(Alignment.Start) + .offset({ x: 15, y: 30 }) Text('3').size({ width: '15%', height: '50' }).backgroundColor(0xdeb887).border({ width: 1 }).fontSize(16) - Text('4\noffset(-10%, 20%)') - .size({ width: 150, height: '50' }) .backgroundColor(0xbbb2cb).border({ width: 1 }).fontSize(16) - .offset({ x: '-10%', y: '20%' }) + Text('4 offset(-10%, 20%)') + .size({ width: 100, height: '50' }) + .backgroundColor(0xbbb2cb) + .border({ width: 1 }) + .fontSize(16) + .offset({ x: '-5%', y: '20%' }) }.width('90%').height(100).border({ width: 1, style: BorderStyle.Dashed }) } .width('100%').margin({ top: 25 }) @@ -105,4 +148,4 @@ struct PositionExample2 { } ``` -![zh-cn_image_0000001174104392](figures/zh-cn_image_0000001174104392.gif) +![position.png](figures/position.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md index 3c65b9b1f6591b2b12571864b3ae51444c8d091c..92463eb228b273e59b141143d599d52b7bbafed5 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-menu.md @@ -1,5 +1,7 @@ # Menu控制 +为组件绑定弹出式菜单,弹出式菜单以垂直列表形式显示菜单项,可通过长按、点击或鼠标右键触发。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -8,16 +10,16 @@ ## 属性 -| 名称 | 参数类型 | 描述 | +| 名称 | 参数类型 | 描述 | | ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| bindMenu | Array8+ | content: [CustomBuilder](ts-types.md#custombuilder8)
responseType: [ResponseType](ts-appendix-enums.md#responsetype8) | 给组件绑定菜单,触发方式为长按或者右键点击,弹出菜单项需要自定义。 | +| bindMenu | Array<[MenuItem](#menuitem)> \| [CustomBuilder](ts-types.md#custombuilder8) | 给组件绑定菜单,点击后弹出菜单。弹出菜单项支持文本和自定义两种功能。 | +| bindContextMenu8+ | content: [CustomBuilder](ts-types.md#custombuilder8),
responseType: [ResponseType](ts-appendix-enums.md#responsetype8) | 给组件绑定菜单,触发方式为长按或者右键点击,弹出菜单项需要自定义。 | ## MenuItem -| 名称 | 类型 | 描述 | -| ------ | ----------------------- | ---------------------- | -| value | string | 菜单项文本。 | +| 名称 | 类型 | 描述 | +| ------ | ----------------------- | ----------- | +| value | string | 菜单项文本。 | | action | () => void | 点击菜单项的事件回调。 | @@ -30,7 +32,6 @@ @Entry @Component struct MenuExample { - build() { Column() { Text('click for Menu') @@ -61,7 +62,7 @@ struct MenuExample { ```ts // xxx.ets -import router from '@system.router' +import router from '@system.router'; @Entry @Component diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-opacity.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-opacity.md index 04cf60d25ddc9558e4c1e944b455532fe762d49c..1883fcc9579703540203e7034d6d8005fe9df258 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-opacity.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-opacity.md @@ -10,9 +10,9 @@ ## 属性 -| 名称 | 参数类型 | 描述 | -| ------- | ---------------------------------------------------- | ------------------------------------------------------------ | -| opacity | number \| [Resource](ts-types.md#resource) | 元素的不透明度,取值范围为0到1,1表示为不透明,0表示为完全透明。
默认值:1 | +| 名称 | 参数类型 | 描述 | +| ------- | ---------------------------------------- | ---------------------------------------- | +| opacity | number \| [Resource](ts-types.md#resource) | 元素的不透明度,取值范围为0到1,1表示不透明,0表示完全透明, 达到隐藏组件效果,但是在布局中占位。
**说明:**
子组件可以继承父组件的此属性。默认值:1 | ## 示例 @@ -30,6 +30,10 @@ struct OpacityExample { Text().width('90%').height(50).opacity(0.7).backgroundColor(0xAFEEEE) Text('opacity(0.4)').fontSize(9).width('90%').fontColor(0xCCCCCC) Text().width('90%').height(50).opacity(0.4).backgroundColor(0xAFEEEE) + Text('opacity(0.1)').fontSize(9).width('90%').fontColor(0xCCCCCC) + Text().width('90%').height(50).opacity(0.1).backgroundColor(0xAFEEEE) + Text('opacity(0)').fontSize(9).width('90%').fontColor(0xCCCCCC) + Text().width('90%').height(50).opacity(0).backgroundColor(0xAFEEEE) } .width('100%') .padding({ top: 5 }) @@ -37,4 +41,4 @@ struct OpacityExample { } ``` -![zh-cn_image_0000001219662647](figures/zh-cn_image_0000001219662647.gif) +![opacity.png](figures/opacity.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-overlay.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-overlay.md index bebc47e0ebffe61d08b6edf221ef4f604b595842..14fdb7f1a435f40f82029ed7f207d6ba4457de00 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-overlay.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-overlay.md @@ -1,22 +1,16 @@ # 浮层 +设置组件的遮罩文本。 + > **说明:** > -> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -## 权限列表 - -无 - +> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 属性 - -| 名称 | 参数类型 | 默认值 | 描述 | -| ------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------ | -| overlay | value: string,
options?: {
align?: [Alignment](ts-appendix-enums.md#alignment), 
offset?: {x?: number, y?: number}
} | {
align: Alignment.Center,
offset: {0, 0}
} | 在当前组件上,增加遮罩文本,布局与当前组件相同。 | - +| 名称 | 参数类型 | 默认值 | 描述 | +| -------- | -------- | -------- | -------- | +| overlay | value: string,
options?: {
align?: [Alignment](ts-appendix-enums.md#alignment), 
offset?: {x?: number, y?: number}
} | {
align: Alignment.Center,
offset: {0, 0}
} | 在当前组件上,增加遮罩文本。
value: 遮罩文本内容。
options: 文本定位,align设置文本相对于组件的方位,[offset](ts-universal-attributes-location.md)为文本基于自身左上角的偏移量。文本默认处于组件左上角。
两者都设置时效果重叠,文本相对于组件方位定位后再基于当前位置文本的左上角进行偏移。 | ## 示例 @@ -33,7 +27,10 @@ struct OverlayExample { Column() { Image($r('app.media.img')) .width(240).height(240) - .overlay("Winter is a beautiful season, especially when it snows.", { align: Alignment.Bottom, offset: { x: 0, y: -15 } }) + .overlay("Winter is a beautiful season, especially when it snows.", { + align: Alignment.Bottom, + offset: { x: 70, y: 100 } + }) }.border({ color: Color.Black, width: 2 }) }.width('100%') }.padding({ top: 20 }) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-popup.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-popup.md index ae882e08ac4b44096bf99dfcb21a15446866ac7a..307d03d2a20fae1ead2d33e88f9089e2f569e74b 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-popup.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-popup.md @@ -1,5 +1,7 @@ # Popup控制 +给组件绑定popup弹窗,并设置弹窗内容,交互逻辑和显示状态。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -8,98 +10,95 @@ ## 接口 -| 名称 | 参数类型 | 描述 | -| --------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| bindPopup | show: boolean,
popup: PopupOptions\| CustomPopupOptions8+ | 给组件绑定Popup,点击弹出弹窗。
show: 创建页面弹窗提示是否默认显示,默认值为false。
popup: 配置当前弹窗提示的参数。 | +| 名称 | 参数类型 | 描述 | +| ---------- | ------------------------------------- | --------------------------------------- | +| bindPopup | show: boolean,
popup: [PopupOptions](#popupoptions类型说明) \| [CustomPopupOptions](#custompopupoptions8类型说明)8+ | 给组件绑定Popup弹窗,设置参数show为true弹出弹框。
show: 弹窗显示状态,默认值为false,隐藏弹窗。
popup: 配置当前弹窗提示的参数。 | ## PopupOptions类型说明 -| 名称 | 类型 | 必填 | 描述 | -| --------------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| message | string | 是 | 弹窗信息内容。 | -| placementOnTop | boolean | 否 | 是否在组件上方显示,默认值为false。 | -| primaryButton | {
value: string,
action: () => void
} | 否 | 第一个按钮。
value: 弹窗里主按钮的文本。
action: 点击主按钮的回调函数。 | -| secondaryButton | {
value: string,
action: () => void
} | 否 | 第二个按钮。
value: 弹窗里辅助按钮的文本。
action: 点击辅助按钮的回调函数。 | -| onStateChange | (event:{isVisible: boolean }) => void | 否 | 弹窗状态变化事件回调,参数isVisible为弹窗当前的显示状态。 | +| 名称 | 类型 | 必填 | 描述 | +| -------------------------| ------------------------------------------------| -----| ----------------------------------------- | +| message | string | 是 | 弹窗信息内容。 | +| placementOnTop | boolean | 否 | 是否在组件上方显示,默认值为false。 | +| primaryButton | {
value: string,
action: () => void
} | 否 | 第一个按钮。
value: 弹窗里主按钮的文本。
action: 点击主按钮的回调函数。 | +| secondaryButton | {
value: string,
action: () => void
} | 否 | 第二个按钮。
value: 弹窗里辅助按钮的文本。
action: 点击辅助按钮的回调函数。 | +| onStateChange | (event: { isVisible: boolean }) => void | 否 | 弹窗状态变化事件回调,参数isVisible为弹窗当前的显示状态。 | ## CustomPopupOptions8+类型说明 -| 名称 | 类型 | 必填 | 描述 | -| ------------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| builder | [CustomBuilder](ts-types.md#custombuilder8) | 是 | 提示气泡内容的构造器。 | -| placement | [Placement](ts-appendix-enums.md#placement8) | 否 | 气泡组件优先显示的位置,当前位置显示不下时,会自动调整位置。
默认值:Placement.Bottom | -| maskColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 提示气泡遮障层的颜色。 | -| popupColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 提示气泡的颜色。 | -| enableArrow | boolean | 否 | 是否显示箭头,只有上、下方向的气泡会显示箭头。
默认值:true | -| autoCancel | boolean | 否 | 页面有操作时,是否自动关闭气泡
默认值:true | -| onStateChange | (event:{isVisible: boolean }) => void | 否 | 弹窗状态变化事件回调,参数为弹窗当前的显示状态。 | +| 名称 | 类型 | 必填 | 描述 | +| -------------------------| ------------------------- | ---- | ---------------------------------------------------- | +| builder | [CustomBuilder](ts-types.md#custombuilder8) | 是 | 提示气泡内容的构造器。 | +| placement | [Placement](ts-appendix-enums.md#placement8) | 否 | 气泡组件优先显示的位置,当前位置显示不下时,会自动调整位置。
默认值:Placement.Bottom | +| maskColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 提示气泡遮障层的颜色。 | +| popupColor | [ResourceColor](ts-types.md#resourcecolor) | 否 | 提示气泡的颜色。 | +| enableArrow | boolean | 否 | 是否显示箭头。
从API Version 9开始,如果箭头所在方位侧的气泡长度不足以显示下箭头,则会默认不显示箭头。比如:placement设置为Left,但气泡高度小于箭头的宽度(32vp),则实际不会显示箭头。
默认值:true | +| autoCancel | boolean | 否 | 页面有操作时,是否自动关闭气泡。
默认值:true | +| onStateChange | (event: { isVisible: boolean }) => void | 否 | 弹窗状态变化事件回调,参数为弹窗当前的显示状态。 | ## 示例 - ```ts // xxx.ets @Entry @Component struct PopupExample { - @State noHandlePopup: boolean = false @State handlePopup: boolean = false @State customPopup: boolean = false + // popup构造器定义弹框内容 @Builder popupBuilder() { Row({ space: 2 }) { - Image('/resource/ic_public_thumbsup.svg').width(24).height(24).margin({ left: -5 }) + Image($r("app.media.image")).width(24).height(24).margin({ left: -5 }) Text('Custom Popup').fontSize(10) - }.width(100).height(50).backgroundColor(Color.White) + }.width(100).height(50).padding(5) } build() { Flex({ direction: FlexDirection.Column }) { - Button('no handle popup') - .onClick(() => { - this.noHandlePopup = !this.noHandlePopup - }) - .bindPopup(this.noHandlePopup, { - message: 'content1 content1', - placementOnTop: false, - onStateChange: (e) => { - console.info(e.isVisible.toString()) - if (!e.isVisible) { - this.noHandlePopup = false - } - } - }) - .position({ x: 100, y: 50 }) - - Button('with handle popup') + // PopupOptions 类型设置弹框内容 + Button('PopupOptions') .onClick(() => { this.handlePopup = !this.handlePopup }) .bindPopup(this.handlePopup, { - message: 'content2 content2', + message: 'This is a popup with PopupOptions', placementOnTop: true, primaryButton: { - value: 'ok', + value: 'confirm', action: () => { this.handlePopup = !this.handlePopup - console.info('secondaryButton click') + console.info('confirm Button click') + } + }, + // 第二个按钮 + secondaryButton: { + value: 'cancel', + action: () => { + this.handlePopup = !this.handlePopup; + console.info('cancel Button click') } }, onStateChange: (e) => { console.info(e.isVisible.toString()) + if (!e.isVisible) { + this.handlePopup = false + } } }) - .position({ x: 100, y: 200 }) + .position({ x: 100, y: 50 }) + - Button('custom popup') + // CustomPopupOptions 类型设置弹框内容 + Button('CustomPopupOptions') .onClick(() => { this.customPopup = !this.customPopup }) .bindPopup(this.customPopup, { builder: this.popupBuilder, - placement: Placement.Bottom, + placement: Placement.Top, maskColor: 0x33000000, - popupColor: Color.White, + popupColor: Color.Yellow, enableArrow: true, onStateChange: (e) => { if (!e.isVisible) { @@ -107,10 +106,10 @@ struct PopupExample { } } }) - .position({ x: 100, y: 350 }) + .position({ x: 80, y: 200 }) }.width('100%').padding({ top: 5 }) } } ``` -![zh-cn_image_0000001187055946](figures/zh-cn_image_0000001187055946.gif) +![figures/popup.gif](figures/popup.gif) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-size.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-size.md index ff5c7cccc7a293ad4ae0c0856e4f63501a9c16ab..e46f3861c8fd4a4c294a5de7ee3ceb972d701df8 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-size.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-size.md @@ -1,5 +1,7 @@ # 尺寸设置 +用于设置组件的宽高、边距。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -8,15 +10,15 @@ ## 属性 -| 名称 | 参数说明 | 描述 | -| -------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| width | [Length](ts-types.md#length) | 设置组件自身的宽度,缺省时使用元素自身内容需要的宽度。 | -| height | [Length](ts-types.md#length) | 设置组件自身的高度,缺省时使用元素自身内容需要的高度。 | -| size | {
width?: [Length](ts-types.md#length),
height?: [Length](ts-types.md#length)
} | 设置高宽尺寸。 | -| padding | [Padding](ts-types.md#padding) \| [Length](ts-types.md#length) | 设置内边距属性。
参数为Length类型时,四个方向内边距同时生效。
默认值:0 | -| margin | [Margin](ts-types.md#margin) \| [Length](ts-types.md#length) | 设置外边距属性。
参数为Length类型时,四个方向外边距同时生效。
默认值:0 | -| constraintSize | {
minWidth?: [Length](ts-types.md#length),
maxWidth?: [Length](ts-types.md#length),
minHeight?: [Length](ts-types.md#length),
maxHeight?: [Length](ts-types.md#length)
} | 设置约束尺寸,组件布局时,进行尺寸范围限制。
默认值:
{
minWidth: 0,
maxWidth: Infinity,
minHeight: 0,
maxHeight: Infinity
} | -| layoutWeight | number \| string | 容器尺寸确定时,元素与兄弟节点主轴布局尺寸按照权重进行分配,忽略本身尺寸设置,表示自适应占满剩余空间。
默认值:0
**说明:**
仅在Row/Column/Flex布局中生效。 | +| 名称 | 参数说明 | 描述 | +| -------------- | ---------------------------------------- | ---------------------------------------- | +| width | [Length](ts-types.md#length) | 设置组件自身的宽度,缺省时使用元素自身内容需要的宽度。若子组件的宽大于父组件的宽,则会画出父组件的范围。 | +| height | [Length](ts-types.md#length) | 设置组件自身的高度,缺省时使用元素自身内容需要的高度。若子组件的高大于父组件的高,则会画出父组件的范围。 | +| size | {
width?: [Length](ts-types.md#length),
height?: [Length](ts-types.md#length)
} | 设置高宽尺寸。 | +| padding | [Padding](ts-types.md#padding) \| [Length](ts-types.md#length) | 设置内边距属性。
参数为Length类型时,四个方向内边距同时生效。
默认值:0
padding设置百分比时,上下左右内边距均以父容器的width作为基础值。 | +| margin | [Margin](ts-types.md#margin) \| [Length](ts-types.md#length) | 设置外边距属性。
参数为Length类型时,四个方向外边距同时生效。
默认值:0
margin设置百分比时,上下左右外边距均以父容器的width作为基础值。| +| constraintSize | {
minWidth?: [Length](ts-types.md#length),
maxWidth?: [Length](ts-types.md#length),
minHeight?: [Length](ts-types.md#length),
maxHeight?: [Length](ts-types.md#length)
} | 设置约束尺寸,组件布局时,进行尺寸范围限制。constraintSize的优先级高于Width和Height。
默认值:
{
minWidth: 0,
maxWidth: Infinity,
minHeight: 0,
maxHeight: Infinity
} | +| layoutWeight | number \| string | 父容器尺寸确定时,设置了layoutWeight属性的子元素与兄弟元素占主轴尺寸按照权重进行分配,忽略元素本身尺寸设置,表示自适应占满剩余空间。
**说明:**
仅在Row/Column/Flex布局中生效。| ## 示例 @@ -29,30 +31,41 @@ struct SizeExample { build() { Column({ space: 10 }) { Text('margin and padding:').fontSize(12).fontColor(0xCCCCCC).width('90%') - // 宽度80 ,高度80 ,内外边距20 Row() { + // 宽度80 ,高度80 ,外边距20(蓝色区域),内边距10(白色区域) Row() { - Row().size({ width: '100%', height: '100%' }).backgroundColor(0xAFEEEE) - }.width(80).height(80).padding(20).margin(20).backgroundColor(0xFDF5E6) - }.backgroundColor(0xFFA500) + Row().size({ width: '100%', height: '100%' }).backgroundColor(Color.Yellow) + } + .width(80) + .height(80) + .padding(10) + .margin(20) + .backgroundColor(Color.White) + }.backgroundColor(Color.Blue) + + Text('constraintSize').fontSize(12).fontColor(0xCCCCCC).width('90%') + Text('this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text') + .width('90%') + .constraintSize({ maxWidth: 200 }) Text('layoutWeight').fontSize(12).fontColor(0xCCCCCC).width('90%') - // 容器尺寸确定时,元素与兄弟节点主轴布局尺寸按照权重进行分配,忽略本身尺寸设置。 + // 父容器尺寸确定时,设置了layoutWeight的子元素在主轴布局尺寸按照权重进行分配,忽略本身尺寸设置。 Row() { - // 权重1 + // 权重1,占主轴剩余空间1/3 Text('layoutWeight(1)') .size({ width: '30%', height: 110 }).backgroundColor(0xFFEFD5).textAlign(TextAlign.Center) .layoutWeight(1) - // 权重0 + // 权重2,占主轴剩余空间2/3 Text('layoutWeight(2)') .size({ width: '30%', height: 110 }).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .layoutWeight(2) - // 权重默认0 + // 未设置layoutWeight属性,组件按照自身尺寸渲染 Text('no layoutWeight') .size({ width: '30%', height: 110 }).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) }.size({ width: '90%', height: 140 }).backgroundColor(0xAFEEEE) }.width('100%').margin({ top: 5 }) - }} + } +} ``` -![zh-cn_image_0000001174264384](figures/zh-cn_image_0000001174264384.gif) +![size](figures/size.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-text-style.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-text-style.md index 6179351068d82c32cd6f58538f47a704ff856fdc..4278cb3af7cb87c09196bc9d37a7ab1adfafa8df 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-text-style.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-text-style.md @@ -1,28 +1,23 @@ # 文本样式设置 -> **说明:** -> -> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - 针对包含文本元素的组件,设置文本样式。 +> **说明:** +> +> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ---------- | ------------------------ | --------------------------- | ---------------------------------------- | -| fontColor | Color | - | 设置文本颜色。 | -| fontSize | Length | - | 设置文本尺寸,Length为number类型时,使用fp单位。 | -| fontStyle | [FontStyle](ts-appendix-enums.md#fontstyle) | FontStyle.Normal | 设置文本的字体样式。 | -| fontWeight | number \|[FontWeight](ts-appendix-enums.md#fontweight) | FontWeight.FontWeightNormal | 设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。
提供常用枚举值,参考:FontWeight枚举说明。 | -| fontFamily | string | - | 设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial, sans-serif'。 | +| 名称 | 参数类型 | 描述 | +| -----------| ---------------------------------------- | ------------------------------------ | +| fontColor | [ResourceColor](ts-types.md#resourcecolor) | 设置字体颜色。 | +| fontSize | Length \| [Resource](ts-types.md#resource) | 设置字体大小,Length为number类型时,使用fp单位。字体默认大小10。 | +| fontStyle | [FontStyle](ts-appendix-enums.md#fontstyle) | 设置字体样式。
默认值:FontStyle.Normal | +| fontWeight | number \| [FontWeight](ts-appendix-enums.md#fontweight) \| string | 设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。string类型仅支持number类型取值的字符串形式,例如"400",以及"bold"、"bolder"、"lighter"、"regular"、"medium",分别对应FontWeight中相应的枚举值。
默认值:FontWeight.Normal | +| fontFamily | string \| [Resource](ts-types.md#resource) | 设置字体列表。默认字体'HarmonyOS Sans',且当前只支持这种字体。| ## 示例 @@ -35,40 +30,38 @@ struct TextStyleExample { build() { Column({ space: 5 }) { Text('default text') - - Text('text font color red') - .fontColor(Color.Red) - - Text('text font size 20') - .fontSize(20) - - Text('text font style Italic') - .fontStyle(FontStyle.Italic) - - Text('text fontWeight bold') - .fontWeight(700) - - Text('text fontFamily sans-serif') - .fontFamily('sans-serif') - - Text('red 20 Italic bold cursive text') + Divider() + + Text('text font color red').fontColor(Color.Red) + Divider() + + Text('text font default') + Text('text font size 10').fontSize(10) + Text('text font size 10fp').fontSize('10fp') + Text('text font size 20').fontSize(20) + Divider() + + Text('text font style Italic').fontStyle(FontStyle.Italic) + Divider() + + Text('text fontWeight bold').fontWeight(700) + Text('text fontWeight lighter').fontWeight(FontWeight.Lighter) + Divider() + + Text('red 20 Italic bold text') .fontColor(Color.Red) .fontSize(20) .fontStyle(FontStyle.Italic) - .fontWeight(700) - .fontFamily('cursive') - .textAlign(TextAlign.Center) - .width('90%') - - Text('Orange 18 Normal source-sans-pro text') + .fontWeight(FontWeight.Bold) + Divider() + + Text('Orange 18 Normal text') .fontColor(Color.Orange) .fontSize(18) .fontStyle(FontStyle.Normal) - .fontWeight(400) - .fontFamily('source-sans-pro,cursive,sans-serif') }.width('100%') } } ``` -![zh-cn_image_0000001219662673](figures/zh-cn_image_0000001219662673.png) +![textstyle](figures/textstyle.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-touch-target.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-touch-target.md index 700349d0a0cefe05271e1c2995ecf99dad61b2a0..ffa706268f3bd28b93edaa5944ccca29d365c4ca 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-touch-target.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-touch-target.md @@ -2,6 +2,7 @@ 适用于支持通用点击事件、通用触摸事件、通用手势处理的组件。 + > **说明:** > > 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -10,18 +11,18 @@ ## 属性 -| 名称 | 参数类型 | 描述 | -| -------------- | --------------------------------------------- | ------------------------------------------------------------ | -| responseRegion | Array<Rectangle> \| Rectangle | 设置一个或多个触摸热区,包括位置和大小。
默认值:
{
x:0,
y:0,
width:'100%',
height:'100%'
} | +| 名称 | 参数类型 | 描述 | +| -------------- | --------------------------------------------- | ----------------------------------------- | +| responseRegion | Array<[Rectangle](#rectangle对象说明)> \| [Rectangle](#rectangle对象说明) | 设置一个或多个触摸热区,包括位置和大小。
默认触摸热区为整个组件,默认值:
{
x:0,
y:0,
width:'100%',
height:'100%'
} | -### Rectangle对象说明 -| 名称 | 类型 | 必填 | 默认值 | 描述 | -| ------ | ---------------------------- | ---- | ------ | --------------------------------------------------- | -| x | [Length](ts-types.md#length) | 否 | 0vp | 触摸点相对于组件本身左边沿的X坐标。
默认值:0vp | -| y | [Length](ts-types.md#length) | 否 | 0vp | 触摸点相对于组件本身左边沿的Y坐标。
默认值:0vp | -| width | [Length](ts-types.md#length) | 否 | 100% | 触摸热区范围的宽度。
默认值:100% | -| height | [Length](ts-types.md#length) | 否 | 100% | 触摸热区范围的高度。
默认值:100% | +## Rectangle对象说明 +| 名称 | 类型 | 必填 | 描述 | +| ------ | ----------------------------- | -----| -------------------------------- | +| x | [Length](ts-types.md#length) | 否 | 触摸点相对于组件左上角的x轴坐标。
默认值:0vp | +| y | [Length](ts-types.md#length) | 否 | 触摸点相对于组件左上角的y轴坐标。
默认值:0vp | +| width | [Length](ts-types.md#length) | 否 | 触摸热区的宽度。
默认值:'100%' | +| height | [Length](ts-types.md#length) | 否 | 触摸热区的高度。
默认值:'100%' | > **说明:** > @@ -29,7 +30,7 @@ > > width和height只能设置正值百分比。width:'100%'表示热区宽度设置为该组件本身的宽度。比如组件本身宽度是100vp,那么'100%'表示热区宽度也为100vp。height:'100%'表示热区高度设置为该组件本身的高度。 > - > 百分比是相对于组件本身来度量的。 + > 百分比相对于组件自身宽高进行计算。 ## 示例 @@ -38,19 +39,38 @@ // xxx.ets @Entry @Component -struct ResponseRegionExample { +struct TouchTargetExample { + @State text: string = ""; + build() { - Column() { - Toggle({ type: ToggleType.Checkbox, isOn: true }) - .selectedColor(0x39a2db) - .backgroundColor(0xAFEEEE) - .responseRegion({ x: 1.0, y: 1.0, width: 400, height: 400 }) - .onChange((isOn: boolean) => { - console.info('Component status:' + isOn) - }) - }.width('100%').margin({ top: 5 }) + Column({ space: 20 }) { + Text("{x:0,y:0,width:'50%',height:'100%'}") + // 热区宽度为按钮的一半,点击右侧无响应 + Button("button1") + .responseRegion({ x: 0, y: 0, width: '50%', height: '100%' }) + .onClick(() => { + this.text = 'button1 clicked'; + }) + + // 热区宽度为按钮的一半,且右移一个按钮宽度,点击button2右侧左边,点击事件生效 + Text("{x:'100%',y:0,width:'50%',height:'100%'}") + Button("button2") + .responseRegion({ x: '100%', y: 0, width: '50%', height: '100%' }) + .onClick(() => { + this.text = 'button2 clicked'; + }) + // 热区大小为整个按钮,且下移一个按钮高度,点击button3下方按钮大小区域,点击事件生效 + Text("{x:0,y:'100%',width:'100%',height:'100%'}") + Button("button3") + .responseRegion({ x: 0, y: '100%', width: '100%', height: '100%' }) + .onClick(() => { + this.text = 'button3 clicked'; + }) + + Text(this.text).margin({ top: 50 }) + }.width('100%').margin({ top: 10 }) } } ``` -![zh-cn_image_0000001184400598](figures/zh-cn_image_0000001184400598.gif) +![touchtarget.gif](figures/touchtarget.gif) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-visibility.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-visibility.md index ba0cbbb206f96b16c4e65e9b031fa49547a4cc9f..7d90b701c6991739de6f2c745e356a7f6ca3c516 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-visibility.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-visibility.md @@ -1,21 +1,16 @@ # 显隐控制 +控制组件是否可见。 + > **说明:** > -> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - - -## 权限列表 - -无 - +> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 ## 属性 - -| 名称 | 参数类型 | 默认值 | 描述 | -| ---------- | ---------- | ------------------ | ------------ | -| visibility | [Visibility](ts-appendix-enums.md#visibility) | Visibility.Visible | 控制当前组件显示或隐藏。 | +| 名称 | 参数类型 | 描述 | +| ---------- | ---------------------------- | ------------------------------------------ | +| visibility | [Visibility](ts-appendix-enums.md#visibility) | 控制当前组件显示或隐藏。注意,即使组件处于隐藏状态,在页面刷新时仍存在重新创建过程,因此当对性能有严格要求时建议使用[条件渲染](../../ui/ts-rending-control-syntax-if-else.md)代替。
默认值:Visibility.Visible| ## 示例 @@ -28,20 +23,21 @@ struct VisibilityExample { build() { Column() { Column() { - Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC) - Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE) - - Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC) // 隐藏不参与占位 + Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC) Row().visibility(Visibility.None).width('90%').height(80).backgroundColor(0xAFEEEE) - Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC) // 隐藏参与占位 + Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC) Row().visibility(Visibility.Hidden).width('90%').height(80).backgroundColor(0xAFEEEE) + + // 正常显示,组件默认的显示模式 + Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC) + Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE) }.width('90%').border({ width: 1 }) }.width('100%').margin({ top: 5 }) } } ``` -![zh-cn_image_0000001174104390](figures/zh-cn_image_0000001174104390.gif) +![visibility.png](figures/visibility.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-z-order.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-z-order.md index ef1cefcaf1bf94a564bf9ff97dc8d7a1153bb523..60f6b667a8060ce86195496e469633dcf958602d 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-z-order.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-attributes-z-order.md @@ -1,21 +1,18 @@ # Z序控制 +组件的Z序,设置组件的堆叠顺序。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 属性 -| 名称 | 参数类型 | 默认值 | 描述 | -| ------ | ------ | ---- | ---------------------------- | -| zIndex | number | 0 | 同一容器中兄弟组件显示层级关系,z值越大,显示层级越高。 | +| 名称 | 参数类型 | 描述 | +| -------- | -------- | -------- | +| zIndex | number | 同一容器中兄弟组件显示层级关系。zIndex值越大,显示层级越高,即zIndex值大的组件会覆盖在zIndex值小的组件上方。 | ## 示例 @@ -28,20 +25,25 @@ struct ZIndexExample { build() { Column() { Stack() { - // stack会重叠组件, 默认后定义的在最上面 - Text('first child, zIndex(2)') - .size({width: '40%', height: '30%'}).backgroundColor(0xbbb2cb) + // stack会重叠组件, 默认后定义的在最上面,具有较高zIndex值的元素在zIndex较小的元素前面 + Text('1, zIndex(2)') + .size({ width: '40%', height: '30%' }).backgroundColor(0xbbb2cb) .zIndex(2) - // 默认值0 - Text('second child, default zIndex(0)') - .size({width: '90%', height: '80%'}).backgroundColor(0xd2cab3).align(Alignment.TopStart) - Text('third child, zIndex(1)') - .size({width: '70%', height: '50%'}).backgroundColor(0xc1cbac).align(Alignment.TopStart) + Text('2, default zIndex(1)') + .size({ width: '70%', height: '50%' }).backgroundColor(0xd2cab3).align(Alignment.TopStart) .zIndex(1) + Text('3, zIndex(0)') + .size({ width: '90%', height: '80%' }).backgroundColor(0xc1cbac).align(Alignment.TopStart) }.width('100%').height(200) }.width('100%').height(200) } } ``` +Stack容器内子组件不设置zIndex的效果 + +![nozindex.png](figures/nozindex.png) + +Stack容器子组件设置zIndex后效果 + +![zindex.png](figures/zindex.png) -![zh-cn_image_0000001174582860](figures/zh-cn_image_0000001174582860.png) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-component-area-change-event.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-component-area-change-event.md index 0bf7187ad5d6a3d2c81a3662f6487f269ab27c44..edee0fabe4bac1731669640c9c57586f93c7a2d3 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-component-area-change-event.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-component-area-change-event.md @@ -1,20 +1,17 @@ # 组件区域变化事件 +组件区域变化事件指组件显示的尺寸、位置等发生变化时触发的事件。 + > **说明:** > > 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 -## 权限列表 - -无 - - ## 事件 | 名称 | 支持冒泡 | 功能描述 | | ---------------------------------------- | ---- | ---------------------------------------- | -| onAreaChange(event: (oldValue: Area, newValue: Area) => void) | 否 | 组件区域变化时触发该回调,Area类型描述见[Area](../../ui/ts-types.md#area8)。 | +| onAreaChange(event: (oldValue: [Area](ts-types.md#area8), newValue: [Area](ts-types.md#area8)) => void) | 否 | 组件区域变化时触发该回调。 | ## 示例 @@ -25,7 +22,7 @@ @Component struct AreaExample { @State value: string = 'Text' - @State size1: string = '' + @State sizeValue: string = '' build() { Column() { @@ -36,13 +33,13 @@ struct AreaExample { }) .onAreaChange((oldValue: Area, newValue: Area) => { console.info(`Ace: on area change, oldValue is ${JSON.stringify(oldValue)} value is ${JSON.stringify(newValue)}`) - this.size1 = JSON.stringify(newValue) + this.sizeValue = JSON.stringify(newValue) }) - Text('new area is: \n' + this.size).margin({ right: 30, left: 30 }) + Text('new area is: \n' + this.sizeValue).margin({ right: 30, left: 30 }) } .width('100%').height('100%').margin({ top: 30 }) } } ``` -![zh-cn_image_0000001189634870](figures/zh-cn_image_0000001189634870.gif) +![zh-cn_image_0000001189634870](figures/zh-cn_image_0000001189634870.gif) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-click.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-click.md index 6f8902fb7626655e717ca8742fc90f2a564eeacb..33f2d964f4432eecd591abb1d4d0992328f2b0ff 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-click.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-click.md @@ -1,5 +1,7 @@ # 点击事件 +组件被点击时触发的事件。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -7,26 +9,29 @@ ## 事件 -| 名称 | 支持冒泡 | 功能描述 | -| ------------------------------------------------------------ | -------- | --------------------------------------------------- | -| onClick(event: (event?: ClickEvent) => void) | 否 | 点击动作触发该方法调用,event参数见ClickEvent介绍。 | +| 名称 | 支持冒泡 | 功能描述 | +| ---------------------------------------- | ---- | --------------------------------- | +| onClick(event: (event?: ClickEvent) => void) | 否 | 点击动作触发该回调,event返回值见ClickEvent对象说明。 | ## ClickEvent对象说明 -| 属性名称 | 类型 | 描述 | -| ---------------------- | ------------------------------------ | ------------------------------------- | -| screenX | number | 点击点相对于设备屏幕左边沿的X坐标。 | -| screenY | number | 点击点相对于设备屏幕上边沿的Y坐标。 | -| x | number | 点击点相对于被点击元素左边沿的X坐标。 | -| y | number | 点击点相对于被点击元素上边沿的Y坐标。 | -| target8+ | [EventTarget](#eventtarget8对象说明) | 被点击元素对象。 | -| timestamp8+ | number | 事件时间戳。 | -| source8+ | [SourceType](ts-gesture-settings.md) | 事件输入设备。 | +| 名称 | 类型 | 描述 | +| ------------------- | ------------------------------------ | -------------------------------------------------------- | +| screenX | number | 点击位置相对于应用窗口左上角的X坐标。 | +| screenY | number | 点击位置相对于应用窗口左上角的Y坐标。 | +| x | number | 点击位置相对于被点击元素左上角的X坐标。 | +| y | number | 点击位置相对于被点击元素左上角的Y坐标。 | +| timestamp8+ | number | 事件时间戳。触发事件时距离系统启动的时间间隔,单位纳秒。 | +| target8+ | [EventTarget](#eventtarget8对象说明) | 触发事件的元素对象显示区域。 | +| source8+ | [SourceType](ts-gesture-settings.md#sourcetype枚举说明) | 事件输入设备。 | ## EventTarget8+对象说明 -| 名称 | 参数类型 | 描述 | -| ---- | ------------------ | ---------- | + +| 名称 | 参数类型 | 描述 | +| ---- | ------------------------- | ---------- | | area | [Area](ts-types.md#area8) | 目标元素的区域信息。 | + + ## 示例 ```ts @@ -38,15 +43,25 @@ struct ClickExample { build() { Column() { - Button('Click').backgroundColor(0x2788D9).width(100).height(40) - .onClick((event: ClickEvent) => { - console.info(this.text = 'Click Point:' + '\n screenX:' + event.screenX + '\n screenY:' + event.screenY - + '\n x:' + event.x + '\n y:' + event.y + '\ntarget:' + '\n component globalPos:(' - + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\n width:' - + event.target.area.width + '\n height:' + event.target.area.height) - }) - Text(this.text).padding(15) - }.height(350).width('100%').padding(10) + Row({ space: 20 }) { + Button('Click').width(100).height(40) + .onClick((event: ClickEvent) => { + this.text = 'Click Point:' + '\n screenX:' + event.screenX + '\n screenY:' + event.screenY + + '\n x:' + event.x + '\n y:' + event.y + '\ntarget:' + '\n component globalPos:(' + + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\n width:' + + event.target.area.width + '\n height:' + event.target.area.height + '\ntimestamp' + event.timestamp; + }) + Button('Click').width(200).height(50) + .onClick((event: ClickEvent) => { + this.text = 'Click Point:' + '\n screenX:' + event.screenX + '\n screenY:' + event.screenY + + '\n x:' + event.x + '\n y:' + event.y + '\ntarget:' + '\n component globalPos:(' + + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\n width:' + + event.target.area.width + '\n height:' + event.target.area.height + '\ntimestamp' + event.timestamp; + }) + }.margin(20) + + Text(this.text).margin(15) + }.width('100%') } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md index e7f6060a1a23dbcfa81e7d076e0dce9073236118..b6db6abeddf38be59ed681c901e5a5c0991527eb 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md @@ -1,5 +1,7 @@ # 拖拽事件 +拖拽事件指组件被长按后拖拽时触发的事件。 + > **说明:** > > 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -8,30 +10,31 @@ | 名称 | 支持冒泡 | 功能描述 | | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ | -| onDragStart(event: (event: DragEvent, extraParams?: string) =>  [CustomBuilder](ts-types.md#custombuilder8)) \| DragItemInfo | 否 | 第一次拖拽此事件绑定的组件时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见extraParam类型描述。
返回值:当前跟手效果所拖拽的对象,用于显示拖拽时的提示组件。
长按150毫秒(ms)可触发拖拽事件。优先级:长按手势配置时间小于等于150毫秒(ms)时,长按手势优先触发,否则拖拽事件优先触发。 | -| onDragEnter(event: (event: DragEvent, extraParams?: string) => void) | 否 | 拖拽进入组件范围内时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见extraParam类型描述。
当监听了onDrop事件时,此事件才有效。 | -| onDragMove(event: (event: DragEvent, extraParams?: string) => void) | 否 | 拖拽在组件范围内移动时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见extraParam类型描述。
当监听了onDrop事件时,此事件才有效。 | -| onDragLeave(event: (event: DragEvent, extraParams?: string) => void) | 否 | 拖拽离开组件范围内时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见extraParam类型描述。
当监听了onDrop事件时,此事件才有效。 | -| onDrop(event: (event: DragEvent, extraParams?: string) => void) | 否 | 绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见extraParam类型描述。 | +| onDragStart(event: (event: [DragEvent](#dragevent说明), extraParams?: string) =>  [CustomBuilder](ts-types.md#custombuilder8)) \| [DragItemInfo](#dragiteminfo说明) | 否 | 第一次拖拽此事件绑定的组件时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见[extraParams](#extraparams说明)说明。
返回值:当前跟手效果所拖拽的对象,用于显示拖拽时的提示组件。
长按150ms可触发拖拽事件。优先级:长按手势配置时间小于等于150ms时,长按手势优先触发,否则拖拽事件优先触发。 | +| onDragEnter(event: (event: [DragEvent](#dragevent说明), extraParams?: string) => void) | 否 | 拖拽进入组件范围内时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见[extraParams](#extraparams说明)说明。
当监听了onDrop事件时,此事件才有效。 | +| onDragMove(event: (event: [DragEvent](#dragevent说明), extraParams?: string) => void) | 否 | 拖拽在组件范围内移动时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见[extraParams](#extraparams说明)说明。
当监听了onDrop事件时,此事件才有效。 | +| onDragLeave(event: (event: [DragEvent](#dragevent说明), extraParams?: string) => void) | 否 | 拖拽离开组件范围内时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见[extraParams](#extraparams说明)说明。
当监听了onDrop事件时,此事件才有效。 | +| onDrop(event: (event: [DragEvent](#dragevent说明), extraParams?: string) => void) | 否 | 绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发回调。
- event:拖拽事件信息,包括拖拽点坐标。
- extraParams:拖拽事件额外信息,详见[extraParams](#extraparams说明)说明。 | ## DragItemInfo说明 - | 属性名称 | 属性类型 | 必填 | 描述 | - | ------------- | ------ | ------- |--------------------------------- | - | pixelMap | [PixelMap](../apis/js-apis-image.md#pixelmap7) | 否 | 设置拖拽过程中显示的图片。 | - | builder | [CustomBuilder](../../ui/ts-types.md#custombuilder8) | 否 | 使用自定义生成器进行绘图,如果设置了pixelMap,则忽略此值。 | - | extraInfo | string | 否 | 拖拽项的描述。 | +| 属性名称 | 属性类型 | 必填 | 描述 | +| ------------- | ------ | ------- |--------------------------------- | +| pixelMap | [PixelMap](../apis/js-apis-image.md#pixelmap7) | 否 | 设置拖拽过程中显示的图片。 | +| builder | [CustomBuilder](ts-types.md#custombuilder8) | 否 | 拖拽过程中显示自定义组件,如果设置了pixelMap,则忽略此值。 | +| extraInfo | string | 否 | 拖拽项的描述。 | + +## extraParams说明
+用于返回组件在拖拽中需要用到的额外信息。 +extraParams是Json对象转换的string字符串,可以通过Json.parse转换的Json对象获取如下属性。 -## extraParam说明
- 用于返回组件在拖拽中需要用到的额外信息。 - extraParam是Json对象转换的string字符串,可以通过Json.parse转换的Json对象获取如下属性。 - | 属性名称 | 属性类型 | 描述 | - | ------------- | ------ | ---------------------------------------- | - | selectedIndex | number | 当拖拽事件设在父容器的子元素时,selectedIndex表示当前被拖拽子元素是父容器第selectedIndex个子元素,selectedIndex从0开始。
仅在ListItem组件中生效。 | - | insertIndex | number | 当前拖拽元素在List组件中放下时,insertIndex表示被拖拽元素插入该组件的第insertIndex个位置,insertIndex从0开始。
仅在List组件的拖拽事件中生效。 | +| 名称 | 类型 | 描述 | +| ------------- | ------ | ------------------------------------------------------------ | +| selectedIndex | number | 当拖拽事件设在父容器的子元素时,selectedIndex表示当前被拖拽子元素是父容器第selectedIndex个子元素,selectedIndex从0开始。
仅在ListItem组件的拖拽事件中生效。 | +| insertIndex | number | 当前拖拽元素在List组件中放下时,insertIndex表示被拖拽元素插入该组件的第insertIndex个位置,insertIndex从0开始。
仅在List组件的拖拽事件中生效。 | -### DragEvent对象说明 -| 名称 | 返回值类型 | 功能描述 | -| ------ | ------ | ---------------- | +### DragEvent说明 +| 名称 | 类型 | 功能描述 | +| ------ | ------ | ----------------------------- | | getX() | number | 当前拖拽点x轴坐标,单位为vp。 | | getY() | number | 当前拖拽点y轴坐标,单位为vp。 | @@ -42,103 +45,117 @@ @Entry @Component struct DragExample { - @State numbers: string[] = ['one', 'two', 'three', 'four', 'five', 'six'] - @State text: string = '' - @State bool: boolean = false - @State bool1: boolean = false - @State size: string = '' - @State appleVisible: Visibility = Visibility.Visible - @State orangeVisible: Visibility = Visibility.Visible - @State bananaVisible: Visibility = Visibility.Visible - @State select: number = 0 - @State currentIndex: number = 0 + @State numbers: string[] = ['one', 'two', 'three', 'four', 'five', 'six']; + @State text: string = ''; + @State bool: boolean = false; + @State appleVisible: Visibility = Visibility.Visible; + @State orangeVisible: Visibility = Visibility.Visible; + @State bananaVisible: Visibility = Visibility.Visible; + // 自定义拖拽过程中显示的内容 @Builder pixelMapBuilder() { Column() { Text(this.text) - .width('50%').height(60).fontSize(16).borderRadius(10) - .textAlign(TextAlign.Center).backgroundColor(Color.Yellow) + .width('50%') + .height(60) + .fontSize(16) + .borderRadius(10) + .textAlign(TextAlign.Center) + .backgroundColor(Color.Yellow) } } build() { Column() { Text('There are three Text elements here') - .fontSize(12).fontColor(0xCCCCCC).width('90%') - .textAlign(TextAlign.Start).margin(5) - Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceAround }) { - Text('apple').width('25%').height(35).fontSize(16) - .textAlign(TextAlign.Center).backgroundColor(0xAFEEEE) + .fontSize(12) + .fontColor(0xCCCCCC) + .width('90%') + .textAlign(TextAlign.Start) + .margin(5) + Row({ space: 15 }) { + Text('apple') + .width('25%') + .height(35) + .fontSize(16) + .textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) .visibility(this.appleVisible) .onDragStart(() => { - this.bool = true - this.text = 'apple' - this.appleVisible = Visibility.Hidden - return this.pixelMapBuilder + this.bool = true; + this.text = 'apple'; + this.appleVisible = Visibility.None; + return this.pixelMapBuilder; }) - Text('orange').width('25%').height(35).fontSize(16) - .textAlign(TextAlign.Center).backgroundColor(0xAFEEEE) + Text('orange') + .width('25%') + .height(35) + .fontSize(16) + .textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) .visibility(this.orangeVisible) .onDragStart(() => { - this.bool = true - this.text = 'orange' - this.orangeVisible = Visibility.Hidden - return this.pixelMapBuilder + this.bool = true; + this.text = 'orange'; + this.orangeVisible = Visibility.None; + return this.pixelMapBuilder; }) - Text('banana').width('25%').height(35).fontSize(16) - .textAlign(TextAlign.Center).backgroundColor(0xAFEEEE) + Text('banana') + .width('25%') + .height(35) + .fontSize(16) + .textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) .visibility(this.bananaVisible) .onDragStart((event: DragEvent, extraParams: string) => { - console.log('Text onDragStarts, ' + extraParams) - this.bool = true - this.text = 'banana' - this.bananaVisible = Visibility.Hidden - return this.pixelMapBuilder + console.log('Text onDragStart, ' + extraParams + 'X:' + event.getX() + 'Y:' + event.getY()); + this.bool = true; + this.text = 'banana'; + this.bananaVisible = Visibility.None; + return this.pixelMapBuilder; }) - }.border({ width: 1 }).width('90%').padding({ top: 10, bottom: 10 }).margin(10) + }.padding({ top: 10, bottom: 10 }).margin(10) - Text('This is a List element').fontSize(12) - .fontColor(0xCCCCCC).width('90%') - .textAlign(TextAlign.Start).margin(15) - List({ space: 20, initialIndex: 0 }) { + Text('This is a List element') + .fontSize(12) + .fontColor(0xCCCCCC) + .width('90%') + .textAlign(TextAlign.Start) + .margin(15) + List({ space: 20 }) { ForEach(this.numbers, (item) => { ListItem() { - Text('' + item) - .width('100%').height(80).fontSize(16).borderRadius(10) - .textAlign(TextAlign.Center).backgroundColor(0xAFEEEE) + Text(item) + .width('100%') + .height(80) + .fontSize(16) + .borderRadius(10) + .textAlign(TextAlign.Center) + .backgroundColor(0xAFEEEE) } - .onDragStart((event: DragEvent, extraParams: string) => { - console.log('ListItem onDragStarts, ' + extraParams) - var jsonString = JSON.parse(extraParams) - this.bool1 = true - this.text = this.numbers[jsonString.selectedIndex] - this.select = jsonString.selectedIndex - return this.pixelMapBuilder - }) }, item => item) } .editMode(true) - .height('50%').width('90%').border({ width: 1 }) + .height('50%') + .width('90%') + .border({ width: 1 }) + .padding(15) .divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) .onDragEnter((event: DragEvent, extraParams: string) => { - console.log('List onDragEnter, ' + extraParams) + console.log('List onDragEnter, ' + extraParams + 'X:' + event.getX() + 'Y:' + event.getY()); }) .onDragMove((event: DragEvent, extraParams: string) => { - console.log('List onDragMove, ' + extraParams) + console.log('List onDragMove, ' + extraParams + 'X:' + event.getX() + 'Y:' + event.getY()); }) .onDragLeave((event: DragEvent, extraParams: string) => { - console.log('List onDragLeave, ' + extraParams) + console.log('List onDragLeave, ' + extraParams + 'X:' + event.getX() + 'Y:' + event.getY()); }) .onDrop((event: DragEvent, extraParams: string) => { - var jsonString = JSON.parse(extraParams) + var jsonString = JSON.parse(extraParams); if (this.bool) { - this.numbers.splice(jsonString.insertIndex, 0, this.text) - this.bool = false - } else if (this.bool1) { - this.numbers.splice(jsonString.selectedIndex, 1) - this.numbers.splice(jsonString.insertIndex, 0, this.text) - this.bool = false - this.bool1 = false + // 通过splice方法插入元素 + this.numbers.splice(jsonString.insertIndex, 0, this.text); + this.bool = false; } }) }.width('100%').height('100%').padding({ top: 20 }).margin({ top: 20 }) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md index 40ac6e8504339c3674300800aacff8fa67c8ba9b..bf71309377b8079ea14d752692976cf5c743fdea 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-key.md @@ -1,36 +1,30 @@ # 按键事件 -按键事件指组件与键盘、遥控器等按键设备交互时触发的事件。 +按键事件指组件与键盘、遥控器等按键设备交互时触发的事件,适用于所有可获焦组件,例如Button。对于Text,Image等默认不可获焦的组件,可以设置focusable属性为true后使用按键事件。 > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 - -## 权限列表 - -无 - - ## 事件 -| 名称 | 支持冒泡 | 功能描述 | -| ---------------------------------------- | ---- | ---------------------------------------- | -| onKeyEvent(event: (event?: KeyEvent) => void) | 是 | 绑定该方法的组件获焦后,按键动作触发该方法调用,event参数见[KeyEvent](#keyevent对象说明)介绍。 | +| 名称 | 支持冒泡 | 功能描述 | +| ------------------------------------------------------------ | -------- | ------------------------------------------------------------ | +| onKeyEvent(event: (event?: KeyEvent) => void) | 是 | 绑定该方法的组件获焦后,按键动作触发该方法调用,event返回值见[KeyEvent](#keyevent对象说明)介绍。 | ## KeyEvent对象说明 - | 名称 | 类型 | 描述 | - | ------------------------------------- | --------------------------- | -------------------------- | - | type | [KeyType](ts-appendix-enums.md#keytype) | 按键的类型。 | - | keyCode | number | 按键的键码。 | - | keyText | string | 按键的键值。 | - | keySource | [KeySource](ts-appendix-enums.md#keysource) | 触发当前按键的输入设备类型。 | - | deviceId | number | 触发当前按键的输入设备ID。 | - | metaKey | number | 按键发生时元键的状态,1表示按压态,0表示未按压态。 | - | timestamp | number | 按键发生时的时间戳。 | - | stopPropagation | () => void | 阻塞事件冒泡传递。 | +| 名称 | 类型 | 描述 | +| --------------- | ------------------------------------------- | ------------------------------------------------------------ | +| type | [KeyType](ts-appendix-enums.md#keytype) | 按键的类型。 | +| keyCode | number | 按键的键码。 | +| keyText | string | 按键的键值。 | +| keySource | [KeySource](ts-appendix-enums.md#keysource) | 触发当前按键的输入设备类型。 | +| deviceId | number | 触发当前按键的输入设备ID。 | +| metaKey | number | 按键发生时元键(即Windows键盘的WIN键、Mac键盘的Command键)的状态,1表示按压态,0表示未按压态。 | +| timestamp | number | 按键发生时的时间戳。 | +| stopPropagation | () => void | 阻塞事件冒泡传递。 | ## 示例 @@ -39,6 +33,28 @@ // xxx.ets @Entry @Component +struct KeyEventExample { + @State text: string = ''; + @State eventType: string = ''; + + build() { + Column() { + Button('KeyEvent') + .onKeyEvent((event: KeyEvent) => { + if (event.type === KeyType.Down) { + this.eventType = 'Down'; + } + if (event.type === KeyType.Up) { + this.eventType = 'Up'; + } + this.text = 'KeyType:' + this.eventType + '\nkeyCode:' + event.keyCode + '\nkeyText:' + event.keyText; + }) + Text(this.text).padding(15) + }.height(300).width('100%').padding(35) + } +}// xxx.ets +@Entry +@Component struct KeyEventExample { @State text: string = '' @State eventType: string = '' @@ -61,4 +77,4 @@ struct KeyEventExample { } ``` -![zh-cn_image_0000001174264364](figures/zh-cn_image_0000001174264364.gif) +![zh-cn_image_0000001174264364](figures/zh-cn_image_0000001174264364.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-show-hide.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-show-hide.md index d24ad3483e12f365489cef5580dc4dbea6a18e87..f775977ef3b14e1e4f5270c3a5800732b0f826d9 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-show-hide.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-show-hide.md @@ -17,30 +17,36 @@ ```ts // xxx.ets -import prompt from '@system.prompt' +import prompt from '@ohos.prompt'; @Entry @Component struct AppearExample { - @State isShow: boolean = true - private myText: string = 'Text for onAppear' - private changeAppear: string = 'Hide Text' + @State isShow: boolean = true; + @State changeAppear: string = 'Hide Text'; + private myText: string = 'Text for onAppear'; build() { Column() { Button(this.changeAppear) .onClick(() => { - this.isShow = !this.isShow - }).margin(3).backgroundColor(0x2788D9) + this.isShow = !this.isShow; + }).margin(15) if (this.isShow) { - Text(this.myText) + Text(this.myText).fontSize(26).fontWeight(FontWeight.Bold) .onAppear(() => { - this.changeAppear = 'Show Text' - prompt.showToast({ message: 'The text is shown', duration: 2000 }) + this.changeAppear = 'Hide Text'; + prompt.showToast({ + message: 'The text is shown', + duration: 2000 + }) }) .onDisAppear(() => { - this.changeAppear = 'Hide Text' - prompt.showToast({ message: 'The text is hidden', duration: 2000 }) + this.changeAppear = 'Show Text'; + prompt.showToast({ + message: 'The text is hidden', + duration: 2000 + }) }) } }.padding(30).width('100%') diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md index 9f94105c21c5eee879c1ce401df723112bfe6086..59633ade2ee5e9ac1a3fa97d3a8342db75f71f44 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-touch.md @@ -1,5 +1,7 @@ # 触摸事件 +当手指在组件上按下、滑动、抬起时触发。 + > **说明:** > > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -9,32 +11,32 @@ | 名称 | 是否冒泡 | 功能描述 | | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ | -| onTouch(event: (event?: TouchEvent) => void) | 是 | 触摸动作触发该方法调用,event参数见[TouchEvent](#touchevent对象说明)介绍。 | +| onTouch(event: (event?: TouchEvent) => void) | 是 | 触摸动作触发该方法调用,event返回值见[TouchEvent](#touchevent对象说明)介绍。 | ## TouchEvent对象说明 - | 名称 | 类型 | 描述 | - | ------------------- | ---------------------------------------- | ------------ | - | type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 | - | touches | Array<[TouchObject](#touchobject对象说明)> | 全部手指信息。 | - | changedTouches | Array<[TouchObject](#touchobject对象说明)> | 当前发生变化的手指信息。 | - | stopPropagation | () => void | 阻塞事件冒泡。 | - | timestamp8+ | number | 事件时间戳。 | - | target8+ | [EventTarget](ts-universal-events-click.md) | 触发手势事件的元素对象显示区域。 | - | source8+ | [SourceType](ts-gesture-settings.md) | 事件输入设备。 | +| 名称 | 类型 | 描述 | +| ------------------- | ---------------------------------------- | ------------ | +| type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 | +| touches | Array<[TouchObject](#touchobject对象说明)> | 全部手指信息。 | +| changedTouches | Array<[TouchObject](#touchobject对象说明)> | 当前发生变化的手指信息。 | +| stopPropagation | () => void | 阻塞事件冒泡。 | +| timestamp8+ | number | 事件时间戳。触发事件时距离系统启动的时间间隔,单位纳秒。 | +| target8+ | [EventTarget](ts-universal-events-click.md\#eventtarget8对象说明) | 触发事件的元素对象显示区域。 | +| source8+ | [SourceType](ts-gesture-settings.md\#sourcetype枚举说明) | 事件输入设备。 | ## TouchObject对象说明 -| 名称 | 类型 | 描述 | -| ------- | --------------------------- | ------------------- | -| type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 | -| id | number | 手指唯一标识符。 | -| screenX | number | 触摸点相对于设备屏幕左边沿的X坐标。 | -| screenY | number | 触摸点相对于设备屏幕上边沿的Y坐标。 | -| x | number | 触摸点相对于被触摸元素左边沿的X坐标。 | -| y | number | 触摸点相对于被触摸元素上边沿的Y坐标。 | +| 名称 | 类型 | 描述 | +| ------- | ------------------------------------------- | ------------------------------------- | +| type | [TouchType](ts-appendix-enums.md#touchtype) | 触摸事件的类型。 | +| id | number | 手指唯一标识符。 | +| screenX | number | 触摸点相对于应用窗口左上角的X坐标。 | +| screenY | number | 触摸点相对于应用窗口左上角的Y坐标。 | +| x | number | 触摸点相对于被触摸元素左边沿的X坐标。 | +| y | number | 触摸点相对于被触摸元素上边沿的Y坐标。 | ## 示例 @@ -43,29 +45,45 @@ @Entry @Component struct TouchExample { - @State text: string = '' - @State eventType: string = '' + @State text: string = ''; + @State eventType: string = ''; build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { - Button('Touch').backgroundColor(0x2788D9).height(40).width(80) + Column() { + Button('Touch').height(40).width(100) + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.eventType = 'Down'; + } + if (event.type === TouchType.Up) { + this.eventType = 'Up'; + } + if (event.type === TouchType.Move) { + this.eventType = 'Move'; + } + this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' + + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\nComponent globalPos:(' + + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:' + + event.target.area.width + '\nheight:' + event.target.area.height; + }) + Button('Touch').height(50).width(200).margin(20) .onTouch((event: TouchEvent) => { if (event.type === TouchType.Down) { - this.eventType = 'Down' + this.eventType = 'Down'; } if (event.type === TouchType.Up) { - this.eventType = 'Up' + this.eventType = 'Up'; } if (event.type === TouchType.Move) { - this.eventType = 'Move' + this.eventType = 'Move'; } - console.info(this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' - + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:(' + this.text = 'TouchType:' + this.eventType + '\nDistance between touch point and touch element:\nx: ' + + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\nComponent globalPos:(' + event.target.area.globalPosition.x + ',' + event.target.area.globalPosition.y + ')\nwidth:' - + event.target.area.width + '\nheight:' + event.target.area.height) + + event.target.area.width + '\nheight:' + event.target.area.height; }) Text(this.text) - }.height(200).width(350).padding({ left: 35, right: 35, top: 35 }) + }.width('100%').padding(30) } } ``` diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-focus-event.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-focus-event.md index 89f94afe40060dbd6185556ad1ad780d478b19e4..7f5257857009963d2b191a42798a67edcff94ab3 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-focus-event.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-focus-event.md @@ -1,8 +1,12 @@ # 焦点事件 +焦点事件指页面焦点在可获焦组件间移动时触发的事件,组件可使用焦点事件来处理相关逻辑。 + > **说明:** > -> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +> - 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 +> +> - 目前仅支持通过外接键盘的tab键、方向键触发。 ## 事件 @@ -12,9 +16,6 @@ | onFocus(event: () => void) | 否 | 当前组件获取焦点时触发的回调。 | | onBlur(event:() => void) | 否 | 当前组件失去焦点时触发的回调。 | -> **说明:** -> 支持焦点事件的组件:Button、Text、Image、List、Grid。 - ## 示例 @@ -23,44 +24,52 @@ @Entry @Component struct FocusEventExample { - @State textOne: string = '' - @State textTwo: string = '' - @State textThree: string = '' - @State oneButtonColor: string = '#FF0000' - @State twoButtonColor: string = '#87CEFA' - @State threeButtonColor: string = '#90EE90' + @State oneButtonColor: string = '#FFC0CB'; + @State twoButtonColor: string = '#87CEFA'; + @State threeButtonColor: string = '#90EE90'; build() { - Column({ space:20 }){ - Button(this.textOne) + Column({ space: 20 }) { + // 通过外接键盘的上下键可以让焦点在三个按钮间移动,按钮获焦时颜色变化,失焦时变回原背景色 + Button('First Button') .backgroundColor(this.oneButtonColor) - .width(260).height(70).fontColor(Color.Black) + .width(260) + .height(70) + .fontColor(Color.Black) .focusable(true) .onFocus(() => { - this.textOne = 'First Button onFocus' - this.oneButtonColor = '#AFEEEE' + this.oneButtonColor = '#FF0000'; }) .onBlur(() => { - this.textOne = 'First Button onBlur' - this.oneButtonColor = '#FFC0CB' + this.oneButtonColor = '#FFC0CB'; }) - Button(this.textTwo) + Button('Second Button') .backgroundColor(this.twoButtonColor) - .width(260).height(70).fontColor(Color.Black) + .width(260) + .height(70) + .fontColor(Color.Black) .focusable(true) - Button(this.textThree) + .onFocus(() => { + this.twoButtonColor = '#FF0000'; + }) + .onBlur(() => { + this.twoButtonColor = '#87CEFA'; + }) + Button('Third Button') .backgroundColor(this.threeButtonColor) - .width(260).height(70).fontColor(Color.Black) + .width(260) + .height(70) + .fontColor(Color.Black) .focusable(true) .onFocus(() => { - this.textThree = 'Third Button onFocus' - this.threeButtonColor = '#AFEEEE' + this.threeButtonColor = '#FF0000'; }) .onBlur(() => { - this.textThree = 'Third Button onBlur' - this.threeButtonColor = '#FFC0CB' + this.threeButtonColor = '#90EE90'; }) - }.width('100%').margin({ top:20 }) + }.width('100%').margin({ top: 20 }) } } ``` + +![focus](figures/focus.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md index 2264ace64b057a1b55edc3d52c4e84d8a28d0fa6..dcc36e95fe8c362dc8389367a057abd9f2634095 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-mouse-key.md @@ -1,5 +1,7 @@ # 鼠标事件 +在鼠标的单个动作触发多个事件时,事件的顺序是固定的,鼠标事件默认透传。 + > **说明:** > > 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 @@ -10,23 +12,23 @@ | 名称 | 支持冒泡 | 描述 | | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ | | onHover(event: (isHover: boolean) => void) | 否 | 鼠标进入或退出组件时触发该回调。
isHover:表示鼠标是否悬浮在组件上,鼠标进入时为true, 退出时为false。 | -| onMouse(event: (event?: MouseEvent) => void) | 是 | 当前组件被鼠标按键点击时或者鼠标在组件上移动时,触发该回调,event参数包含触发事件时的时间戳、鼠标按键、动作、点击触点在整个屏幕上的坐标和点击触点相对于当前组件的坐标。 | +| onMouse(event: (event?: MouseEvent) => void) | 是 | 当前组件被鼠标按键点击时或者鼠标在组件上悬浮移动时,触发该回调,event返回值包含触发事件时的时间戳、鼠标按键、动作、鼠标位置在整个屏幕上的坐标和相对于当前组件的坐标。 | ## MouseEvent对象说明 | 名称 | 属性类型 | 描述 | | --------- | ------------------------------- | -------------------- | -| screenX | number | 点击触点相对于屏幕左上角的x轴坐标。 | -| screenY | number | 点击触点相对于屏幕左上角的y轴坐标。 | -| x | number | 点击触点相对于当前组件左上角的x轴坐标。 | -| y | number | 点击触点相对于当前组件左上角的y轴坐标。 | +| screenX | number | 鼠标位置相对于应用窗口左上角的x轴坐标。 | +| screenY | number | 鼠标位置相对于应用窗口左上角的y轴坐标。 | +| x | number | 鼠标位置相对于当前组件左上角的x轴坐标。 | +| y | number | 鼠标位置相对于当前组件左上角的y轴坐标。 | | button | [MouseButton](ts-appendix-enums.md#mousebutton) | 鼠标按键。 | -| action | [MouseAction](ts-appendix-enums.md#mouseaction) | 事件动作。 | +| action | [MouseAction](ts-appendix-enums.md#mouseaction) | 鼠标动作。 | | stopPropagation | () => void | 阻塞事件冒泡。 | -| timestamp8+ | number | 事件时间戳。 | -| target8+ | [EventTarget](ts-universal-events-click.md) | 触发手势事件的元素对象显示区域。 | -| source8+ | [SourceType](ts-gesture-settings.md) | 事件输入设备。 | +| timestamp8+ | number | 事件时间戳。触发事件时距离系统启动的时间间隔,单位纳秒。 | +| target8+ | [EventTarget](ts-universal-events-click.md\#eventtarget8对象说明) | 触发手势事件的元素对象显示区域。 | +| source8+ | [SourceType](ts-gesture-settings.md\#sourcetype枚举说明) | 事件输入设备。 | ## 示例 @@ -35,31 +37,80 @@ @Entry @Component struct MouseEventExample { - @State hoverText: string = 'no hover' - @State mouseText: string = 'MouseText' - @State color: Color = Color.Blue + @State hoverText: string = 'no hover'; + @State mouseText: string = ''; + @State action: string = ''; + @State mouseBtn: string = ''; + @State color: Color = Color.Blue; build() { - Column({ space:20 }) { + Column({ space: 20 }) { Button(this.hoverText) + .width(180).height(80) + .backgroundColor(this.color) .onHover((isHover: boolean) => { + // 通过onHover事件动态修改按钮在是否有鼠标悬浮时的文本内容与背景颜色 if (isHover) { - this.hoverText = 'on hover' - this.color = Color.Pink + this.hoverText = 'hover'; + this.color = Color.Pink; } else { - this.hoverText = 'no hover' - this.color = Color.Blue + this.hoverText = 'no hover'; + this.color = Color.Blue; } }) - .backgroundColor(this.color) Button('onMouse') + .width(180).height(80) .onMouse((event: MouseEvent) => { - console.log(this.mouseText = 'onMouse:\nButton = ' + event.button + - '\nAction = ' + event.action + '\nlocalXY=(' + event.x + ',' + event.y + ')' + - '\nscreenXY=(' + event.screenX + ',' + event.screenY + ')') + switch (event.button) { + case MouseButton.None: + this.mouseBtn = 'None'; + break; + case MouseButton.Left: + this.mouseBtn = 'Left'; + break; + case MouseButton.Right: + this.mouseBtn = 'Right'; + break; + case MouseButton.Back: + this.mouseBtn = 'Back'; + break; + case MouseButton.Forward: + this.mouseBtn = 'Forward'; + break; + case MouseButton.Middle: + this.mouseBtn = 'Middle'; + break; + } + switch (event.action) { + case MouseAction.Hover: + this.action = 'Hover'; + break; + case MouseAction.Press: + this.action = 'Press'; + break; + case MouseAction.Move: + this.action = 'Move'; + break; + case MouseAction.Release: + this.action = 'Release'; + break; + } + this.mouseText = 'onMouse:\nButton = ' + this.mouseBtn + + '\nAction = ' + this.action + '\nXY=(' + event.x + ',' + event.y + ')' + + '\nscreenXY=(' + event.screenX + ',' + event.screenY + ')'; }) Text(this.mouseText) - }.padding({ top: 20 }).width('100%') + }.padding({ top: 30 }).width('100%') } } ``` + +示意图: + +鼠标悬浮时改变文本内容与背景颜色: + +![focus](figures/mouse.png) + +鼠标点击时: + +![mouse1](figures/mouse1.png) \ No newline at end of file diff --git a/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-gradient.md b/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-gradient.md index 66c7d73703a3ed5afdb4cffe5ab27bd49e8db131..8f778ea25765381fdd7803aa846e17787366ea82 100644 --- a/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-gradient.md +++ b/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-gradient.md @@ -61,7 +61,7 @@ background: repeating-linear-gradient(direction/angle, color, color, ...); ```css /* 45度夹角,从红色渐变到绿色 */ - background: linear-gradient(45deg, rgb(255,0,0),rgb(0, 255, 0)); + background: linear-gradient(45deg, rgb(255, 0, 0),rgb(0, 255, 0)); ``` ![222](figures/222.PNG) @@ -70,7 +70,7 @@ background: repeating-linear-gradient(direction/angle, color, color, ...); ```css /* 从左向右渐变,在距离左边90px和距离左边360px (600*0.6) 之间270px宽度形成渐变 */ - background: linear-gradient(to right, rgb(255,0,0) 90px, rgb(0, 255, 0) 60%); + background: linear-gradient(to right, rgb(255, 0, 0) 90px, rgb(0, 255, 0) 60%); ``` @@ -82,4 +82,5 @@ background: repeating-linear-gradient(direction/angle, color, color, ...); /* 从左向右重复渐变,重复渐变区域30px(60-30)透明度0.5 */ background: repeating-linear-gradient(to right, rgba(255, 255, 0, 1) 30px,rgba(0, 0, 255, .5) 60px); ``` + ![444](figures/444.PNG) diff --git a/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-mediaquery.md b/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-mediaquery.md index 6fa60061f6d0f4f29a2ecf1180b9b65ec94cdabc..1caa03daece18dc5ad40254438e1618572e58717 100644 --- a/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-mediaquery.md +++ b/zh-cn/application-dev/reference/js-service-widget-ui/js-service-widget-common-mediaquery.md @@ -69,7 +69,7 @@ | 类型 | 说明 | | -------- | -------- | -| and | 将多个媒体特征(Media Feature)以“与”的方式连接成一个媒体查询,只有当所有媒体特征都为true,查询条件成立。另外,它还可以将媒体类型和媒体功能结合起来。
例如:screen and (device-type: wearable) and (max-height: 600) 表示当设备类型是智能穿戴同时应用的最大高度小于等于600个像素单位时成立。 | +| and | 将多个媒体特征(Media Feature)以逻辑运算符“与”的方式连接成一个媒体查询,只有当所有媒体特征都为true,查询条件成立。另外,它还可以将媒体类型和媒体功能结合起来。
例如:screen and (device-type: wearable) and (max-height: 600) 表示当设备类型是智能穿戴同时应用的最大高度小于等于600个像素单位时成立。 | | not | 取反媒体查询结果,媒体查询结果不成立时返回true,否则返回false。在媒体查询列表中应用not,则not仅取反应用它的媒体查询。
例如:not screen and (min-height: 50) and (max-height: 600) 表示当应用高度小于50个像素单位或者大于600个像素单位时成立。
使用not运算符时必须指定媒体类型。 | | only | 当整个表达式都匹配时,才会应用选择的样式,可以应用在防止某些较早的版本的浏览器上产生歧义的场景。一些较早版本的浏览器对于同时包含了媒体类型和媒体特征的语句会产生歧义,比如:
screen and (min-height: 50)
老版本浏览器会将这句话理解成screen,从而导致仅仅匹配到媒体类型(screen),就应用了指定样式,使用only可以很好地规避这种情况。
使用only时必须指定媒体类型。 | | ,(comma) | 将多个媒体特征以“或”的方式连接成一个媒体查询,如果存在结果为true的媒体特征,则查询条件成立。其效果等同于or运算符。
例如:screen and (min-height: 1000),  (round-screen:true) 表示当应用高度大于等于1000个像素单位或者设备屏幕是圆形时,条件成立。 | diff --git a/zh-cn/application-dev/security/huks-overview.md b/zh-cn/application-dev/security/huks-overview.md index 7acab188684b7ccc323caeec4b282590a949409b..2d0ae259739a53e391c49d69c0a5ad116621cb76 100755 --- a/zh-cn/application-dev/security/huks-overview.md +++ b/zh-cn/application-dev/security/huks-overview.md @@ -16,9 +16,9 @@ HUKS对密钥的使用主要通过Init、Update、Finish操作来实现。 - **Init操作**:读取密钥,并为其创建Session Id返回给调用者。 -- **Udate操作**:根据Init操作获取的Session Id对数据进行分段update处理。 +- **Update操作**:根据Init操作获取的Session Id对数据进行分段update处理。 -- **Fnish操作**:当所有待处理的数据均传入HUKS后,调用Finish操作完成最终数据处理,释放资源。 +- **Finish操作**:当所有待处理的数据均传入HUKS后,调用Finish操作完成最终数据处理,释放资源。 >![](../public_sys-resources/icon-notice.gif) **须知:当Init、Update、Finish操作中的任一阶段发生错误时,都需要调用Abort操作来终止密钥的使用。** diff --git a/zh-cn/application-dev/ui/Readme-CN.md b/zh-cn/application-dev/ui/Readme-CN.md index 435fd6777edb98f96ab1502e28d4eeafe59ff9eb..e795869f2f2143a1726ca501a797a34b68efada5 100755 --- a/zh-cn/application-dev/ui/Readme-CN.md +++ b/zh-cn/application-dev/ui/Readme-CN.md @@ -7,7 +7,6 @@ - 文件组织 - [目录结构](ts-framework-directory.md) - [应用代码文件访问规则](ts-framework-file-access-rules.md) - - [js标签配置](ts-framework-js-tag.md) - 资源管理 - [资源文件的分类](ui-ts-basic-resource-file-categories.md) - [资源访问](ts-resource-access.md) diff --git a/zh-cn/application-dev/ui/arkui-overview.md b/zh-cn/application-dev/ui/arkui-overview.md index 08e119eb28eaddd337a300875e53cefd6efdee3a..98c48b818b54420b3c838491f73fe5c56a92f9fa 100644 --- a/zh-cn/application-dev/ui/arkui-overview.md +++ b/zh-cn/application-dev/ui/arkui-overview.md @@ -14,7 +14,7 @@ ## 主要特征 -- UI组件:方舟开发框架不仅提供了多种基础组件,如文本显示、图片显示、按键交互等,也提供了支持视频播放能力的媒体组件。并且针对不同类型设备进行了组件设计,提供了组件在不同平台上的样式适配能力,此种组件称为“多态组件”。 +- UI组件:方舟开发框架不仅提供了多种基础组件, 例如文本、图片、按钮等 ,也提供了支持视频播放能力的媒体组件。并且针对不同类型设备进行了组件设计,提供了组件在不同平台上的样式适配能力,此种组件称为“多态组件”。 - 布局:UI界面设计离不开布局的参与。方舟开发框架提供了多种布局方式,不仅保留了经典的弹性布局能力,也提供了列表、宫格、栅格布局和适应多分辨率场景开发的原子布局能力。 diff --git a/zh-cn/application-dev/ui/figures/custom-dialog-demo.gif b/zh-cn/application-dev/ui/figures/custom-dialog-demo.gif new file mode 100644 index 0000000000000000000000000000000000000000..8d0979823e13f959b2a4828f479af7bbc03f69f3 Binary files /dev/null and b/zh-cn/application-dev/ui/figures/custom-dialog-demo.gif differ diff --git a/zh-cn/application-dev/ui/figures/zh-cn_image_0000001118642023.gif b/zh-cn/application-dev/ui/figures/zh-cn_image_0000001118642023.gif new file mode 100644 index 0000000000000000000000000000000000000000..c584f3fddad26c473453a573a12f6aa869d2cdbc Binary files /dev/null and b/zh-cn/application-dev/ui/figures/zh-cn_image_0000001118642023.gif differ diff --git a/zh-cn/application-dev/ui/figures/zh-cn_image_0000001118642600.PNG b/zh-cn/application-dev/ui/figures/zh-cn_image_0000001118642600.PNG new file mode 100644 index 0000000000000000000000000000000000000000..60236b7109ffd1345eba17443d154824a79159b8 Binary files /dev/null and b/zh-cn/application-dev/ui/figures/zh-cn_image_0000001118642600.PNG differ diff --git a/zh-cn/application-dev/ui/js-framework-syntax-css.md b/zh-cn/application-dev/ui/js-framework-syntax-css.md index 9da60fc817b3e830b6159545cfde4b80b6362b4a..e5378697c7d2957ce75470ca962fdd6400f6f93a 100644 --- a/zh-cn/application-dev/ui/js-framework-syntax-css.md +++ b/zh-cn/application-dev/ui/js-framework-syntax-css.md @@ -1,6 +1,6 @@ # CSS语法参考 -CSS是描述HML页面结构的样式语言。所有组件均存在系统默认样式,也可在页面CSS样式文件中对组件、页面自定义不同的样式。请参考[通用样式](../reference/arkui-js/js-components-common-styles.md)了解基于JS扩展的类Web开发范式支持的组件样式。 +CSS是描述HML页面结构的样式语言。所有组件均存在系统默认样式,也可在页面CSS样式文件中对组件、页面自定义不同的样式。请参考[通用样式](../reference/arkui-js/js-components-common-styles.md)了解兼容JS的类Web开发范式支持的组件样式。 ## 尺寸单位 diff --git a/zh-cn/application-dev/ui/js-framework-syntax-js.md b/zh-cn/application-dev/ui/js-framework-syntax-js.md index 9aac5acd159d34fd1fa19ca2370155b71da2b8f5..5eb1398708ea343b181a8a9abbe741996af64577 100644 --- a/zh-cn/application-dev/ui/js-framework-syntax-js.md +++ b/zh-cn/application-dev/ui/js-framework-syntax-js.md @@ -164,8 +164,8 @@ JS文件用来定义HML页面的业务逻辑,支持ECMA规范的JavaScript语 images: [ { src: '/common/frame1.png' }, { src: '/common/frame2.png' }, - { src: '/common/frame3.png' }, - ], + { src: '/common/frame3.png' } + ] }, handleClick() { const animator = this.$refs.animator; // 获取ref属性为animator的DOM元素 @@ -196,8 +196,8 @@ JS文件用来定义HML页面的业务逻辑,支持ECMA规范的JavaScript语 images: [ { src: '/common/frame1.png' }, { src: '/common/frame2.png' }, - { src: '/common/frame3.png' }, - ], + { src: '/common/frame3.png' } + ] }, handleClick() { const animator = this.$element('animator'); // 获取id属性为animator的DOM元素 diff --git a/zh-cn/application-dev/ui/ts-component-based-customdialog.md b/zh-cn/application-dev/ui/ts-component-based-customdialog.md index 72b8c9cb6b64b2e410caff9dc3934d6cc171c4aa..523343054067927cdc8e7d1361e02c90332caeec 100644 --- a/zh-cn/application-dev/ui/ts-component-based-customdialog.md +++ b/zh-cn/application-dev/ui/ts-component-based-customdialog.md @@ -47,3 +47,5 @@ struct CustomDialogUser { } } ``` + + ![custom-dialog-demo](figures/custom-dialog-demo.gif) \ No newline at end of file diff --git a/zh-cn/application-dev/ui/ts-component-creation-re-initialization.md b/zh-cn/application-dev/ui/ts-component-creation-re-initialization.md index 1786a365cb4098141f02e8a0f9c2a79993abd91b..f45dd97155727e4159eddafb8da752c8e073b469 100644 --- a/zh-cn/application-dev/ui/ts-component-creation-re-initialization.md +++ b/zh-cn/application-dev/ui/ts-component-creation-re-initialization.md @@ -55,10 +55,10 @@ struct ParentComp { Column() { Text(this.isCountDown ? 'Count Down' : 'Stopwatch') if (this.isCountDown) { - Image('countdown.png') + Image($r("app.media.countdown")).width(200).height(200) TimerComponent({counter: 10, changePerSec: -1, showInColor: Color.Red}) } else { - Image('stopwatch.png') + Image($r("app.media.stopwatch")).width(200).height(200) TimerComponent({counter: 0, changePerSec: +1, showInColor: Color.Black }) } Button(this.isCountDown ? 'Switch to Stopwatch' : 'Switch to Count Down') @@ -92,3 +92,5 @@ struct TimerComponent { } } ``` + + ![](figures/zh-cn_image_0000001118642023.gif) \ No newline at end of file diff --git a/zh-cn/application-dev/ui/ts-framework-directory.md b/zh-cn/application-dev/ui/ts-framework-directory.md index 8c434f805a6a7f384ea20f2314014d2a0e53ad32..c7c0b7caa48a54b8c523902dbd6fb9aaed254d91 100644 --- a/zh-cn/application-dev/ui/ts-framework-directory.md +++ b/zh-cn/application-dev/ui/ts-framework-directory.md @@ -29,3 +29,12 @@ FA应用的eTS模块(entry/src/main)的典型开发目录结构如下: > - 资源目录resources文件夹位于src/main下,此目录下资源文件的详细规范以及子目录结构规范参看[资源文件的分类](ui-ts-basic-resource-file-categories.md)。 > > - 页面支持导入TypeScript和JavaScript文件。 + +**js标签配置:** + + 开发框架需要在配置文件中标识相关的js标签,其中的每个元素代表一个JS模块的信息,包含了实例名称、页面路由、视图窗口等。 + + +> **说明:** +> +> FA模型请参考 [表22 js对象的内部结构说明](../quick-start/package-structure.md#module对象的内部结构)。 \ No newline at end of file diff --git a/zh-cn/application-dev/ui/ts-framework-file-access-rules.md b/zh-cn/application-dev/ui/ts-framework-file-access-rules.md index b132dc619ce4271d1cb31e1b95173dc481650c93..a643804f19e9ee415ab663169999946bcafaf672 100644 --- a/zh-cn/application-dev/ui/ts-framework-file-access-rules.md +++ b/zh-cn/application-dev/ui/ts-framework-file-access-rules.md @@ -1,17 +1,14 @@ -# 应用代码文件访问规则 +# 文件访问规则 +应用代码中文件访问方法主要有下面两种: -应用代码文件可通过如下方式访问: +- **相对路径**:使用相对路径引用代码文件,以"../"访问上一级目录,以"./"访问当前目录,也可以省略不写。 +- **绝对路径**:使用当前模块根路径引用代码文件,比如:common/utils/utils。 -- 使用相对路径引用代码文件,比如:上一级目录:../common/utils/utils,当前目录:./common/utils/utils。 -- 使用当前模块根路径引用代码文件,比如:common/utils/utils。 - -- 公共代码文件推荐放在**common**目录下。 ## 示例 - ``` import { FoodData, FoodList } from "../common/utils/utils"; @@ -31,11 +28,10 @@ struct FoodCategoryList { } ``` -导入文件示例: +被导入文件utils.ets: -``` +```ts //common/utils/utils.ets - export class FoodData { name: string; constructor(name: string) { @@ -67,4 +63,4 @@ export struct FoodList { } } } -``` +``` \ No newline at end of file diff --git a/zh-cn/application-dev/ui/ts-framework-js-tag.md b/zh-cn/application-dev/ui/ts-framework-js-tag.md deleted file mode 100644 index c86383841617c4f0157c9a6371f82e9cf54e8da1..0000000000000000000000000000000000000000 --- a/zh-cn/application-dev/ui/ts-framework-js-tag.md +++ /dev/null @@ -1,101 +0,0 @@ -# js标签配置 - -开发框架需要应用的config.json中配置相关的js标签,其中包含了实例名称、页面路由、视图窗口配置信息。 - - -| 标签 | 类型 | 默认值 | 必填 | 描述 | -| -------- | -------- | -------- | -------- | -------- | -| name | string | default | 是 | 标识ETS实例的名字。 | -| pages | Array | - | 是 | 页面路由信息,详见[pages](#pages)说明。 | -| window | Object | - | 否 | 视图窗口配置信息,详见[window](#window)说明。 | -| mode | Object | - | 否 | 配置Js Component运行类型与语法风格,详见[mode](#mode)说明。 | - - -## pages - -定义每个页面入口组件的路由信息,每个页面由页面路径和页面名组成,页面的文件名就是页面名。比如: - -``` -{ - "pages": [ - "pages/index", - "pages/detail" - ] -} -``` - -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> - pages列表中第一个页面为应用的首页入口。 -> -> - 页面文件名不能使用组件名称,比如:Text.ets、Button.ets等。 -> -> - 每个页面文件中必须包含[页面入口组件](../ui/ts-component-based-entry.md)(\@Entry装饰)。 - - -## window - -window用于配置相关视图显示窗口,支持配置如下属性: - -| 类型 | 默认值 | 说明 | -| -------- | -------- | -------- | -| designWidth | - | 配置视图显示的逻辑宽度,缺省默认720(智能穿戴默认454)。视图显示的逻辑宽度决定了lpx像素单位大小,如designWidth配置720时,在视图宽度为1440物理像素时,1lpx为2物理像素。详见[lpx像素单位](../ui/ts-pixel-units.md)说明。 | - -``` -{ - ... - "window": { - "designWidth": 720 - } - ... -} -``` - - -## mode - -mode用于配置JS Component的运行类型与语法风格,支持如下属性: - -| 类型 | 默认值 | 说明 | -| -------- | -------- | -------- | -| type | - | 配置该JS Component的运行类型,可选值为:
- pageAbility:以ability的方式运行该JS Component。
- form:以卡片的方式运行该JS Component。 | -| syntax | - | 配置该JS Component的语法风格,可选值为:
- hml:以hml/css/js风格进行编写。
- ets:以声明式语法风格进行编写。 | - -> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> 不支持同时配置type类型为form,syntax类型为ets。 - - -## 示例 - -config.json: - -``` -{ - "app": { - "bundleName": "com.example.player", - "version": { - "code": 1, - "name": "1.0" - }, - "vendor": "example" - }, - "module": { - "js": [{ - "name": "default", - "pages": [ - "pages/index", - "pages/detail" - ], - "window": { - "designWidth": 720 - }, - "mode": { - "type": "pageAbility", - "syntax": "ets" - }, - }], - "abilities": [{ - ... - }] - } -} -``` diff --git a/zh-cn/application-dev/ui/ts-general-ui-concepts.md b/zh-cn/application-dev/ui/ts-general-ui-concepts.md index 3b56f1795a766404c5edf60a7822158e29ba80ce..5dc1272e6e577bd8e9bf643f2ad7722c8d404e8c 100644 --- a/zh-cn/application-dev/ui/ts-general-ui-concepts.md +++ b/zh-cn/application-dev/ui/ts-general-ui-concepts.md @@ -1,6 +1,6 @@ # 基本概念 -基于TS扩展的声明式开发范式提供了一系列基础组件,这些组件以声明方式进行组合和扩展来描述应用程序的UI界面,并且还提供了基本的数据绑定和事件处理机制,帮助开发者实现应用交互逻辑。 +基于eTS的声明式开发范式提供了一系列基础组件,这些组件以声明方式进行组合和扩展来描述应用程序的UI界面,并且还提供了基本的数据绑定和事件处理机制,帮助开发者实现应用交互逻辑。 ## HelloWorld基本示例 diff --git a/zh-cn/application-dev/ui/ui-js-building-ui-layout-text.md b/zh-cn/application-dev/ui/ui-js-building-ui-layout-text.md index cb3a7c1a186b90c4fd1395d00e363295dd9e91a1..59ce530a620fef49250be9146ef3949ae6404df5 100755 --- a/zh-cn/application-dev/ui/ui-js-building-ui-layout-text.md +++ b/zh-cn/application-dev/ui/ui-js-building-ui-layout-text.md @@ -19,8 +19,10 @@ flex-direction: column; margin-top: 20px; margin-left: 30px; + font-weight: 700; } .title-text { + width: 95%; color: #1a1a1a; font-size: 50px; margin-top: 40px; @@ -38,9 +40,11 @@ // xxx.js export default { data: { - headTitle: 'Capture the Beauty in This Moment', + headTitle: 'Capture the Beauty in Moment', paragraphFirst: 'Capture the beauty of light during the transition and fusion of ice and water. At the instant of movement and stillness, softness and rigidity, force and beauty, condensing moving moments.', paragraphSecond: 'Reflecting the purity of nature, the innovative design upgrades your visual entertainment and ergonomic comfort. Effortlessly capture what you see and let it speak for what you feel.', }, } ``` + + ![zh-cn_image_0000001118642600](figures/zh-cn_image_0000001118642600.PNG) \ No newline at end of file diff --git a/zh-cn/application-dev/ui/ui-js-components-button.md b/zh-cn/application-dev/ui/ui-js-components-button.md index 52ae1c820ab4cc1c16c4196cc820697380705b8c..a584bb53b9abec2c85dc072a9ecd9e0ee975989c 100644 --- a/zh-cn/application-dev/ui/ui-js-components-button.md +++ b/zh-cn/application-dev/ui/ui-js-components-button.md @@ -74,13 +74,7 @@ Button是按钮组件,其类型包括胶囊按钮、圆形按钮、文本按 > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** -> - 胶囊按钮(type=capsule)不支持border相关样式。 -> -> - 圆形按钮(type=circle)不支持文本相关样式。 -> -> - 文本按钮(type=text),自适应文本大小,不支持尺寸样式设置(radius,width,height),背景透明不支持background-color样式。 -> -> - Button组件使用的icon图标如果来自云端路径,需要添加网络访问权限 ohos.permission.INTERNET。 +> - Button组件使用的icon图标如果来自云端路径,需要添加网络访问权限 ohos.permission.INTERNET。具体申请方式请参考[权限申请声明](../../security/accesstoken-guidelines.md)。 如果需要添加ohos.permission.INTERNET权限,则在resources文件夹下的config.json文件里进行权限配置。 diff --git a/zh-cn/application-dev/ui/ui-js-components-grid.md b/zh-cn/application-dev/ui/ui-js-components-grid.md index 8444150dcd559dee40757a28928039c23c65ffbf..e622fc396f4628d149e97d27e020849c7a8524d7 100644 --- a/zh-cn/application-dev/ui/ui-js-components-grid.md +++ b/zh-cn/application-dev/ui/ui-js-components-grid.md @@ -108,9 +108,9 @@ export default { ![zh-cn_image_0000001227135613](figures/zh-cn_image_0000001227135613.gif) -## 添加grild-col +## 添加grid-col -创建grid-container组件并添加grid-row,在grid-row组件内添加grild-col组件形成布局。 +创建grid-container组件并添加grid-row,在grid-row组件内添加grid-col组件形成布局。 ``` diff --git a/zh-cn/application-dev/ui/ui-js-components-images.md b/zh-cn/application-dev/ui/ui-js-components-images.md index 4eb69617fc893e28f22e5359a8cbb800c0a88836..4d781dd0cb0aed20923e98e28504f7907a17e2a0 100644 --- a/zh-cn/application-dev/ui/ui-js-components-images.md +++ b/zh-cn/application-dev/ui/ui-js-components-images.md @@ -132,7 +132,7 @@ export default {
- +
Touch and hold the image diff --git a/zh-cn/application-dev/ui/ui-js-components-offscreencanvas.md b/zh-cn/application-dev/ui/ui-js-components-offscreencanvas.md index f645c710a356f4a369c8bda538eccea9649b2ea9..ac829edabd4609f862920a5004cd4dbf394f7109 100644 --- a/zh-cn/application-dev/ui/ui-js-components-offscreencanvas.md +++ b/zh-cn/application-dev/ui/ui-js-components-offscreencanvas.md @@ -1,6 +1,6 @@ # OffscreenCanvasRenderingContext2D对象 -使用OffscreenCanvas在离屏Canvas画布组件上进行绘制,绘制对象可以是矩形、文本、图片等。具体请参考[OffscreenCanvasRenderingContext2D对象](../reference/arkui-js/js-offscreencanvasrenderingcontext2d.md)。 +使用OffscreenCanvas在离屏Canvas画布组件上进行绘制,绘制对象可以是矩形、文本、图片等。 离屏,即GPU在当前缓冲区以外新开辟的一个缓冲区。 具体请参考[OffscreenCanvasRenderingContext2D对象](../reference/arkui-js/js-offscreencanvasrenderingcontext2d.md)。 以下示例创建了一个OffscreenCanvas画布,再在画布上创建一个getContext2d对象,并设置filter属性改变图片样式。 diff --git a/zh-cn/application-dev/ui/ui-js-components-path2d.md b/zh-cn/application-dev/ui/ui-js-components-path2d.md index f5e8690de8ab83fbecaf8ba481c2af6313fcb7b5..2345c9123ba3a8e6a630ba11f8c5d1e11aa4f741 100644 --- a/zh-cn/application-dev/ui/ui-js-components-path2d.md +++ b/zh-cn/application-dev/ui/ui-js-components-path2d.md @@ -68,7 +68,7 @@ export default { path.moveTo(600, 535); path.arc(520, 450, 85, 0, 6); ctx.stroke(path); - }, + } } ``` @@ -131,51 +131,66 @@ text{ ``` // xxx.js import prompt from '@system.prompt'; + export default { - data:{ - ctx: null, - path1: null, - path2: null, - path3: null, - isAdd: "addPath2", - isChange: true, - textName: 'change' - }, - onShow(){ - this.ctx = this.$refs.canvas.getContext('2d',{antialias:true}); - this.path1 = this.ctx.createPath2D(); - this.path1.moveTo(200, 200); - this.path1.lineTo(400, 200); - this.path1.lineTo(400, 400); - this.path1.lineTo(200, 400); - this.path1.closePath(); - this.path2 = this.ctx.createPath2D(); - this.path2.arc(300, 300, 75, 0, 6.28) - this.ctx.stroke(this.path1); - }, - addPath(){ - if(this.isAdd == "addPath2"){ - this.ctx.clearRect(0,0,600,600) - this.ctx.beginPath(); - this.path2.addPath(this.path1) - this.ctx.stroke(this.path2); - this.isAdd = "clearPath2" - }else{ - this.ctx.clearRect(0,0,600,600) - this.ctx.stroke(this.path1); this.isAdd = "addPath2" - } - }, - setTransform(){ - if(this.isChange){ - this.ctx.clearRect(0,0,600,600) - this.path3 = this.ctx.createPath2D(); - this.path3.arc(150, 150, 100, 0, 6.28) - this.path3.setTransform(2, 0.1, 0.1, 2, 0,0); this.ctx.stroke(this.path3); this.isChange = !this.isChange; this.textName = "back" - }else{ - this.ctx.clearRect(0,0,600,600) - this.path3.setTransform(0.5, -0.1, -0.1, 0.5, 0,0);this.ctx.stroke(this.path3);this.isChange = !this.isChange; this.textName = "change" + data: { + ctx: null, + path1: null, + path2: null, + path3: null, + isAdd: "addPath2", + isChange: true, + textName: 'change' + }, + onShow() { + this.ctx = this.$refs.canvas.getContext('2d', { + antialias: true + }); + this.path1 = this.ctx.createPath2D(); + // 正方形 + this.path1.moveTo(200, 200); + this.path1.lineTo(400, 200); + this.path1.lineTo(400, 400); + this.path1.lineTo(200, 400); + this.path1.closePath(); + this.path2 = this.ctx.createPath2D(); + // 圆形 + this.path2.arc(300, 300, 75, 0, 6.28); + this.ctx.stroke(this.path1); + }, + addPath() { + if (this.isAdd == "addPath2") { + // 删除指定指定区域的绘制内容 + this.ctx.clearRect(0, 0, 600, 600); + this.ctx.beginPath(); + // 将另一个的路径添加到当前路径对象中 + this.path2.addPath(this.path1); + this.ctx.stroke(this.path2); + this.isAdd = "clearPath2"; + } else { + this.ctx.clearRect(0, 0, 600, 600); + this.ctx.stroke(this.path1); + this.isAdd = "addPath2"; + } + }, + setTransform() { + if (this.isChange) { + this.ctx.clearRect(0, 0, 600, 600); + this.path3 = this.ctx.createPath2D(); + this.path3.arc(150, 150, 100, 0, 6.28); + // 重置现有的变换矩阵并创建新的变换矩阵 + this.path3.setTransform(2, 0.1, 0.1, 2, 0, 0); + this.ctx.stroke(this.path3); + this.isChange = !this.isChange; + this.textName = "back" + } else { + this.ctx.clearRect(0, 0, 600, 600); + this.path3.setTransform(0.5, -0.1, -0.1, 0.5, 0, 0); + this.ctx.stroke(this.path3); + this.isChange = !this.isChange; + this.textName = "change"; + } } - }, } ``` diff --git a/zh-cn/application-dev/ui/ui-js-components-picker.md b/zh-cn/application-dev/ui/ui-js-components-picker.md index d9b41d2a7d2ebc85836ad8d9e3518bc47cc11240..4fd2782d40fa24583b403c7331f7184d5ead3c8e 100644 --- a/zh-cn/application-dev/ui/ui-js-components-picker.md +++ b/zh-cn/application-dev/ui/ui-js-components-picker.md @@ -11,7 +11,7 @@ Picker是滑动选择器组件,类型支持普通选择器、日期选择器
picker -
+
``` ``` diff --git a/zh-cn/application-dev/ui/ui-js-custom-components.md b/zh-cn/application-dev/ui/ui-js-custom-components.md index 7e520b1aee36ebdae7fb840c87e685937e191366..1ae23f0f14524df61cd1b3d54f3fa10063ae009a 100755 --- a/zh-cn/application-dev/ui/ui-js-custom-components.md +++ b/zh-cn/application-dev/ui/ui-js-custom-components.md @@ -1,6 +1,6 @@ # 自定义组件 -使用基于JS扩展的类Web开发范式的方舟开发框架支持自定义组件,用户可根据业务需求将已有的组件进行扩展,增加自定义的私有属性和事件,封装成新的组件,方便在工程中多次调用,提高页面布局代码的可读性。具体的封装方法示例如下: +使用兼容JS扩展的类Web开发范式的方舟开发框架支持自定义组件,用户可根据业务需求将已有的组件进行扩展,增加自定义的私有属性和事件,封装成新的组件,方便在工程中多次调用,提高页面布局代码的可读性。具体的封装方法示例如下: - 构建自定义组件 diff --git a/zh-cn/application-dev/ui/ui-ts-building-category-grid-layout.md b/zh-cn/application-dev/ui/ui-ts-building-category-grid-layout.md index 6246ee523ea8676d0bdb500def97cd88c586a2d7..2ce0276cfa511d524f44c059d96c9f3352b4efc9 100644 --- a/zh-cn/application-dev/ui/ui-ts-building-category-grid-layout.md +++ b/zh-cn/application-dev/ui/ui-ts-building-category-grid-layout.md @@ -320,7 +320,7 @@ } ``` - 自定义组件提供了两个生命周期的回调接口aboutToAppear和aboutToDisappear。aboutToAppear的执行时机在创建自定义组件后,执行自定义组件build方法之前。aboutToDisappear在自定义组件的去初始化的时机执行。 +​ 自定义组件提供了两个生命周期的回调接口aboutToAppear和aboutToDisappear。aboutToAppear的执行时机在创建自定义组件后,执行自定义组件build方法之前。aboutToDisappear在自定义组件销毁之前的时机执行。 ![zh-cn_image_0000001215113569](figures/zh-cn_image_0000001215113569.png) diff --git a/zh-cn/application-dev/ui/ui-ts-creating-simple-page.md b/zh-cn/application-dev/ui/ui-ts-creating-simple-page.md index 8e976dd67cf0ff1769a0057fb32b9fa4ff0472b5..9ac54343c438a09bdc16395838a3c61222249ef2 100644 --- a/zh-cn/application-dev/ui/ui-ts-creating-simple-page.md +++ b/zh-cn/application-dev/ui/ui-ts-creating-simple-page.md @@ -1,6 +1,6 @@ # 创建简单视图 -在这一小节中,我们将开始食物详情页的开发,学习如何通过容器组件Stack、Flex和基本组件Image、Text,构建用户自定义组件,完成图文并茂的食物介绍。 +在这一小节中,我们将开始食物详情页的开发,学习如何通过容器组件Stack、Flex和基础组件Image、Text,构建用户自定义组件,完成图文并茂的食物介绍。 ## 构建Stack布局 @@ -24,7 +24,8 @@ ![zh-cn_image_0000001214128687](figures/zh-cn_image_0000001214128687.png) 2. 食物图片展示。 - 创建Image组件,指定Image组件的url,Image组件和Text组件都是必选构造参数组件。为了让Text组件在Image组件上方显示,所以要先声明Image组件。图片资源放在resources下的rawfile文件夹内,引用rawfile下资源时使用`$rawfile('filename')`的形式,filename为rawfile目录下的文件相对路径。当前`$rawfile`仅支持Image控件引用图片资源。 + 创建Image组件,指定Image组件的url,Image组件是必选构造参数组件。为了让Text组件在Image组件上方显示,所以要先声明Image组件。图片资源放在resources下的rawfile文件夹内,引用rawfile下资源时使用`$rawfile('filename')`的形式,filename为rawfile目录下的文件相对路径。当前`$rawfile`仅支持Image控件引用图片资源。 + ``` @Entry @Component @@ -40,15 +41,16 @@ } ``` - ![zh-cn_image_0000001168410342](figures/zh-cn_image_0000001168410342.png) + +![zh-cn_image_0000001168410342](figures/zh-cn_image_0000001168410342.png) 3. 通过资源访问图片。 除指定图片路径外,也可以使用引用媒体资源符$r引用资源,需要遵循resources文件夹的资源限定词的规则。右键resources文件夹,点击New>Resource Directory,选择Resource Type为Media(图片资源)。 将Tomato.png放入media文件夹内。就可以通过`$r('app.type.name')`的形式引用应用资源,即`$r('app.media.Tomato')`。 - ``` - @Entry +``` +@Entry @Component struct MyComponent { build() { @@ -62,7 +64,8 @@ } } } - ``` +``` + 4. 设置Image宽高,并且将image的objectFit属性设置为ImageFit.Contain,即保持图片长宽比的情况下,使得图片完整地显示在边界内。 如果Image填满了整个屏幕,原因如下: @@ -70,8 +73,8 @@ 2. Image的objectFit默认属性是ImageFit.Cover,即在保持长宽比的情况下放大或缩小,使其填满整个显示边界。 - ``` - @Entry +``` +@Entry @Component struct MyComponent { build() { @@ -85,13 +88,15 @@ } } } - ``` +``` + ![zh-cn_image_0000001214210217](figures/zh-cn_image_0000001214210217.png) 5. 设置食物图片和名称布局。设置Stack的对齐方式为底部起始端对齐,Stack默认为居中对齐。设置Stack构造参数alignContent为Alignment.BottomStart。其中Alignment和FontWeight一样,都是框架提供的内置枚举类型。 - ``` - @Entry + +``` +@Entry @Component struct MyComponent { build() { @@ -105,16 +110,21 @@ } } } - ``` +``` + ![zh-cn_image_0000001168728872](figures/zh-cn_image_0000001168728872.png) -6. 通过设置Stack的背景颜色来改变食物图片的背景颜色,设置颜色有两种方式: +6. 通过设置Stack的背景颜色来改变食物图片的背景颜色,设置颜色有四种方式: 1. 通过框架提供的Color内置枚举值来设置,比如backgroundColor(Color.Red),即设置背景颜色为红色。 2. string类型参数,支持的颜色格式有:rgb、rgba和HEX颜色码。比如backgroundColor('\#0000FF'),即设置背景颜色为蓝色,backgroundColor('rgb(255, 255, 255)'),即设置背景颜色为白色。 + 3. number类型参数,支持十六进制颜色值。比如backgroundColor(0xFF0000),即设置背景颜色为红色。 + + 4. Resource类型参数请参考[资源访问](ts-resource-access.md) 。 + - ``` - @Entry +``` +@Entry @Component struct MyComponent { build() { @@ -128,8 +138,9 @@ } .backgroundColor('#FFedf2f5') } - } - ``` +} +``` + ![zh-cn_image_0000001168888822](figures/zh-cn_image_0000001168888822.png) @@ -137,8 +148,8 @@ 1. 参数为Length时,即统一指定四个边的外边距,比如margin(20),即上、右、下、左四个边的外边距都是20。 2. 参数为{top?: Length, right?: Length, bottom?: Length, left?:Length},即分别指定四个边的边距,比如margin({ left: 26, bottom: 17.4 }),即左边距为26,下边距为17.4。 - ``` - @Entry +``` +@Entry @Component struct MyComponent { build() { @@ -154,15 +165,16 @@ .backgroundColor('#FFedf2f5') } } - ``` +``` + ![zh-cn_image_0000001213968747](figures/zh-cn_image_0000001213968747.png) 8. 调整组件间的结构,语义化组件名称。创建页面入口组件为FoodDetail,在FoodDetail中创建Column,设置水平方向上居中对齐 alignItems(HorizontalAlign.Center)。MyComponent组件名改为FoodImageDisplay,为FoodDetail的子组件。 Column是子组件竖直排列的容器组件,本质为线性布局,所以只能设置交叉轴方向的对齐。 - ``` - @Component +``` +@Component struct FoodImageDisplay { build() { Stack({ alignContent: Alignment.BottomStart }) { @@ -188,7 +200,8 @@ .alignItems(HorizontalAlign.Center) } } - ``` +``` + ## 构建Flex布局 @@ -196,8 +209,9 @@ 开发者可以使用Flex弹性布局来构建食物的食物成分表,弹性布局在本场景的优势在于可以免去多余的宽高计算,通过比例来设置不同单元格的大小,更加灵活。 1. 创建ContentTable组件,使其成为页面入口组件FoodDetail的子组件。 - ``` - @Component + +``` +@Component struct FoodImageDisplay { build() { Stack({ alignContent: Alignment.BottomStart }) { @@ -229,7 +243,8 @@ .alignItems(HorizontalAlign.Center) } } - ``` +``` + 2. 创建Flex组件展示Tomato两类成分。 一类是热量Calories,包含卡路里(Calories);一类是营养成分Nutrition,包含蛋白质(Protein)、脂肪(Fat)、碳水化合物(Carbohydrates)和维生素C(VitaminC)。 @@ -238,8 +253,8 @@ 已省略FoodImageDisplay代码,只针对ContentTable进行扩展。 - ``` - @Component +``` +@Component struct ContentTable { build() { Flex() { @@ -267,13 +282,15 @@ .alignItems(HorizontalAlign.Center) } } - ``` +``` + ![zh-cn_image_0000001169759552](figures/zh-cn_image_0000001169759552.png) 3. 调整布局,设置各部分占比。分类名占比(layoutWeight)为1,成分名和成分含量一共占比(layoutWeight)2。成分名和成分含量位于同一个Flex中,成分名占据所有剩余空间flexGrow(1)。 - ``` - @Component + +``` +@Component struct FoodImageDisplay { build() { Stack({ alignContent: Alignment.BottomStart }) { @@ -322,15 +339,16 @@ .alignItems(HorizontalAlign.Center) } } - ``` +``` + ![zh-cn_image_0000001215079443](figures/zh-cn_image_0000001215079443.png) 4. 仿照热量分类创建营养成分分类。营养成分部分(Nutrition)包含:蛋白质(Protein)、脂肪(Fat)、碳水化合物(Carbohydrates)和维生素C(VitaminC)四个成分,后三个成分在表格中省略分类名,用空格代替。 设置外层Flex为竖直排列FlexDirection.Column, 在主轴方向(竖直方向)上等距排列FlexAlign.SpaceBetween,在交叉轴方向(水平轴方向)上首部对齐排列ItemAlign.Start。 - ``` - @Component +``` +@Component struct ContentTable { build() { Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { @@ -421,7 +439,8 @@ .alignItems(HorizontalAlign.Center) } } - ``` +``` + 5. 使用自定义构造函数\@Builder简化代码。可以发现,每个成分表中的成分单元其实都是一样的UI结构。 ![zh-cn_image_0000001169599582](figures/zh-cn_image_0000001169599582.png) @@ -430,8 +449,8 @@ 在ContentTable内声明\@Builder修饰的IngredientItem方法,用于声明分类名、成分名称和成分含量UI描述。 - ``` - @Component +``` + @Component struct ContentTable { @Builder IngredientItem(title:string, name: string, value: string) { Flex() { @@ -450,12 +469,13 @@ } } } - ``` +``` - 在ContentTable的build方法内调用IngredientItem接口,需要用this去调用该Component作用域内的方法,以此来区分全局的方法调用。 - ``` - @Component + 在ContentTable的build方法内调用IngredientItem接口,需要用this去调用该Component作用域内的方法,以此来区分全局的方法调用。 + +``` +@Component struct ContentTable { ...... build() { @@ -470,12 +490,13 @@ .padding({ top: 30, right: 30, left: 30 }) } } - ``` +``` - ContentTable组件整体代码如下。 - ``` - @Component + ContentTable组件整体代码如下。 + +``` +@Component struct ContentTable { @Builder IngredientItem(title:string, name: string, value: string) { Flex() { @@ -494,17 +515,18 @@ } } - build() { - Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { - this.IngredientItem('Calories', 'Calories', '17kcal') - this.IngredientItem('Nutrition', 'Protein', '0.9g') - this.IngredientItem('', 'Fat', '0.2g') - this.IngredientItem('', 'Carbohydrates', '3.9g') - this.IngredientItem('', 'VitaminC', '17.8mg') - } - .height(280) - .padding({ top: 30, right: 30, left: 30 }) - } + build() { + Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Start }) { + this.IngredientItem('Calories', 'Calories', '17kcal') + this.IngredientItem('Nutrition', 'Protein', '0.9g') + this.IngredientItem('', 'Fat', '0.2g') + this.IngredientItem('', 'Carbohydrates', '3.9g') + this.IngredientItem('', 'VitaminC', '17.8mg') + } + .height(280) + .padding({ top: 30, right: 30, left: 30 }) + } + } @Entry @@ -518,7 +540,8 @@ .alignItems(HorizontalAlign.Center) } } - ``` +``` + ![zh-cn_image_0000001215199399](figures/zh-cn_image_0000001215199399.png) diff --git a/zh-cn/application-dev/ui/ui-ts-layout-mediaquery.md b/zh-cn/application-dev/ui/ui-ts-layout-mediaquery.md index ec103e4e07a3e4e52cd9e2de53f066a321cf2137..4434c8b5072eef327e30a7baf9ff466a871aad60 100644 --- a/zh-cn/application-dev/ui/ui-ts-layout-mediaquery.md +++ b/zh-cn/application-dev/ui/ui-ts-layout-mediaquery.md @@ -130,7 +130,7 @@ listener.on('change', onPortrait) } aboutToAppear() { - portraitFunc = this.onPortrait.bind(this) //bind current js instance + portraitFunc = this.onPortrait.bind(this) // 绑定当前应用实例 this.listener.on('change', portraitFunc) } diff --git a/zh-cn/application-dev/ui/ui-ts-overview.md b/zh-cn/application-dev/ui/ui-ts-overview.md index 5f7780947f8cbd6e014c98897bced69c3b6d5d60..aa4f9c9c119eec9bf70c6325c28e7e22b98722ea 100644 --- a/zh-cn/application-dev/ui/ui-ts-overview.md +++ b/zh-cn/application-dev/ui/ui-ts-overview.md @@ -1,13 +1,13 @@ # 概述 -基于TS扩展的声明式开发范式的方舟开发框架是一套开发极简、高性能、跨设备应用的UI开发框架,支持开发者高效的构建跨设备应用UI界面。 +基于eTS的声明式开发范式的方舟开发框架是一套开发极简、高性能、跨设备应用的UI开发框架,支持开发者高效的构建跨设备应用UI界面。 ## 基础能力 -使用基于TS扩展的声明式开发范式的方舟开发框架,采用更接近自然语义的编程方式,让开发者可以直观地描述UI界面,不必关心框架如何实现UI绘制和渲染,实现极简高效开发。开发框架不仅从组件、动效和状态管理三个维度来提供UI能力,还提供了系统能力接口,实现系统能力的极简调用。 +使用基于eTS的声明式开发范式的方舟开发框架,采用更接近自然语义的编程方式,让开发者可以直观地描述UI界面,不必关心框架如何实现UI绘制和渲染,实现极简高效开发。开发框架不仅从组件、动效和状态管理三个维度来提供UI能力,还提供了系统能力接口,实现系统能力的极简调用。 -请参考[基于TS扩展的声明式开发范式API](../reference/arkui-ts/ts-universal-events-click.md)文档,全面地了解组件,更好地开发应用。 +请参考[基于eTS的声明式开发范式API](../reference/arkui-ts/ts-universal-events-click.md)文档,全面地了解组件,更好地开发应用。 - **开箱即用的组件** @@ -22,12 +22,12 @@ - **状态与数据管理** - 状态数据管理作为基于TS扩展的声明式开发范式的特色,通过功能不同的装饰器给开发者提供了清晰的页面更新渲染流程和管道。状态管理包括UI组件状态和应用程序状态,两者协作可以使开发者完整地构建整个应用的数据更新和UI渲染。 + 状态数据管理作为基于eTS的声明式开发范式的特色,通过功能不同的装饰器给开发者提供了清晰的页面更新渲染流程和管道。状态管理包括UI组件状态和应用程序状态,两者协作可以使开发者完整地构建整个应用的数据更新和UI渲染。 - **系统能力接口** - 使用基于TS扩展的声明式开发范式的方舟开发框架,还封装了丰富的系统能力接口,开发者可以通过简单的接口调用,实现从UI设计到系统能力调用的极简开发。 + 使用基于eTS的声明式开发范式的方舟开发框架,还封装了丰富的系统能力接口,开发者可以通过简单的接口调用,实现从UI设计到系统能力调用的极简开发。 ## 整体架构 @@ -59,7 +59,7 @@ ## 相关实例 -基于TS扩展的声明式开发范式的方舟开发框架,有以下相关实例可供参考: +基于eTS的声明式开发范式的方舟开发框架,有以下相关实例可供参考: - [`Canvas`:画布组件(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Canvas) @@ -73,7 +73,7 @@ - [`Gallery`:组件集合(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/Gallery) -- [`BringApp`:拉起系统应用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/BringApp) +- [`BringApp`:拉起系统应用(eTS)(API8)(Full SDK)](https://gitee.com/openharmony/applications_app_samples/tree/master/ETSUI/BringApp) - [`Chat`:聊天示例应用(eTS)(API8)](https://gitee.com/openharmony/applications_app_samples/tree/master/AppSample/Chat) diff --git a/zh-cn/application-dev/website.md b/zh-cn/application-dev/website.md index 7bccc0af2d0e8bb1a4624d4f6500b6068656a66f..501d53db5e072cf594bccd0d6e17b90d761e3d9d 100644 --- a/zh-cn/application-dev/website.md +++ b/zh-cn/application-dev/website.md @@ -34,13 +34,12 @@ - [测试框架使用指导](ability/ability-delegator.md) - UI开发 - [方舟开发框架(ArkUI)概述](ui/arkui-overview.md) - - 基于TS扩展的声明式开发范式 + - 基于eTS的声明式开发范式 - [概述](ui/ui-ts-overview.md) - 框架说明 - 文件组织 - [目录结构](ui/ts-framework-directory.md) - [应用代码文件访问规则](ui/ts-framework-file-access-rules.md) - - [js标签配置](ui/ts-framework-js-tag.md) - 资源管理 - [资源文件的分类](ui/ui-ts-basic-resource-file-categories.md) - [资源访问](ui/ts-resource-access.md) @@ -104,7 +103,7 @@ - [构建食物分类Grid布局](ui/ui-ts-building-category-grid-layout.md) - [页面跳转与数据传递](ui/ui-ts-page-redirection-data-transmission.md) - [性能提升的推荐方案](ui/ts-performance-improvement-recommendation.md) - - 基于JS扩展的类Web开发范式 + - 兼容JS的类Web开发范式 - [概述](ui/ui-js-overview.md) - 框架说明 - [文件组织](ui/js-framework-file.md) diff --git a/zh-cn/release-notes/api-change/v3.1-Release/changelog-v3.1-release.md b/zh-cn/release-notes/api-change/v3.1-Release/changelog-v3.1-release.md new file mode 100644 index 0000000000000000000000000000000000000000..cc569f933aff1bd331034e409a908561c350cb30 --- /dev/null +++ b/zh-cn/release-notes/api-change/v3.1-Release/changelog-v3.1-release.md @@ -0,0 +1,21 @@ +# 3.1 release相对于3.1 beta变更详细说明 + +### 针对color.json中颜色值,增加合法性校验 + +针对color.json中颜色值,增加合法性校验,其校验规则如下: + +- 使用十六进制颜色码,格式如下: + - #rgb:red(0-f) green(0-f) blue(0-f) + - #argb:transparency(0-f) red(0-f) green(0-f) blue(0-f) + - #rrggbb: red(00-ff) green(00-ff) blue(00-ff) + - #aarrggbb: transparency(00-ff) red(00-ff) green(00-ff) blue(00-ff) +- 使用$引用应用中已定义的资源,格式如下: + - $color:xxx + +**变更影响** + +不符合上述校验规则,将在编译时报错。 + +**关键的接口/组件变更** + +无 \ No newline at end of file diff --git a/zh-cn/release-notes/api-change/v3.1-Release/readme.md b/zh-cn/release-notes/api-change/v3.1-Release/readme.md index ca69ac422e485e04f319ae9dcddabf66012a99dd..6c1ca7ef961568d5b08f3d6b8eb91f83b3dc47db 100644 --- a/zh-cn/release-notes/api-change/v3.1-Release/readme.md +++ b/zh-cn/release-notes/api-change/v3.1-Release/readme.md @@ -4,7 +4,7 @@ - [JS API差异报告](js-apidiff-v3.1-release.md) - [Native API差异报告](native-apidiff-v3.1-release.md) +- [3.1 release相对于3.1 beta变更详细说明](changelog-v3.1-release.md) 此外,本次还发布了OpenHarmony 3.2 Canary (API Version 9 Canary)版本: [JS API差异报告(API Version 9 Canary)](js-apidiff-v3.2-canary.md) - diff --git a/zh-cn/website.md b/zh-cn/website.md index 9c00f78df4b670bc2cbe2e4aca093b912cb296f7..76c5157702ae3a5ff1956e4482b0bf02125cfb30 100644 --- a/zh-cn/website.md +++ b/zh-cn/website.md @@ -64,6 +64,7 @@ - [资源调度](release-notes/api-change/v3.1-Release/js-apidiff-resource-scheduler_api-9-canary.md) - [窗口管理](release-notes/api-change/v3.1-Release/js-apidiff-window_api-9-canary.md) - [Native API差异报告](release-notes/api-change/v3.1-Release/native-apidiff-v3.1-release.md) + - [3.1 release相对于3.1 beta变更详细说明](release-notes/api-change/v3.1-Release/changelog-v3.1-release.md) - 贡献 - [参与贡献](contribute/参与贡献.md) - [行为准则](contribute/行为准则.md)