• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-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 {
17  BroadCast,
18  BroadCastConstants,
19  BroadCastManager,
20  BrowserConstants,
21  Constants,
22  Log,
23  ScreenManager
24} from '@ohos/common';
25import { BrowserController } from '@ohos/common/CommonComponents';
26import { PhotoGridView } from '../view/PhotoGridView';
27import { PhotoBrowserComponent } from '../view/PhotoBrowserComponent';
28import { SelectPhotoBrowserView } from '../view/SelectPhotoBrowserView';
29import { LEFT_BLANK } from '@ohos/thirdselect/src/main/ets/default/utils/ThirdSelectConstants';
30
31const TAG: string = 'PhotoGridPage';
32AppStorage.SetOrCreate('PhotoGridPageIndex', Constants.INVALID);
33
34// Album Page
35@Entry
36@Component
37export struct PhotoGridPage {
38  @State pageStatus: boolean = false;
39  @Provide isSelectedMode: boolean = false;
40  @Provide isShow: boolean = true;
41  @State isRunningAnimation: boolean = false;
42  @StorageLink(LEFT_BLANK) leftBlank: number[]
43    = [0, ScreenManager.getInstance().getStatusBarHeight(), 0, ScreenManager.getInstance().getNaviBarHeight()];
44  @State @Watch('updateAnimationStatus') browserController: BrowserController = new BrowserController(true);
45  private appBroadCast: BroadCast = BroadCastManager.getInstance().getBroadCast();
46
47  onPageShow(): void {
48    this.pageStatus = true;
49  }
50
51  onPageHide(): void {
52    this.pageStatus = false;
53  }
54
55  onBackPress(): boolean {
56    if (this.browserController.isBrowserShow) {
57      this.doPhotoBrowserViewBack();
58      return true;
59    }
60    if (this.browserController.isSelectBrowserShow) {
61      this.doSelectPhotoBrowserViewBack();
62      return true;
63    }
64
65    if (this.isSelectedMode) {
66      this.isSelectedMode = false;
67      return true;
68    }
69    return false;
70  }
71
72  doSelectPhotoBrowserViewBack() {
73    this.appBroadCast.emit(BroadCastConstants.SELECT_PHOTO_BROWSER_BACK_PRESS_EVENT, []);
74  }
75
76  doPhotoBrowserViewBack() {
77    this.appBroadCast.emit(BroadCastConstants.PHOTO_BROWSER_BACK_PRESS_EVENT, []);
78  }
79
80  build() {
81    Stack() {
82      Column() {
83        PhotoGridView({
84          pageStatus: this.pageStatus,
85          browserController: this.browserController
86        })
87      }
88      .padding({ bottom: this.leftBlank[3] })
89
90      if (this.browserController.isBrowserShow) {
91        Column() {
92          PhotoBrowserComponent({
93            pageStatus: this.pageStatus,
94            geometryTransitionEnable: true,
95            isRunningAnimation: $isRunningAnimation,
96            browserController: this.browserController
97          })
98        }
99        .width("100%")
100        .height("100%")
101        // Opacity must change for TransitionEffect taking effect
102        .transition(TransitionEffect.asymmetric(TransitionEffect.opacity(0.99), TransitionEffect.opacity(0.99)))
103      }
104
105      if (this.browserController.isSelectBrowserShow) {
106        Column() {
107          SelectPhotoBrowserView({
108            pageStatus: this.pageStatus,
109            geometryTransitionEnable: true,
110            isRunningAnimation: $isRunningAnimation,
111            browserController: this.browserController
112          })
113        }
114        .width("100%")
115        .height("100%")
116
117        // Opacity must change for TransitionEffect taking effect
118        .transition(TransitionEffect.asymmetric(TransitionEffect.opacity(0.99), TransitionEffect.opacity(0.99)))
119      }
120    }
121  }
122
123  pageTransition() {
124    PageTransitionEnter({ type: RouteType.Pop, duration: BrowserConstants.PHOTO_GRID_ANIMATION_DURATION })
125      .opacity(1)
126    PageTransitionExit({ type: RouteType.Push, duration: BrowserConstants.PHOTO_GRID_ANIMATION_DURATION })
127      .opacity(1)
128  }
129
130  private updateAnimationStatus() {
131    this.isRunningAnimation = this.browserController.isAnimating;
132  }
133}