• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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 */
15import mediaLibrary from '@ohos.multimedia.mediaLibrary'
16
17@CustomDialog
18export default struct ImagePicker {
19  private imageDatas: Array<mediaLibrary.FileAsset> = []
20  private selected: number = 0
21  public controller: CustomDialogController
22  @Link index: number
23
24  aboutToAppear() {
25    this.selected = this.index
26  }
27
28  build() {
29    Column() {
30      List({ space: 5 }) {
31        ForEach(this.imageDatas, (item, index) => {
32          ListItem() {
33            Stack({ alignContent: Alignment.TopEnd }) {
34              Image(item.uri).width(180).height(150).margin({ left: 2, right: 2, top: 5, bottom: 5 })
35              Radio({ value: 'Radio3', group: 'radioGroup' }).checked(index === this.index ? true : false)
36                .onChange(() => {
37                  this.selected = index
38                })
39            }
40          }
41        })
42      }
43      .width('95%')
44      .height(160)
45      .listDirection(Axis.Horizontal)
46
47      Row() {
48        Button($r('app.string.cancel'))
49          .margin({ right: '25%' })
50          .onClick(() => {
51            this.controller.close()
52          })
53        Button($r('app.string.conform'))
54          .onClick(() => {
55            this.index = this.selected
56          })
57      }
58      .margin({ bottom: 10 })
59    }
60    .width('100%')
61  }
62}