提交 63d49cdd 编写于 作者: W wusongqing

update doc against 5810

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 d35878b6
# Media Query # Media Query
> ![icon-note.gif](public_sys-resources/icon-note.gif)**NOTE** > **NOTE**
>
> The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > The APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -22,19 +23,21 @@ matchMediaSync(condition: string): MediaQueryListener ...@@ -22,19 +23,21 @@ matchMediaSync(condition: string): MediaQueryListener
Sets the media query criteria and returns the corresponding listening handle. Sets the media query criteria and returns the corresponding listening handle.
- Parameters **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| condition | string | Yes| Matching condition of a media event.|
- Return value **Parameters**
| Type| Description| | Name | Type | Mandatory | Description |
| -------- | -------- | | --------- | ------ | ---- | ---------------------------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or unregister the listening callback.| | condition | string | Yes | Matching condition of a media event. For details, see [Syntax of Media Query Conditions](../../ui/ui-ts-layout-mediaquery.md#syntax-of-media-query-conditions).|
- Example **Return value**
| Type | Description |
| ------------------ | ---------------------- |
| MediaQueryListener | Listening handle to a media event, which is used to register or deregister the listening callback.|
**Example**
```js ```js
let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
``` ```
...@@ -42,13 +45,14 @@ let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen ...@@ -42,13 +45,14 @@ let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen
Media query handle, including the first query result when the handle is applied for. Media query handle, including the first query result when the handle is applied for.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
### Attributes ### Attributes
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ------- | ------- | ---- | ---- | ---------- |
| matches | boolean | Yes| No| Whether the match condition is met.| | matches | boolean | Yes | No | Whether the match condition is met. |
| media | string | Yes| No| Matching condition of a media event.| | media | string | Yes | No | Matching condition of a media event.|
### on ### on
...@@ -57,13 +61,15 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void ...@@ -57,13 +61,15 @@ on(type: 'change', callback: Callback&lt;MediaQueryResult&gt;): void
Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change. Registers a callback with the corresponding query condition by using the handle. This callback is triggered when the media attributes change.
- Parameters **System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | **Parameters**
| type | string | Yes| Must enter the string **change**.| | Name | Type | Mandatory | Description |
| callback | Callback&lt;MediaQueryResult&gt; | Yes| Callback registered with media query.| | -------- | -------------------------------- | ---- | ---------------- |
| type | string | Yes | Must enter the string **change**.|
| callback | Callback&lt;MediaQueryResult&gt; | Yes | Callback registered with media query. |
- Example **Example**
For details, see [off Example](#off). For details, see [off Example](#off).
...@@ -71,18 +77,21 @@ Registers a callback with the corresponding query condition by using the handle. ...@@ -71,18 +77,21 @@ Registers a callback with the corresponding query condition by using the handle.
off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void off(type: 'change', callback?: Callback&lt;MediaQueryResult&gt;): void
Unregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change. Deregisters a callback with the corresponding query condition by using the handle, so that no callback is triggered when the media attributes change.
- Parameters
| Name| Type| Mandatory| Description| **System capability**: SystemCapability.ArkUI.ArkUI.Full
| -------- | -------- | -------- | -------- |
| type | boolean | Yes| Must enter the string **change**.| **Parameters**
| callback | Callback&lt;MediaQueryResult&gt; | No| Callback to be unregistered. If the default value is used, all callbacks of the handle are unregistered.| | Name | Type | Mandatory | Description |
| -------- | -------------------------------- | ---- | ----------------------------- |
| type | boolean | Yes | Must enter the string **change**. |
| callback | Callback&lt;MediaQueryResult&gt; | No | Callback to be deregistered. If the default value is used, all callbacks of the handle are deregistered.|
- Example **Example**
```js ```js
import mediaquery from '@ohos.mediaquery' import mediaquery from '@ohos.mediaquery'
let listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events. listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
function onPortrait(mediaQueryResult) { function onPortrait(mediaQueryResult) {
if (mediaQueryResult.matches) { if (mediaQueryResult.matches) {
// do something here // do something here
...@@ -91,7 +100,7 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -91,7 +100,7 @@ Unregisters a callback with the corresponding query condition by using the handl
} }
} }
listener.on('change', onPortrait) // Register a callback. listener.on('change', onPortrait) // Register a callback.
listener.off('change', onPortrait) // Unregister a callback. listener.off('change', onPortrait) // Deregister a callback.
``` ```
...@@ -100,10 +109,10 @@ Unregisters a callback with the corresponding query condition by using the handl ...@@ -100,10 +109,10 @@ Unregisters a callback with the corresponding query condition by using the handl
### Attributes ### Attributes
| Name| Type| Readable| Writable| Description| | Name | Type | Readable | Writable | Description |
| -------- | -------- | -------- | -------- | -------- | | ------- | ------- | ---- | ---- | ---------- |
| matches | boolean | Yes| No| Whether the match condition is met.| | matches | boolean | Yes | No | Whether the match condition is met. |
| media | string | Yes| No| Matching condition of a media event.| | media | string | Yes | No | Matching condition of a media event.|
### Example ### Example
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册