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