• 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 * @devices tv, phone, tablet, wearable
18 */
19export interface MediaQueryEvent {
20  /**
21   * @devices tv, phone, tablet, wearable
22   * @since 3
23   */
24  matches: boolean;
25}
26
27/**
28 * @devices tv, phone, tablet, wearable
29 */
30export interface MediaQueryList {
31  /**
32   * Serialized media query condition.
33   * This parameter is read-only.
34   * @devices tv, phone, tablet, wearable
35   * @since 3
36   */
37  media?: string;
38
39  /**
40   * Whether the query is successful. True if the query condition is matched successfully, false otherwise.
41   * This parameter is read-only.
42   * @devices tv, phone, tablet, wearable
43   * @since 3
44   */
45  matches?: boolean;
46
47  /**
48   * Called when the matches value changes.
49   * @devices tv, phone, tablet, wearable
50   * @since 3
51   */
52  onchange?: (matches: boolean) => void;
53
54  /**
55   * Adds a listening function to MediaQueryList.
56   * The listening function must be added before onShow is called, that is, added to the onInit or onReady function.
57   * @devices tv, phone, tablet, wearable
58   * @since 3
59   */
60  addListener(callback: (event: MediaQueryEvent) => void): void;
61
62  /**
63   * Removes a listening function from MediaQueryList.
64   * @devices tv, phone, tablet, wearable
65   * @since 3
66   */
67  removeListener(callback: (event: MediaQueryEvent) => void): void;
68}
69
70/**
71 * @devices tv, phone, tablet, wearable
72 */
73export default class MediaQuery {
74  /**
75   * Queries a media item and returns a MediaQueryList object.
76   * @devices tv, phone, tablet, wearable
77   */
78  static matchMedia(condition: string): MediaQueryList;
79}
80