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