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 { CameraId } from '../../setting/settingitem/CameraId' 17import { Action, ActionData } from '../actions/Action' 18 19export type CameraState = { 20 cameraPosition: string, 21 curCameraPosition: string, 22 cameraId: string, 23 curCameraName: string, 24 cameraCount: number, 25 shutterIcon: Resource 26} 27 28const initState: CameraState = { 29 cameraPosition: 'BACK', 30 curCameraPosition: 'BACK', 31 cameraId: '', 32 curCameraName: 'BACK', 33 cameraCount: 0, 34 shutterIcon: $r('app.media.ic_circled_filled') 35} 36 37export default function CameraReducer(state = initState, action: ActionData): CameraState { 38 switch (action.type) { 39 case Action.ACTION_SET_CAMERA_POSITION: 40 return { ...state, cameraPosition: action.data.cameraPosition } 41 case Action.ACTION_SWITCH_CAMERA: 42 return { ...state, cameraPosition: action.data.cameraId } 43 case Action.ACTION_UPDATE_CAMERA_POSITION: 44 return { ...state, curCameraPosition: action.data.cameraPosition } 45 case Action.ACTION_UPDATE_SHUTTER_ICON: 46 return { ...state, shutterIcon: action.data.shutterIcon } 47 case Action.ACTION_UPDATE_CAMERA_STATUS: 48 return { ...state } 49 default: 50 return state; 51 } 52}