• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 { Log } from '../../utils/Log';
17import { Dispatch, getStore, OhCombinedState } from '../../redux/store';
18
19class StateStruct {
20  zoomRatio: number = 1;
21}
22
23class ZoomTextDispatcher {
24  public setDispatch(dispatch: Dispatch) {
25    this.mDispatch = dispatch;
26  }
27
28  private mDispatch: Dispatch = (data) => data;
29}
30
31@Component
32export struct ZoomText {
33  @Link state: StateStruct
34  private TAG: string = '[ZoomText]'
35  private mAction: ZoomTextDispatcher = new ZoomTextDispatcher();
36
37  aboutToAppear() {
38    Log.info(`${this.TAG} aboutToAppear E`)
39    getStore().subscribe((state: OhCombinedState) => {
40      this.state = {
41        zoomRatio: state.zoomReducer.zoomRatio,
42      };
43    }, (dispatch: Dispatch) => {
44      this.mAction.setDispatch(dispatch);
45    });
46    Log.info(`${this.TAG} aboutToAppear X`)
47  }
48
49  aboutToDisappear(): void {
50    Log.info(`${this.TAG} aboutToDisappear E`)
51  }
52
53  build() {
54    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
55      Text(this.state.zoomRatio.toFixed(1))
56        .fontSize(60)
57        .fontColor(Color.White)
58        .fontWeight(300)
59        .textAlign(TextAlign.Center)
60      Text('x')
61        .fontSize(60)
62        .fontColor(Color.White)
63        .fontWeight(300)
64        .textAlign(TextAlign.Center)
65    }
66    .width('100%')
67    .height('100%')
68  }
69}