• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 { BreakpointSystem, BreakPointType } from '../../../common/BreakpointSystem'
17
18@Entry
19@Component
20struct MediaQuerySample {
21  private breakpointSystem: BreakpointSystem = new BreakpointSystem()
22  @StorageProp('currentBreakpoint') currentBreakpoint: string = 'md'
23
24  aboutToAppear() {
25    this.breakpointSystem.register()
26  }
27
28  aboutToDisappear() {
29    this.breakpointSystem.unregister()
30  }
31
32  build() {
33    Column() {
34      Image(new BreakPointType({
35        sm: $r('app.media.sm'),
36        md: $r('app.media.md'),
37        lg: $r('app.media.lg')
38      }).getValue(this.currentBreakpoint))
39        .height(100)
40        .width(100)
41        .objectFit(ImageFit.Contain)
42
43      Text(this.currentBreakpoint)
44        .fontSize(24)
45        .margin(10)
46    }
47    .width('100%')
48    .height('100%')
49    .justifyContent(FlexAlign.Center)
50  }
51}