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