• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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 Log from '../default/Log';
17import StyleConfiguration, { IconComponentStyle } from './common/StyleConfiguration'
18
19const TAG = 'iconComponent'
20
21@Component
22export default struct iconComponent {
23  @State iconOff: string = ""
24  @State iconOn: string = ""
25  @Prop iconOffStr: string
26  @Prop iconOnStr: string
27  private useIconStr = false
28  @State mIconIsHover: boolean = false
29  @Link changeSwitch: boolean
30  @State style: IconComponentStyle = StyleConfiguration.getIconComponentStyle()
31
32  aboutToAppear() {
33    Log.showInfo(TAG,`aboutToAppear, ${this.changeSwitch} ${JSON.stringify(this.iconOff)} ${JSON.stringify(this.iconOn)} , useIconStr: ${this.useIconStr}`)
34  }
35
36  aboutToDisappear() {
37    Log.showInfo(TAG, 'aboutToDisappear')
38  }
39
40  build() {
41    Stack() {
42      Flex()
43        .backgroundColor(this.changeSwitch ? this.style.iconOnBG : this.style.iconOffBG)
44        .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight }))
45        .width(this.style.circleWidth)
46        .height(this.style.circleHeight)
47      Flex()
48        .backgroundColor(this.mIconIsHover ? this.style.hoverColor : this.style.transparentColor)
49        .clip(new Circle({ width: this.style.circleWidth, height: this.style.circleHeight }))
50        .width(this.style.circleWidth)
51        .height(this.style.circleHeight)
52      Image(this.changeSwitch == false ? (this.useIconStr ? this.iconOffStr : this.iconOff) : (this.useIconStr ? this.iconOnStr : this.iconOn))
53        .size({ width: this.style.iconWidth, height: this.style.iconHeight })
54        .objectFit(ImageFit.Contain)
55        .fillColor(this.changeSwitch ? this.style.iconOnColor : this.style.iconOffColor)
56        .onHover((isHover) => {
57          this.mIconIsHover = isHover;
58        })
59    }
60    .width(this.style.circleWidth)
61    .height(this.style.circleHeight)
62  }
63}
64