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