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';
19import { Action } from '../../redux/actions/Action';
20class StateStruct {
21  xComponentWidth: number = 0;
22  xComponentHeight: number = 0;
23}
24
25
26class ShowFlashBlackDispatcher {
27  private mDispatch: Dispatch = (data) => data;
28
29  public setDispatch(dispatch: Dispatch) {
30    this.mDispatch = dispatch;
31  }
32
33  public updateShowFlashBlackFlag(flag: boolean): void {
34    this.mDispatch(Action.updateShowFlashBlackFlag(flag));
35  }
36}
37
38@Component
39export struct ShowFlashBlack {
40  private TAG: string = '[ShowFlashBlack]:'
41  @State state: StateStruct = new StateStruct()
42  @State opacityValue: number = 1
43  private mAction: ShowFlashBlackDispatcher = new ShowFlashBlackDispatcher();
44
45  aboutToAppear() {
46    Log.info(`${this.TAG} aboutToAppear E`)
47    getStore().subscribe((state: OhCombinedState) => {
48      this.state = {
49        xComponentWidth: state.previewReducer.xComponentWidth,
50        xComponentHeight: state.previewReducer.xComponentHeight
51      };
52    }, (dispatch: Dispatch) => {
53      this.mAction.setDispatch(dispatch);
54    });
55    Log.info(`${this.TAG} aboutToAppear X`)
56  }
57
58  build() {
59    Flex({ direction: FlexDirection.Row }) {
60      Row() {
61        Shape() {
62          Rect()
63            .width(this.state.xComponentWidth)
64            .height(this.state.xComponentHeight)
65        }
66        .fill(Color.Black)
67        .opacity(this.opacityValue)
68        .onAppear(() => {
69          animateTo({
70            duration: 50,
71            delay: 0,
72            onFinish: () => {
73            }
74          }, () => {
75          })
76          animateTo({
77            duration: 300,
78            curve: Curve.Sharp,
79            delay: 50,
80            onFinish: () => {
81              this.mAction.updateShowFlashBlackFlag(false)
82              this.opacityValue = 1
83            }
84          }, () => {
85            this.opacityValue = 0
86          })
87        })
88      }
89    }
90    .width(this.state.xComponentWidth)
91    .height(this.state.xComponentHeight)
92  }
93}