跳到主要内容
版本:v7

@capacitor/action-sheet

Action Sheet API 提供对原生操作表(Action Sheets)的访问,操作表从屏幕底部弹出,显示用户可以执行的操作。

安装

npm install @capacitor/action-sheet@latest-7
npx cap sync

变量

本插件将使用以下项目变量(在您应用的 variables.gradle 文件中定义):

  • androidxMaterialVersion: com.google.android.material:material 的版本(默认值:1.12.0

PWA 注意事项

Action Sheet 插件需要 PWA Elements 才能工作。

示例

import { ActionSheet, ActionSheetButtonStyle } from '@capacitor/action-sheet';

const showActions = async () => {
const result = await ActionSheet.showActions({
title: '照片选项',
message: '请选择一个操作',
options: [
{
title: '上传',
},
{
title: '分享',
},
{
title: '删除',
style: ActionSheetButtonStyle.Destructive,
},
],
});

console.log('操作表结果:', result);
};

API

showActions(...)

showActions(options: ShowActionsOptions) => Promise<ShowActionsResult>

显示一个操作表样式的模态框,其中包含用户可以选择的各种选项。

参数类型
options
ShowActionsOptions

返回值:

Promise<ShowActionsResult>

自: 1.0.0


接口

ShowActionsResult

属性类型描述
indexnumber所点击选项的索引(从零开始)1.0.0

ShowActionsOptions

属性类型描述
titlestring操作表的标题1.0.0
messagestring显示在标题下方的消息。此选项仅在 iOS 上受支持。1.0.0
optionsActionSheetButton[]用户可以选择的操作选项1.0.0

ActionSheetButton

属性类型描述
titlestring选项的标题1.0.0
style
ActionSheetButtonStyle
选项的样式。此选项仅在 iOS 上受支持。1.0.0
iconstring选项的图标(遵循 ionicon 命名规范)。此选项仅在 Web 平台上受支持。1.0.0

枚举

ActionSheetButtonStyle

成员描述
Default'DEFAULT'选项的默认样式。1.0.0
Destructive'DESTRUCTIVE'用于表示破坏性操作的选项样式。1.0.0
Cancel'CANCEL'用于取消操作表的选项样式。如果使用,应将其应用于最后一个可用选项。1.0.0