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