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