@capacitor/action-sheet
Action Sheet API 提供对原生 Action Sheet 的访问,这些面板从屏幕底部弹出并显示用户可以执行的操作。
安装
npm install @capacitor/action-sheet@latest-6
npx cap sync
变量
此插件将使用以下项目变量(在应用的 variables.gradle 文件中定义):
androidxMaterialVersion:com.google.android.material:material的版本(默认值:1.10.0)
PWA 说明
Action Sheet 插件需要 PWA Elements 才能工作。
示例
import { ActionSheet, ActionSheetButtonStyle } from '@capacitor/action-sheet';
const showActions = async () => {
const result = await ActionSheet.showActions({
title: 'Photo Options',
message: 'Select an option to perform',
options: [
{
title: 'Upload',
},
{
title: 'Share',
},
{
title: 'Remove',
style: ActionSheetButtonStyle.Destructive,
},
],
});
console.log('Action Sheet result:', result);
};
API
showActions(...)
showActions(options: ShowActionsOptions) => Promise<ShowActionsResult>
显示一个包含多个选项供用户选择的 Action Sheet 样式模态框。
| 参数 | 类型 |
|---|---|
options | |
返回:
Promise<ShowActionsResult>
始于: 1.0.0
接口
ShowActionsResult
| 属性 | 类型 | 描述 | 始于 |
|---|---|---|---|
index | number | 被点击选项的索引(从零开始) | 1.0.0 |
ShowActionsOptions
| 属性 | 类型 | 描述 | 始于 |
|---|---|---|---|
title | string | Action Sheet 的标题。 | 1.0.0 |
message | string | 在标题下方显示的消息。此选项仅 iOS 支持。 | 1.0.0 |
options | ActionSheetButton[] | 用户可选择的选项。 | 1.0.0 |
ActionSheetButton
| 属性 | 类型 | 描述 | 始于 |
|---|---|---|---|
title | string | 选项的标题 | 1.0.0 |
style | | 选项的样式。此选项仅 iOS 支持。 | 1.0.0 |
icon | string | 选项的图标(ionicon 命名约定)。此选项仅 Web 支持。 | 1.0.0 |
枚举
ActionSheetButtonStyle
| 成员 | 值 | 描述 | 始于 |
|---|---|---|---|
Default | 'DEFAULT' | 选项的默认样式。 | 1.0.0 |
Destructive | 'DESTRUCTIVE' | 用于破坏性操作的样式。 | 1.0.0 |
Cancel | 'CANCEL' | 用于取消 Action Sheet 的选项的样式。如果使用,应放在最后一个可用选项上。 | 1.0.0 |