版本:0.85
ActionSheetIOS
在 iOS 上显示原生的 Action Sheet 组件。
示例
参考
方法
showActionSheetWithOptions()
React TSX
static showActionSheetWithOptions: (
options: ActionSheetIOSOptions,
callback: (buttonIndex: number) => void,
);
显示一个 iOS action sheet。options 对象必须包含以下一项或多项:
options(字符串数组)- 按钮标题列表(必填)cancelButtonIndex(整数)-options中取消按钮的索引cancelButtonTintColor(字符串)- 用于更改取消按钮文本颜色的 颜色destructiveButtonIndex(整数或整数数组)-options中危险按钮的索引title(字符串)- 显示在 action sheet 上方的标题message(字符串)- 显示在标题下方的消息anchor(数字)- action sheet 应锚定到的节点(用于 iPad)tintColor(字符串)- 用于非危险按钮标题的 颜色disabledButtonIndices(数字数组)- 应被禁用的按钮索引列表userInterfaceStyle(字符串)- action sheet 使用的界面样式,可设置为light或dark,否则将使用默认系统样式
callback 函数接收一个参数,即所选项目的从零开始索引。
最小示例:
React TSX
ActionSheetIOS.showActionSheetWithOptions(
{
options: ['Cancel', 'Remove'],
destructiveButtonIndex: 1,
cancelButtonIndex: 0,
},
buttonIndex => {
if (buttonIndex === 1) {
/* 危险操作 */
}
},
);
dismissActionSheet()
React TSX
static dismissActionSheet();
关闭当前显示的最上层 iOS action sheet,如果没有 action sheet,则会显示警告。
showShareActionSheetWithOptions()
React TSX
static showShareActionSheetWithOptions: (
options: ShareActionSheetIOSOptions,
failureCallback: (error: Error) => void,
successCallback: (success: boolean, method: string) => void,
);
显示 iOS 分享面板。options 对象应包含 message 和 url 中的一个或两个,并且还可以包含 subject 或 excludedActivityTypes:
url(字符串)- 要分享的 URLmessage(字符串)- 要分享的消息subject(字符串)- 消息的主题excludedActivityTypes(数组)- 要从 ActionSheet 中排除的活动
备注
如果 url 指向本地文件,或者是 base64 编码的 uri,则会直接加载并共享其指向的文件。这样你可以分享图片、视频、PDF 文件等。如果 url 指向远程文件或地址,则必须符合 RFC 2396 中描述的 URL 格式。例如,不会共享没有正确协议(HTTP/HTTPS)的网页 URL。
failureCallback 函数接收一个参数,即错误对象。该对象上定义的唯一属性是可选的 stack 属性,类型为 string。
successCallback 函数接收两个参数:
- 一个表示成功或失败的布尔值
- 一个字符串,在成功时指示分享方式