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';
20
21class StateStruct {
22  isThirdPartyCall: boolean = false;
23}
24
25class TabBarDispatcher {
26  private mDispatch: Dispatch = (data) => data;
27
28  public setDispatch(dispatch: Dispatch) {
29    this.mDispatch = dispatch;
30  }
31
32  public showSettingView(isShowSettingView: boolean): void {
33    this.mDispatch(Action.showSettingView(isShowSettingView));
34  }
35}
36
37
38@Component
39export struct TabBar {
40  private TAG: string = '[TabBar]';
41  @State state: StateStruct = new StateStruct();
42  private onBackClicked: Function = () => {};
43  private mAction: TabBarDispatcher = new TabBarDispatcher();
44
45  aboutToAppear(): void {
46    Log.info(`${this.TAG} aboutToAppear invoke E`)
47    getStore().subscribe((state: OhCombinedState) => {
48      this.state = {
49        isThirdPartyCall: state.contextReducer.isThirdPartyCall,
50      };
51    }, (dispatch: Dispatch) => {
52      this.mAction.setDispatch(dispatch);
53    });
54    Log.info(`${this.TAG} aboutToAppear invoke X`)
55  }
56
57  build() {
58    Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
59      Column() {
60        //        TabBarOther()
61      }.width('40%').height('100%')
62      Column() {
63        if (this.state.isThirdPartyCall) {
64          Row() {
65            Image($r('app.media.ic_public_back')).width(24).height(24)
66              .onClick(() => {
67                this.mAction.showSettingView(false)
68                this.onBackClicked()
69              })
70          }.width(48).height(48)
71          .padding({left: 12})
72          .margin({ bottom: 12 })
73        }
74      }.width('40%').height('100%')
75      Column() {
76        Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
77          Image($r('app.media.setting')).width(24).height(24)
78        }.width('100%').height('100%')
79      }.width('20%').height('100%').onClick(() => {
80        this.mAction.showSettingView(true)
81      })
82    }.width('100%').height('100%')
83  }
84}