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 } from '../actions/Action'
17
18export type ZoomState = {
19  zoomRatio: number,
20  minZoomRatio: number,
21  maxZoomRatio: number,
22  scrollDetailsBox: number,
23  isPhotoZoomDetails: boolean,
24  photoDetailsOffsetX: number,
25  photoDetailsOffsetXInit: number,
26  isShowZoomText: boolean,
27  isShowPressScrollDetailPhotoButton: boolean,
28  showZoomLabelValue: boolean,
29  isShowPinch: boolean,
30}
31
32const initState: ZoomState = {
33  zoomRatio: 1,
34  minZoomRatio: 1,
35  maxZoomRatio: 6,
36  scrollDetailsBox: 32,
37  isPhotoZoomDetails: false,
38  photoDetailsOffsetX: 0,
39  photoDetailsOffsetXInit: 0,
40  isShowZoomText: false,
41  isShowPinch: false,
42  isShowPressScrollDetailPhotoButton: false,
43  showZoomLabelValue: true,
44}
45
46export function zoomReducer(state = initState, action: ActionData): ZoomState {
47  switch (action.type) {
48    case Action.ACTION_CHANGE_ZOOM_RATIO:
49      return { ...state, zoomRatio: action.data.zoomRatio };
50    case Action.ACTION_RESET_ZOOM_RATIO:
51      return { ...state, zoomRatio: action.data.zoomRatio };
52    case Action.ACTION_INIT_ZOOM_RATIO:
53      return { ...state, minZoomRatio: action.data.minZoomRatio, maxZoomRatio: action.data.maxZoomRatio };
54    case Action.ACTION_UPDATE_SCROLL_DETAILS_BOX:
55      return { ...state, scrollDetailsBox: action.data.scrollDetailsBox };
56    case Action.ACTION_UPDATE_PHOTO_ZOOM_DETAILS_FLAG:
57      return { ...state, isPhotoZoomDetails: action.data.isPhotoZoomDetails };
58    case Action.ACTION_UPDATE_PHOTO_DETAILS_OFFSET_X:
59      return { ...state, photoDetailsOffsetX: action.data.photoDetailsOffsetX };
60    case Action.ACTION_INIT_PHOTO_DETAILS_OFFSET_X:
61      return { ...state, photoDetailsOffsetXInit: action.data.photoDetailsOffsetXInit };
62    case Action.ACTION_UPDATE_SHOW_ZOOM_TEXT_FLAG:
63      return { ...state, isShowZoomText: action.data.isShowZoomText };
64    case Action.ACTION_UPDATE_SHOW_PRESS_SCROLL_DETAIL_PHOTO_BUTTON:
65      return { ...state, isShowPressScrollDetailPhotoButton: action.data.isShowPressScrollDetailPhotoButton };
66    case Action.ACTION_SHOW_ZOOM_LABEL_VALUE:
67      return { ...state, showZoomLabelValue: action.data.showZoomLabelValue };
68    case Action.ACTION_UPDATE_SHOW_PINCH:
69      return { ...state, isShowPinch: action.data.isShowPinch };
70    default:
71      return state;
72  }
73}