ActionSheetIOS
显示 iOS 原生 Action Sheet 组件。
示例
参考
方法
showActionSheetWithOptions()
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”函数接受一个参数,即所选项目的零基索引。
最小示例
tsx
ActionSheetIOS.showActionSheetWithOptions(
{
options: ['Cancel', 'Remove'],
destructiveButtonIndex: 1,
cancelButtonIndex: 0,
},
buttonIndex => {
if (buttonIndex === 1) {
/* destructive action */
}
},
);
dismissActionSheet()
tsx
static dismissActionSheet();
关闭显示的最新 iOS action sheet,如果没有 action sheet 显示,则显示警告。
showShareActionSheetWithOptions()
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”函数接受一个参数,即错误对象。此对象上唯一定义的属性是类型为 string 的可选 stack 属性。
“successCallback”函数接受两个参数:
- 表示成功或失败的布尔值
- 一个字符串,在成功的情况下,指示分享方式