• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2020 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
16/**
17 * Defines the MediaQuery event.
18 *
19 * @interface MediaQueryEvent
20 * @syscap SystemCapability.ArkUI.ArkUI.Full
21 * @since 3
22 */
23export interface MediaQueryEvent {
24  /**
25   * The result of match result.
26   *
27   * @type { boolean }
28   * @syscap SystemCapability.ArkUI.ArkUI.Full
29   * @since 3
30   */
31  matches: boolean;
32}
33
34/**
35 * Defines the MediaQuery list info.
36 *
37 * @interface MediaQueryList
38 * @syscap SystemCapability.ArkUI.ArkUI.Full
39 * @since 3
40 */
41export interface MediaQueryList {
42  /**
43   * Serialized media query condition.
44   * This parameter is read-only.
45   *
46   * @type { ?string }
47   * @syscap SystemCapability.ArkUI.ArkUI.Full
48   * @since 3
49   */
50  media?: string;
51
52  /**
53   * Whether the query is successful. True if the query condition is matched successfully, false otherwise.
54   * This parameter is read-only.
55   *
56   * @type { ?boolean }
57   * @syscap SystemCapability.ArkUI.ArkUI.Full
58   * @since 3
59   */
60  matches?: boolean;
61
62  /**
63   * Called when the matches value changes.
64   *
65   * @type { ?function }
66   * @syscap SystemCapability.ArkUI.ArkUI.Full
67   * @since 3
68   */
69  onchange?: (matches: boolean) => void;
70
71  /**
72   * Adds a listening function to MediaQueryList.
73   * The listening function must be added before onShow is called, that is, added to the onInit or onReady function.
74   *
75   * @param { function } callback
76   * @syscap SystemCapability.ArkUI.ArkUI.Full
77   * @since 3
78   */
79  addListener(callback: (event: MediaQueryEvent) => void): void;
80
81  /**
82   * Removes a listening function from MediaQueryList.
83   *
84   * @param { function } callback
85   * @syscap SystemCapability.ArkUI.ArkUI.Full
86   * @since 3
87   */
88  removeListener(callback: (event: MediaQueryEvent) => void): void;
89}
90
91/**
92 * Defines the mediaquery interface.
93 *
94 * @syscap SystemCapability.ArkUI.ArkUI.Full
95 * @since 3
96 */
97export default class MediaQuery {
98  /**
99   * Queries a media item and returns a MediaQueryList object.
100   *
101   * @param { string } condition
102   * @returns { MediaQueryList }
103   * @syscap SystemCapability.ArkUI.ArkUI.Full
104   * @since 3
105   */
106  static matchMedia(condition: string): MediaQueryList;
107}
108