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_CHANGE_PREVIEW_SIZE, ACTION_CHANGE_SHUTTER_BUTTON } from '../actions/ModeChange'; 18import { UIDATA_TAB_ITEM } from '../actions/UiData'; 19 20export type ModeChangeState = { 21 number: number, 22 res: Resource, 23 tabItem: string[] 24} 25 26const initState: ModeChangeState = { 27 number: 154, 28 res: $r('app.media.icon'), 29 tabItem: ['', 'flash', 'zoom', 'focus', 'setup'] 30} 31 32export function modeChangeReducer(state = initState, action: ActionData): ModeChangeState { 33 switch (action.type) { 34 case ACTION_CHANGE_PREVIEW_SIZE: 35 return { 36 ...state, number: action.data.size 37 }; 38 case ACTION_CHANGE_SHUTTER_BUTTON: 39 return { 40 ...state, res: action.data.res 41 }; 42 case UIDATA_TAB_ITEM: 43 return { 44 ...state, tabItem: action.data.tabItem 45 }; 46 default: 47 return state; 48 } 49}