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 { Action } from '../../../redux/actions/Action' 17import { CaptureMode } from '../../../setting/settingitem/CaptureMode' 18import { Log } from '../../../utils/Log' 19import { EventBus } from '../../../worker/eventbus/EventBus' 20import { EventBusManager } from '../../../worker/eventbus/EventBusManager' 21import { getStore } from '../../../redux/store' 22 23let tabBarLandState = (state) => { 24 return { 25 opacityValueForTabBar: state.SettingReducer.opacityValueForTabBar 26 } 27} 28 29let tabBarLandDispatcher = (dispatch) => { 30 return { 31 updateOpacityForTabBar: (opacityValue) => { 32 dispatch(Action.updateOpacityForTabBar(opacityValue)) 33 } 34 } 35} 36 37class StateStruct { 38} 39 40@Component 41export struct TabBarOther { 42 private TAG: string = '[TabBarOther]:' 43 @State state: StateStruct = new StateStruct() 44 appEventBus: EventBus = EventBusManager.getInstance().getEventBus() 45 46 private aboutToAppear() { 47 Log.info(`${this.TAG} aboutToAppear invoke E`) 48 getStore().connect(tabBarLandState, tabBarLandDispatcher)(this.state) 49 this.appEventBus.on(Action.ACTION_ON_MODE_CHANGED, this.updateOpacityTabBar.bind(this)) 50 Log.info(`${this.TAG} aboutToAppear invoke X`) 51 } 52 53 private aboutToDisappear(): void { 54 Log.info(`${this.TAG} aboutToDisappear invoke E`) 55 this.appEventBus.off(Action.ACTION_ON_MODE_CHANGED, this.updateOpacityTabBar.bind(this)) 56 Log.info(`${this.TAG} aboutToDisappear invoke X`) 57 } 58 59 private updateOpacityTabBar(data) { 60 Log.info(`${this.TAG} updateOpacityTabBar invoke E`) 61 if (data.mode === CaptureMode.VIDEO) { 62 animateTo({ duration: 2000, 63 curve: Curve.Sharp, 64 delay: 0 65 }, () => { 66 this.state.updateOpacityForTabBar(1) 67 }) 68 } else { 69 animateTo({ duration: 2000, 70 curve: Curve.Sharp, 71 delay: 0 72 }, () => { 73 this.state.updateOpacityForTabBar(0) 74 }) 75 } 76 Log.info(`${this.TAG} updateOpacityTabBar invoke X`) 77 } 78 79 build() { 80 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 81 Column() { 82 Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 83 Image($r("app.media.sd_card")).width(24).height(24) 84 }.width('100%').height('100%') 85 } 86 .width('100%') 87 .height('100%') 88 .opacity(this.state.opacityValueForTabBar) 89 } 90 .width('100%') 91 .height('100%') 92 } 93}