ts-methods-action-sheet.md 3.1 KB
Newer Older
Z
zengyawen 已提交
1
# Action Sheet
Z
zengyawen 已提交
2 3


E
ester.zhou 已提交
4 5
> **NOTE**
>
Z
zengyawen 已提交
6
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
7

Z
zengyawen 已提交
8 9 10 11 12

An action sheet is a dialog box that displays actions a user can take.


## Required Permissions
Z
zengyawen 已提交
13 14 15

None

Z
zengyawen 已提交
16 17 18 19 20

## ActionSheet.show

show(options: { paramObject1})

E
ester.zhou 已提交
21
Defines and shows an action sheet.
Z
zengyawen 已提交
22 23

- paramObject1 parameters
24
  | Name | Type | Mandatory | Default Value | Description |
Z
zengyawen 已提交
25
  | -------- | -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
26 27
  | title | string \|[Resource](../../ui/ts-types.md) | No | None | Title of the dialog box. |
  | message | string \|[Resource](../../ui/ts-types.md) |  |  | Content of the dialog box. |
E
esterzhou 已提交
28
  | autoCancel | boolean | No | true | Whether to close the dialog box when the overlay is clicked. |
E
ester.zhou 已提交
29
  | confirm | {<br/>value: string \| [Resource](../../ui/ts-types.md),<br/>action: () =&gt; void<br/>} | No | - | Text content of the confirm button and callback upon button clicking.<br/>**value**: button text.<br/>**action**: callback upon button clicking. |
E
esterzhou 已提交
30
  | cancel | () =&gt; void | No | - | Callback invoked when the dialog box is closed after the overlay is clicked. |
E
ester.zhou 已提交
31 32 33
  | alignment | [DialogAlignment](ts-methods-custom-dialog-box.md) | No | DialogAlignment.Default | Alignment mode of the dialog box in the vertical direction. |
  | offset | {<br/>dx: Length,<br/>dy: Length<br/>} | No | {<br/>dx: 0,<br/>dy: 0<br/>} | Offset of the dialog box relative to the alignment position. |
  | sheets | Array<SheetInfo&gt; | Yes | - | Options in the dialog box. Each option supports the image, text, and callback. |
Z
zengyawen 已提交
34 35

- SheetInfo parameters
E
esterzhou 已提交
36
  | Name | Type | Mandatory | Default Value | Description |
37
  | -------- | -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
38 39
  | title | string \| [Resource](../../ui/ts-types.md) | Yes | - | Sheet text. |
  | icon | string \| [Resource](../../ui/ts-types.md) | No | None | Sheet icon. |
E
esterzhou 已提交
40
  | action | ()=&gt;void | Yes | - | Callback when the sheet is selected. |
Z
zengyawen 已提交
41 42 43 44 45


## Example


Z
zengyawen 已提交
46

E
ester.zhou 已提交
47 48
```ts
// xxx.ets
Z
zengyawen 已提交
49 50
@Entry
@Component
E
ester.zhou 已提交
51
struct ActionSheetExample {
Z
zengyawen 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Button('Click to Show ActionSheet')
        .onClick(() => {
          ActionSheet.show({
            title: 'ActionSheet title',
            message: 'message',
            confirm: {
              value: 'Confirm button',
              action: () => {
                console.log('Get Alert Dialog handled')
              }
            },
            sheets: [
              {
                title: 'apples',
                action: () => {
                  console.error('apples')
                }
              },
              {
                title: 'bananas',
                action: () => {
                  console.error('bananas')
                }
              },
              {
                title: 'pears',
                action: () => {
                  console.error('pears')
                }
              }
            ]
          })
        })
    }.width('100%')
    .height('100%')
  }
}
```

Z
zengyawen 已提交
93 94

![en-us_image_0000001212058508](figures/en-us_image_0000001212058508.gif)
Z
zengyawen 已提交
95