• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { Callback } from './@ohos.base';
17
18/**
19 * Used to do mediaquery operations.
20 *
21 * @namespace mediaquery
22 * @syscap SystemCapability.ArkUI.ArkUI.Full
23 * @since 7
24 */
25/**
26 * Used to do mediaquery operations.
27 *
28 * @namespace mediaquery
29 * @syscap SystemCapability.ArkUI.ArkUI.Full
30 * @crossplatform
31 * @since 10
32 */
33declare namespace mediaquery {
34
35  interface MediaQueryResult {
36    /**
37     * Whether the match condition is met.
38     * This parameter is read-only.
39     *
40     * @type { boolean }
41     * @syscap SystemCapability.ArkUI.ArkUI.Full
42     * @since 7
43     */
44    /**
45     * Whether the match condition is met.
46     * This parameter is read-only.
47     *
48     * @type { boolean }
49     * @syscap SystemCapability.ArkUI.ArkUI.Full
50     * @crossplatform
51     * @since 10
52     */
53    readonly matches: boolean;
54
55    /**
56     * Matching condition of a media event.
57     * This parameter is read-only.
58     *
59     * @type { string }
60     * @syscap SystemCapability.ArkUI.ArkUI.Full
61     * @since 7
62     */
63    /**
64     * Matching condition of a media event.
65     * This parameter is read-only.
66     *
67     * @type { string }
68     * @syscap SystemCapability.ArkUI.ArkUI.Full
69     * @crossplatform
70     * @since 10
71     */
72    readonly media: string;
73  }
74
75  interface MediaQueryListener extends MediaQueryResult {
76    /**
77     * Registers a callback with the corresponding query condition by using the handle.
78     * This callback is triggered when the media attributes change.
79     *
80     * @param { 'change' } type
81     * @param { Callback<MediaQueryResult> } callback
82     * @syscap SystemCapability.ArkUI.ArkUI.Full
83     * @since 7
84     */
85    /**
86     * Registers a callback with the corresponding query condition by using the handle.
87     * This callback is triggered when the media attributes change.
88     *
89     * @param { 'change' } type
90     * @param { Callback<MediaQueryResult> } callback
91     * @syscap SystemCapability.ArkUI.ArkUI.Full
92     * @crossplatform
93     * @since 10
94     */
95    on(type: 'change', callback: Callback<MediaQueryResult>): void;
96
97    /**
98     * Deregisters a callback with the corresponding query condition by using the handle.
99     * This callback is not triggered when the media attributes chang.
100     *
101     * @param { 'change' } type
102     * @param { Callback<MediaQueryResult> } callback
103     * @syscap SystemCapability.ArkUI.ArkUI.Full
104     * @since 7
105     */
106    /**
107     * Deregisters a callback with the corresponding query condition by using the handle.
108     * This callback is not triggered when the media attributes chang.
109     *
110     * @param { 'change' } type
111     * @param { Callback<MediaQueryResult> } callback
112     * @syscap SystemCapability.ArkUI.ArkUI.Full
113     * @crossplatform
114     * @since 10
115     */
116    off(type: 'change', callback?: Callback<MediaQueryResult>): void;
117  }
118
119  /**
120   * Sets the media query criteria and returns the corresponding listening handle
121   *
122   * @param { string } condition
123   * @returns { MediaQueryListener }
124   * @syscap SystemCapability.ArkUI.ArkUI.Full
125   * @since 7
126   */
127  /**
128   * Sets the media query criteria and returns the corresponding listening handle
129   *
130   * @param { string } condition
131   * @returns { MediaQueryListener }
132   * @syscap SystemCapability.ArkUI.ArkUI.Full
133   * @crossplatform
134   * @since 10
135   */
136  function matchMediaSync(condition: string): MediaQueryListener;
137}
138
139export default mediaquery;
140