100aff185Sopenharmony_ci/*
200aff185Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
400aff185Sopenharmony_ci * you may not use this file except in compliance with the License.
500aff185Sopenharmony_ci * You may obtain a copy of the License at
600aff185Sopenharmony_ci *
700aff185Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
800aff185Sopenharmony_ci *
900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and
1300aff185Sopenharmony_ci * limitations under the License.
1400aff185Sopenharmony_ci */
1500aff185Sopenharmony_ciimport { Constants as PhotoConstants } from '../model/browser/photo/Constants';
1600aff185Sopenharmony_ciimport Curves from '@ohos.curves';
1700aff185Sopenharmony_ciimport { Log } from '../utils/Log';
1800aff185Sopenharmony_ci
1900aff185Sopenharmony_ciconst TAG: string = 'browser_PhotoBrowserComponentBg';
2000aff185Sopenharmony_ci
2100aff185Sopenharmony_ci@Component
2200aff185Sopenharmony_ciexport struct PhotoBrowserComponentBg {
2300aff185Sopenharmony_ci  @Consume @Watch('onChangeBgColor') onlyChangeBgColor: boolean;
2400aff185Sopenharmony_ci  @Consume backgroundColorResource: Resource;
2500aff185Sopenharmony_ci  @Link @Watch('onShowChanged') isShowBar: boolean;
2600aff185Sopenharmony_ci  @State opacityValue: number = 1;
2700aff185Sopenharmony_ci  @State isBlackBgVisibility: boolean = false;
2800aff185Sopenharmony_ci  @State blackBgColorResource: Resource = this.backgroundColorResource;
2900aff185Sopenharmony_ci  private isFromPhotoBrowser = false;
3000aff185Sopenharmony_ci
3100aff185Sopenharmony_ci  onShowChanged(): void {
3200aff185Sopenharmony_ci    if (!this.isShowBar) {
3300aff185Sopenharmony_ci      this.isBlackBgVisibility = true;
3400aff185Sopenharmony_ci    }
3500aff185Sopenharmony_ci    if (this.blackBgColorResource.id != $r('app.color.black').id) {
3600aff185Sopenharmony_ci      this.blackBgColorResource = this.backgroundColorResource;
3700aff185Sopenharmony_ci    }
3800aff185Sopenharmony_ci    animateTo({
3900aff185Sopenharmony_ci      duration: PhotoConstants.IMMERSE_ANIM_DURATION,
4000aff185Sopenharmony_ci      delay: this.isShowBar ? 0 : PhotoConstants.IMMERSE_ANIM_DELAY,
4100aff185Sopenharmony_ci      curve: this.isShowBar ? Curves.cubicBezier(0.2, 0.0, 0.2, 1.0) : Curves.cubicBezier(0.6, 0.0, 0.6, 1.0),
4200aff185Sopenharmony_ci      onFinish: () => {
4300aff185Sopenharmony_ci        if (this.isShowBar) {
4400aff185Sopenharmony_ci          this.isBlackBgVisibility = false;
4500aff185Sopenharmony_ci        }
4600aff185Sopenharmony_ci        this.blackBgColorResource = this.backgroundColorResource;
4700aff185Sopenharmony_ci      }
4800aff185Sopenharmony_ci    }, () => {
4900aff185Sopenharmony_ci      if (this.isShowBar) {
5000aff185Sopenharmony_ci        this.opacityValue = 1;
5100aff185Sopenharmony_ci      } else {
5200aff185Sopenharmony_ci        this.opacityValue = 0;
5300aff185Sopenharmony_ci      }
5400aff185Sopenharmony_ci    })
5500aff185Sopenharmony_ci  }
5600aff185Sopenharmony_ci
5700aff185Sopenharmony_ci  onChangeBgColor(): void {
5800aff185Sopenharmony_ci    this.blackBgColorResource = this.backgroundColorResource;
5900aff185Sopenharmony_ci  }
6000aff185Sopenharmony_ci
6100aff185Sopenharmony_ci  build() {
6200aff185Sopenharmony_ci    Stack() {
6300aff185Sopenharmony_ci      if (this.isFromPhotoBrowser) {
6400aff185Sopenharmony_ci        if (this.isBlackBgVisibility) {
6500aff185Sopenharmony_ci          Column() {
6600aff185Sopenharmony_ci          }
6700aff185Sopenharmony_ci          .key('PhotoBrowserBg')
6800aff185Sopenharmony_ci          .backgroundColor(this.blackBgColorResource)
6900aff185Sopenharmony_ci          .width('100%')
7000aff185Sopenharmony_ci          .height('100%')
7100aff185Sopenharmony_ci        }
7200aff185Sopenharmony_ci
7300aff185Sopenharmony_ci        Column() {
7400aff185Sopenharmony_ci        }
7500aff185Sopenharmony_ci        .key('PhotoBrowserBg')
7600aff185Sopenharmony_ci        .backgroundColor($r('app.color.default_background_color'))
7700aff185Sopenharmony_ci        .width('100%')
7800aff185Sopenharmony_ci        .height('100%')
7900aff185Sopenharmony_ci        .opacity(this.opacityValue)
8000aff185Sopenharmony_ci      } else {
8100aff185Sopenharmony_ci        Column() {
8200aff185Sopenharmony_ci        }
8300aff185Sopenharmony_ci        .key('PhotoBrowserBg')
8400aff185Sopenharmony_ci        .backgroundColor(this.backgroundColorResource)
8500aff185Sopenharmony_ci        .width('100%')
8600aff185Sopenharmony_ci        .height('100%')
8700aff185Sopenharmony_ci        .animation({
8800aff185Sopenharmony_ci          duration: PhotoConstants.IMMERSE_ANIM_DURATION
8900aff185Sopenharmony_ci        })
9000aff185Sopenharmony_ci      }
9100aff185Sopenharmony_ci
9200aff185Sopenharmony_ci    }
9300aff185Sopenharmony_ci    .width('100%')
9400aff185Sopenharmony_ci    .height('100%')
9500aff185Sopenharmony_ci  }
9600aff185Sopenharmony_ci}