跳到主要内容
版本:v8

@capacitor/action-sheet

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

安装

npm install @capacitor/action-sheet
npx cap sync

变量

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

  • androidxMaterialVersion:com.google.android.material:material 的版本(默认:1.13.0)

PWA 说明

动作表插件需要 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>

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

ParamType
options
ShowActionsOptions

Returns:

Promise<ShowActionsResult>

Since: 1.0.0


Interfaces

ShowActionsResult

PropTypeDescriptionSince
indexnumber点击的选项的索引(从零开始),如果动作表被取消则为 -1。在 iOS 上,如果有一个带有 ActionSheetButtonStyle.Cancel 样式的按钮,并且用户点击动作表外部,则返回取消选项的索引1.0.0
canceledboolean如果动作表被用户取消则为 true;否则为 false。在 Web 上,需要 @ionic/pwa-elements 版本 3.4.0 或更高。8.1.0

ShowActionsOptions

PropTypeDescriptionSince
titlestring动作表的标题。1.0.0
messagestring在标题下显示的消息。此选项仅在 iOS 上受支持。1.0.0
optionsActionSheetButton[]用户可以选择的选项。1.0.0
cancelableboolean如果为 true,则在点击外部时取消动作表;如果为 false,则不会。默认为 false。在 iOS 上不可用,动作表始终可以通过点击外部来取消。在 Web 上,需要 @ionic/pwa-elements 版本 3.4.0 或更高。8.1.0

ActionSheetButton

PropTypeDescriptionSince
titlestring选项的标题1.0.0
style
ActionSheetButtonStyle
选项的样式。此选项仅在 iOS 上受支持。1.0.0
iconstring选项的图标(ionicon 命名约定)。此选项仅在 Web 上受支持。1.0.0

Enums

ActionSheetButtonStyle

MembersValueDescriptionSince
Default'DEFAULT'选项的默认样式。1.0.0
Destructive'DESTRUCTIVE'用于破坏性选项的样式。1.0.0
Cancel'CANCEL'用于取消动作表的选项的样式。如果使用,应该放在最后一个可用选项上。1.0.0