@@ -3,50 +3,58 @@ id: actionsheetios
33title : ActionSheetIOS
44---
55
6- 显示一个 iOS 原生的[ Action Sheet] ( https://developer.apple.com/design/human-interface-guidelines/ios/views/ action-sheets/ ) 组件。
6+ 显示 iOS 原生的 [ Action Sheet] ( https://developer.apple.com/design/human-interface-guidelines/action-sheets ) 组件。
77
88## 示例
99
10- ``` SnackPlayer name=ActionSheetIOS&supportedPlatforms=ios
11- import React, { useState } from "react";
12- import { ActionSheetIOS, Button, StyleSheet, Text, View } from "react-native";
10+ ``` SnackPlayer name=ActionSheetIOS%20Example&supportedPlatforms=ios
11+ import React, {useState} from 'react';
12+ import {ActionSheetIOS, Button, StyleSheet, Text} from 'react-native';
13+ import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
14+
1315const App = () => {
14- const [result, setResult] = useState("🔮");
16+ const [result, setResult] = useState('🔮');
17+
1518 const onPress = () =>
1619 ActionSheetIOS.showActionSheetWithOptions(
1720 {
18- options: [" Cancel", " Generate number", " Reset" ],
21+ options: [' Cancel', ' Generate number', ' Reset' ],
1922 destructiveButtonIndex: 2,
2023 cancelButtonIndex: 0,
21- userInterfaceStyle: 'dark'
24+ userInterfaceStyle: 'dark',
2225 },
2326 buttonIndex => {
2427 if (buttonIndex === 0) {
2528 // cancel action
2629 } else if (buttonIndex === 1) {
27- setResult(Math.floor(Math.random() * 100) + 1);
30+ setResult(String( Math.floor(Math.random() * 100) + 1) );
2831 } else if (buttonIndex === 2) {
29- setResult("🔮" );
32+ setResult('🔮' );
3033 }
31- }
34+ },
3235 );
36+
3337 return (
34- <View style={styles.container}>
35- <Text style={styles.result}>{result}</Text>
36- <Button onPress={onPress} title="Show Action Sheet" />
37- </View>
38+ <SafeAreaProvider>
39+ <SafeAreaView style={styles.container}>
40+ <Text style={styles.result}>{result}</Text>
41+ <Button onPress={onPress} title="Show Action Sheet" />
42+ </SafeAreaView>
43+ </SafeAreaProvider>
3844 );
3945};
46+
4047const styles = StyleSheet.create({
4148 container: {
4249 flex: 1,
43- justifyContent: " center"
50+ justifyContent: ' center',
4451 },
4552 result: {
4653 fontSize: 64,
47- textAlign: " center"
48- }
54+ textAlign: ' center',
55+ },
4956});
57+
5058export default App;
5159```
5260
@@ -63,32 +71,36 @@ static showActionSheetWithOptions: (
6371);
6472```
6573
66- 在 iOS 设备上显示一个 ActionSheet 弹出框,其中` options ` 参数为一个对象,其属性必须包含以下一项或多项:
74+ 在 iOS 设备上显示一个 ActionSheet 弹出框,其中 ` options ` 参数为一个对象,其属性必须包含以下一项或多项:
6775
68- - ` options ` (字符串数组) - 按钮标题列表(必需)
69- - ` cancelButtonIndex ` (整数) - ` options ` 中取消按钮的索引
70- - ` cancelButtonTintColor ` (字符串) - 用于改变取消按钮文本颜色的颜色([ 颜色] ( colors ) )
71- - ` destructiveButtonIndex ` (整数或整数数组) - ` options ` 中破坏性按钮的索引
72- - ` title ` (字符串) - 显示在操作表上方的标题
73- - ` message ` (字符串) - 显示在标题下方的消息
74- - ` anchor ` (数字) - 操作表应锚定的节点(用于 iPad)
75- - ` tintColor ` (字符串) - 用于非破坏性按钮标题的颜色([ 颜色] ( colors ) )
76- - ` disabledButtonIndices ` (数字数组) - 应禁用的按钮索引列表
77- - ` userInterfaceStyle ` (字符串) - 用于操作表的界面样式,可以设置为 ` light ` 或 ` dark ` ,否则将使用默认的系统样式
78-
79- ` callback ` 函数则仅接受一个参数,即所点击按钮的索引。
76+ - ` options ` (字符串数组)- 按钮标题列表(必需)
77+ - ` cancelButtonIndex ` (整数)- ` options ` 中取消按钮的索引
78+ - ` cancelButtonTintColor ` (字符串)- 用于改变取消按钮文本颜色的[ 颜色] ( colors ) 值
79+ - ` destructiveButtonIndex ` (整数或整数数组)- ` options ` 中破坏性按钮的索引
80+ - ` title ` (字符串)- 显示在操作表上方的标题
81+ - ` message ` (字符串)- 显示在标题下方的消息
82+ - ` anchor ` (数字)- 操作表应锚定的节点(用于 iPad)
83+ - ` tintColor ` (字符串)- 用于非破坏性按钮标题的[ 颜色] ( colors ) 值
84+ - ` disabledButtonIndices ` (数字数组)- 应禁用的按钮索引列表
85+ - ` userInterfaceStyle ` (字符串)- 用于操作表的界面样式,可以设置为 ` light ` 或 ` dark ` ,否则将使用默认的系统样式
8086
81- 一个例子:
87+ ` callback ` 函数仅接受一个参数,即所点击按钮的从零开始的索引。
8288
83- ```
84- ActionSheetIOS.showActionSheetWithOptions({
85- options: ['取消', '删除'],
86- destructiveButtonIndex: 1,
87- cancelButtonIndex: 0,
88- },
89- (buttonIndex) => {
90- if (buttonIndex === 1) { /* 当接收到的索引为1,即点击了删除按钮时,执行对应操作 */ }
91- });
89+ 一个简单的例子:
90+
91+ ``` tsx
92+ ActionSheetIOS .showActionSheetWithOptions (
93+ {
94+ options: [' Cancel' , ' Remove' ],
95+ destructiveButtonIndex: 1 ,
96+ cancelButtonIndex: 0 ,
97+ },
98+ buttonIndex => {
99+ if (buttonIndex === 1 ) {
100+ /* destructive action */
101+ }
102+ },
103+ );
92104```
93105
94106---
@@ -113,18 +125,20 @@ static showShareActionSheetWithOptions: (
113125);
114126```
115127
116- 在 iOS 设备上显示一个分享弹出框,其中` options ` 参数为一个对象,其属性包含以下几项(必须至少有 message 或 url):
128+ 在 iOS 设备上显示一个分享弹出框,其中 ` options ` 参数为一个对象,必须包含 ` message ` 或 ` url ` 中的至少一项,还可以额外指定 ` subject ` 或 ` excludedActivityTypes ` :
117129
118- - ` url ` (字符串) - 要分享的 URL 地址
119- - ` message ` (字符串) - 要分享的信息
120- - ` subject ` (字符串) - 要分享的信息主题
121- - ` excludedActivityTypes ` (数组) - 指定在 actionsheet 中不显示的活动
130+ - ` url ` (字符串)- 要分享的 URL 地址
131+ - ` message ` (字符串)- 要分享的信息
132+ - ` subject ` (字符串)- 要分享的信息主题
133+ - ` excludedActivityTypes ` (数组)- 指定在 ActionSheet 中不显示的活动
122134
123- 注:如果` url ` 指向本地文件,或者是一个 base64 编码的 url,则会直接读取并分享相应的文件。你可以用这样的方式来分享图片、视频以及 PDF 文件等。If ` url ` points to a remote file or address it must conform to URL format as described in [ RFC 2396] ( https://www.ietf.org/rfc/rfc2396.txt ) . For example, a web URL without a proper protocol (HTTP/HTTPS) will not be shared.
135+ ::: note
136+ 如果 ` url ` 指向本地文件,或者是一个 base64 编码的 URI,则会直接读取并分享相应的文件。你可以用这种方式来分享图片、视频以及 PDF 文件等。如果 ` url ` 指向远程文件或地址,则必须符合 [ RFC 2396] ( https://www.ietf.org/rfc/rfc2396.txt ) 中描述的 URL 格式。例如,不带正确协议(HTTP/HTTPS)的网址将无法被分享。
137+ :::
124138
125- ` failureCallback ` 函数仅接受一个错误对象参数。此对象中仅包含一个可选的` stack ` 属性,类型为字符串。
139+ ` failureCallback ` 函数仅接受一个错误对象参数。此对象中仅包含一个可选的 ` stack ` 属性,类型为字符串。
126140
127- ` successCallback ` 函数接受两个参数:
141+ ` successCallback ` 函数接受两个参数:
128142
129- - 表示成功与否的布尔值
130- - 成功的话返回一个表示分享方式的字符串
143+ - 一个表示成功与否的布尔值
144+ - 成功时返回一个表示分享方式的字符串
0 commit comments