跳至主内容
版本:当前版本

ActionSheetIOS

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

显示 iOS 原生的 操作菜单 组件。

示例

参考

方法

showActionSheetWithOptions()

tsx
static showActionSheetWithOptions: (
options: ActionSheetIOSOptions,
callback: (buttonIndex: number) => void,
);

显示 iOS 操作菜单。options 对象必须包含以下一项或多项:

  • options (字符串数组) - 按钮标题列表(必填)

  • cancelButtonIndex (整型) - options 中取消按钮的索引

  • cancelButtonTintColor (字符串) - 用于设置取消按钮文字颜色的颜色值

  • destructiveButtonIndex (整型或整型数组) - options 中危险操作按钮的索引

  • title (字符串) - 显示在操作菜单上方的标题

  • message (字符串) - 显示在标题下方的消息

  • anchor (数值) - 操作菜单应锚定的节点(用于 iPad)

  • tintColor (字符串) - 用于非危险操作按钮标题的颜色值

  • disabledButtonIndices (数值数组) - 应禁用的按钮索引列表

  • userInterfaceStyle (字符串) - 操作菜单的界面样式,可设为 lightdark,未设置时使用系统默认样式

'callback' 回调函数接收一个参数:所选项目的从零开始的索引。

最小示例:

tsx
ActionSheetIOS.showActionSheetWithOptions(
{
options: ['Cancel', 'Remove'],
destructiveButtonIndex: 1,
cancelButtonIndex: 0,
},
buttonIndex => {
if (buttonIndex === 1) {
/* destructive action */
}
},
);

dismissActionSheet()

tsx
static dismissActionSheet();

关闭当前最顶层的 iOS 操作菜单。若无操作菜单显示,将输出警告信息。


showShareActionSheetWithOptions()

tsx
static showShareActionSheetWithOptions: (
options: ShareActionSheetIOSOptions,
failureCallback: (error: Error) => void,
successCallback: (success: boolean, method: string) => void,
);

显示 iOS 分享菜单。options 对象应包含 messageurl 中的至少一项,并可额外设置 subjectexcludedActivityTypes

  • url (字符串) - 待分享的 URL

  • message (字符串) - 待分享的消息

  • subject (字符串) - 消息主题

  • excludedActivityTypes (数组) - 要从操作菜单中排除的活动类型

备注

如果 url 指向本地文件或是 base64 编码的 URI,系统将直接加载并分享该文件。通过这种方式,您可以分享图片、视频、PDF 等文件。若 url 指向远程文件或地址,则必须符合 RFC 2396 规定的 URL 格式。例如,未使用正确协议(HTTP/HTTPS)的网页 URL 将无法被分享。

'failureCallback' 失败回调函数接收一个参数:错误对象。该对象仅包含一个可选的 stack 属性(类型为 string)。

'successCallback' 成功回调函数接收两个参数:

  • 布尔值,表示操作成功或失败

  • 字符串,操作成功时表示分享方式