• 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 { Action, ActionData, UiStateMode } from '../actions/Action'
17
18export type ContextState = {
19  uiEnable: boolean,
20  uiStateMode: UiStateMode,
21  deviceHeight: number,
22  footBarWidth: number,
23  footBarHeight: number,
24  isThirdPartyCall: boolean,
25  isFaCall: boolean,
26  permissionFlag: boolean,
27  action: string,
28  isKeepScreenOn: boolean,
29  initShowFlag: boolean
30}
31
32const initState: ContextState = {
33  uiEnable: true,
34  uiStateMode: UiStateMode.NONE,
35  deviceHeight: 0,
36  footBarWidth: 0,
37  footBarHeight: 0,
38  isThirdPartyCall: false,
39  isFaCall: false,
40  permissionFlag: false,
41  action: '',
42  isKeepScreenOn: false,
43  initShowFlag: false
44}
45
46export default function ContextReducer(state = initState, action: ActionData): ContextState {
47  switch (action.type) {
48  case Action.ACTION_UI_STATE:
49    return { ...state, uiEnable: action.data.enable, uiStateMode: action.data.uiStateMode }
50  case Action.ACTION_INIT_FOOT_BAR_WIDTH:
51    return { ...state, footBarWidth: action.data.footBarWidth }
52  case Action.ACTION_INIT_FOOT_BAR_HEIGHT:
53    return { ...state, footBarHeight: action.data.footBarHeight }
54  case Action.ACTION_THIRD_PARTY_CALL:
55    return { ...state, isThirdPartyCall: action.data.isThirdPartyCall, action: action.data.action }
56  case Action.ACTION_FA_CALL:
57    return {...state, isFaCall: action.data.isFaCall}
58  case Action.ACTION_SET_PERMISSION_FLAG:
59    return { ...state, permissionFlag: action.data.permissionFlag }
60  case Action.ACTION_INIT_ACTION:
61    return { ...state, action: action.data.action }
62  case Action.ACTION_KEEP_SCREEN_ON:
63    return { ...state, isKeepScreenOn: action.data.isKeepScreenOn }
64  case Action.ACTION_UPDATE_INIT_SHOW_FLAG:
65    return { ...state, initShowFlag: action.data.initShowFlag }
66  default:
67    return state;
68  }
69}