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 { Log } from '../../utils/Log'
18import { EventBus } from '../../worker/eventbus/EventBus'
19import { EventBusManager } from '../../worker/eventbus/EventBusManager'
20import { Dispatch, OhCombinedState } from '../../redux/store'
21import { getStore } from '../../redux/store'
22import ReportUtil from '../../utils/ReportUtil'
23
24class StateStruct {
25  isThirdPartyCall: boolean = false
26}
27
28class ScreenSizeType {
29  width: number = 0
30  height: number = 0
31}
32
33class TabBarDispatcher {
34  private mDispatch: Dispatch = (data) => data;
35
36  public setDispatch(dispatch: Dispatch) {
37    this.mDispatch = dispatch;
38  }
39
40  public showSettingView(isShowSettingView: boolean): void {
41    this.mDispatch(Action.showSettingView(isShowSettingView));
42  }
43}
44
45@Component
46export struct TabBarLand {
47  private TAG: string = '[TabBarLand]';
48  @State state: StateStruct = new StateStruct();
49  @State opacityTabBar: number = 0;
50  @State isShowTabBarOther: boolean = false;
51  @Link screenSize: ScreenSizeType;
52  private onBackClicked: Function = () => {
53  };
54  appEventBus: EventBus = EventBusManager.getInstance().getEventBus();
55  private mAction: TabBarDispatcher = new TabBarDispatcher();
56
57  aboutToAppear(): void {
58    Log.info(`${this.TAG} aboutToAppear invoke E`);
59    getStore().subscribe((state: OhCombinedState) => {
60      this.state = {
61        isThirdPartyCall: state.contextReducer.isThirdPartyCall
62      };
63    }, (dispatch: Dispatch) => {
64      this.mAction.setDispatch(dispatch);
65    });
66
67    Log.info(`${this.TAG} aboutToAppear invoke X`)
68  }
69
70  build() {
71    Flex({ direction: FlexDirection.ColumnReverse, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) {
72      if (this.state.isThirdPartyCall) {
73        Row() {
74          Image($r('app.media.ic_public_back')).width(24).height(24)
75            .onClick(() => {
76              this.onBackClicked()
77            })
78        }.width(48).height(48)
79        .padding({ left: 12 })
80        .margin({ bottom: 12 })
81      }
82
83      Row() {
84        Image($r('app.media.setting')).width(24).height(24)
85          .onClick(() => {
86            ReportUtil.write(ReportUtil.CLICK_SETTINGS)
87            this.mAction.showSettingView(true);
88          })
89      }.width(48).height(48)
90      .padding({ left: 12 })
91      .position(this.state.isThirdPartyCall ? { x: 0, y: 12 } : { x: 0, y: this.screenSize.height - 144 })
92    }.width(48).height('100%')
93  }
94}