• 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 { Constants } from '../model/browser/photo/Constants';
17import { Log } from '../utils/Log';
18import { UiUtil } from '../utils/UiUtil';
19
20const TAG = 'BrowserController';
21
22@Observed
23export class BrowserController {
24  public geometryTransitionEnable: boolean = false;
25  public isAnimating: boolean = false;
26  public isBrowserShow: boolean = false;
27  public browserParam: Object = undefined;
28  public browserBackFunc: Function;
29  public isSelectBrowserShow: boolean = false;
30  public selectBrowserParam: Object = undefined;
31  public pageFrom: string = undefined;
32
33  constructor(isGeometryEnable: boolean) {
34    this.geometryTransitionEnable = isGeometryEnable;
35  }
36
37  showBrowserWithNoAnimation(param: Object) {
38    this.isBrowserShow = true;
39    this.browserParam = param;
40  }
41
42  showSelectBrowserWithNoAnimation(param: Object) {
43    this.isSelectBrowserShow = true;
44    this.selectBrowserParam = param;
45  }
46
47  showBrowser(geometryIndex: number, geometryString: string, name: string, param: Object) {
48    Log.debug(TAG, 'call show browser');
49    animateTo({
50      curve: Constants.PHOTO_TRANSITION_CURVE,
51      duration: Constants.SHARE_TRANSITION_DURATION,
52      onFinish: () => {
53        this.finishAnimation();
54      }
55    }, () => {
56      UiUtil.resetGeometryTransitionParams();
57      UiUtil.updateGeometryTapInfo(geometryIndex, geometryString);
58      this.isBrowserShow = true;
59      this.pageFrom = name;
60      this.browserParam = param;
61      this.isAnimating = true;
62    });
63  }
64
65  hideBrowser() {
66    Log.debug(TAG, 'call hide browser');
67    animateTo({
68      curve: Constants.SPRING_MOTION_CURVE, // 大图进出阻尼曲线参数
69      onFinish: () => {
70        AppStorage.SetOrCreate<string>('geometryTransitionBrowserId', '');
71        UiUtil.resetGeometryTransitionParams();
72        this.finishAnimation();
73      }
74    }, () => {
75      this.isBrowserShow = false;
76      this.browserParam = undefined;
77      this.isAnimating = true;
78      AppStorage.SetOrCreate<number>('placeholderIndex', -1);
79    });
80  }
81
82  showSelectBrowser(geometryIndex: number, geometryString: string, name: string, param: Object) {
83    Log.debug(TAG, 'call show select browser');
84    animateTo({
85      curve: Constants.PHOTO_TRANSITION_CURVE,
86      duration: Constants.SHARE_TRANSITION_DURATION,
87      onFinish: () => {
88        this.finishAnimation();
89      }
90    }, () => {
91      UiUtil.resetGeometryTransitionParams();
92      UiUtil.updateGeometryTapInfo(geometryIndex, geometryString);
93      this.isSelectBrowserShow = true;
94      this.pageFrom = name;
95      this.selectBrowserParam = param;
96      this.isAnimating = true;
97    });
98  }
99
100  hideSelectBrowser() {
101    Log.debug(TAG, 'call hide select browser');
102    animateTo({
103      curve: Constants.SPRING_MOTION_CURVE, // 大图进出阻尼曲线参数
104      onFinish: () => {
105        AppStorage.SetOrCreate<string>('geometryTransitionBrowserId', '');
106        UiUtil.resetGeometryTransitionParams();
107        this.finishAnimation();
108      }
109    }, () => {
110      this.isSelectBrowserShow = false;
111      this.selectBrowserParam = undefined;
112      this.isAnimating = true;
113      AppStorage.SetOrCreate<number>('placeholderIndex', -1);
114    });
115  }
116
117  finishAnimation() {
118    this.isAnimating = false;
119  }
120}