• 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 { BreakpointSystem, BrowserConstants, Constants } from '@ohos/common';
17import { BrowserController } from '@ohos/common/CommonComponents';
18import { ThirdSelectPhotoBrowserBase, ThirdSelectPhotoGridBase } from '@ohos/thirdselect';
19import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
20
21let localStorage = LocalStorage.getShared();
22
23// Third Select Album Page
24@Entry(localStorage)
25@Component
26export struct ThirdSelectPhotoGridPage {
27  @State pageStatus: boolean = false;
28  @Provide albumId: string = '';
29  @State @Watch('updateAnimationStatus') browserController: BrowserController = new BrowserController(true);
30  @State isRunningAnimation: boolean = false;
31  private onBackFunc: Function = (): void => {};
32  private breakpointSystem: BreakpointSystem = new BreakpointSystem();
33
34  aboutToAppear() {
35    if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
36      this.breakpointSystem.registerOrientationChange();
37    }
38  }
39
40  aboutToDisappear() {
41    if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
42      this.breakpointSystem.unregisterOrientationChange();
43    }
44  }
45
46  onPageShow() {
47    this.pageStatus = true;
48  }
49
50  onPageHide() {
51    this.pageStatus = false;
52  }
53
54  onBackPress() {
55    if (this.browserController.isBrowserShow) {
56      this.browserController.browserBackFunc && this.browserController.browserBackFunc();
57      return true;
58    }
59    if (this.onBackFunc) {
60      this.onBackFunc();
61      if (localStorage?.has(Constants.PHOTO_PICKER_SESSION_KEY)) {
62        let session = localStorage?.get<UIExtensionContentSession>(Constants.PHOTO_PICKER_SESSION_KEY);
63        session?.terminateSelf();
64      }
65      return true;
66    }
67    return false;
68  }
69
70  bindBackFunc(backFunc: Function): void {
71    this.onBackFunc = backFunc;
72  }
73
74  build() {
75    Stack() {
76      Column() {
77        ThirdSelectPhotoGridBase({
78          pageStatus: this.pageStatus,
79          backFuncBinder: (backFunc: Function): void => this.bindBackFunc(backFunc),
80          browserController: this.browserController
81        })
82          .transition({ type: TransitionType.All, opacity: 0 })
83      }
84
85      if (this.browserController.isBrowserShow) {
86        Column() {
87          ThirdSelectPhotoBrowserBase({
88            pageStatus: this.pageStatus,
89            geometryTransitionEnable: true,
90            isRunningAnimation: $isRunningAnimation,
91            browserController: this.browserController
92          })
93        }
94        .width("100%")
95        .height("100%")
96
97        // Opacity must change for TransitionEffect taking effect
98        .transition(TransitionEffect.asymmetric(TransitionEffect.opacity(0.99), TransitionEffect.opacity(0.99)))
99      }
100    }
101  }
102
103  pageTransition() {
104    PageTransitionEnter({ type: RouteType.Pop, duration: BrowserConstants.PHOTO_GRID_ANIMATION_DURATION })
105      .opacity(1)
106    PageTransitionExit({ type: RouteType.Push, duration: BrowserConstants.PHOTO_GRID_ANIMATION_DURATION })
107      .opacity(1)
108  }
109
110  private updateAnimationStatus() {
111    this.isRunningAnimation = this.browserController.isAnimating;
112  }
113}
114