跳到主要内容

ActionSheetIOS

显示 iOS 原生 Action Sheet 组件。

示例

参考

方法

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 (数组) - 从 ActionSheet 中排除的活动类型

注意: 如果 url 指向本地文件,或者是一个 base64 编码的 uri,它指向的文件将会被加载并直接分享。通过这种方式,你可以分享图片、视频、PDF 文件等。如果 url 指向远程文件或地址,它必须符合 RFC 2396 中描述的 URL 格式。例如,没有正确协议 (HTTP/HTTPS) 的 Web URL 将不会被分享。

'failureCallback' 函数接受一个参数,一个错误对象。此对象上唯一定义的属性是一个可选的 stack 属性,类型为 string

'successCallback' 函数接受两个参数

  • 一个布尔值,表示成功或失败
  • 一个字符串,在成功的情况下,指示分享的方法