{"id":509,"date":"2023-02-25T14:24:30","date_gmt":"2023-02-25T06:24:30","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=509"},"modified":"2023-04-29T20:46:38","modified_gmt":"2023-04-29T12:46:38","slug":"react-native-learning-actionsheetios-api","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/react-native-learning-actionsheetios-api\/","title":{"rendered":"React Native\u5b66\u4e60\u4e4bActionSheetIOS API"},"content":{"rendered":"<p>\u9700\u6c42\uff1a\u5206\u4eab\u548c\u5f39\u51fa\u591a\u9879\u9009\u62e9\u64cd\u4f5c\uff01\u5728IOS\u5f00\u53d1\u4e2d\uff0cActionSheet\u63d0\u4f9b\u4e86\u8fd9\u6837\u7684\u529f\u80fd\uff0c\u800cReact Native\u540c\u6837\u5c01\u88c5\u4e86\u8be5\u529f\u80fd\uff0c\u90a3\u5c31\u662f<code>ActionSheetIOS<\/code><\/p>\n<p>\u63d0\u4f9b\u4e86\u4e24\u4e2a\u9759\u6001\u65b9\u6cd5\uff1a<code>showActionSheetWithOptions<\/code>\u548c<code>showShareActionSheetWithOptions<\/code><\/p>\n<p><!-- more --><\/p>\n<h3>showActionSheetWithOptions<\/h3>\n<pre><code>static showActionSheetWithOptions(options, callback)<\/code><\/pre>\n<p>\u5728iOS\u8bbe\u5907\u4e0a\u663e\u793a\u4e00\u4e2aActionSheet\u5f39\u51fa\u6846\uff0c\u5176\u4e2doptions\u53c2\u6570\u4e3a\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u5c5e\u6027\u5fc5\u987b\u5305\u542b\u4ee5\u4e0b\u4e00\u9879\u6216\u591a\u9879\uff1a<\/p>\n<ul>\n<li><code>options<\/code>\uff08\u5b57\u7b26\u4e32\u6570\u7ec4\uff09\uff1a\u4e00\u7ec4\u6309\u94ae\u7684\u6807\u9898\uff08\u5fc5\u9009\uff09<\/li>\n<li><code>cancelButtonIndex<\/code>\uff08\u6574\u578b\uff09\uff1a\u9009\u9879\u4e2d\u53d6\u6d88\u6309\u94ae\u6240\u5728\u7684\u4f4d\u7f6e\uff08\u7d22\u5f15\uff09<\/li>\n<li><code>destructiveButtonIndex<\/code>\uff08\u6574\u578b\uff09\uff1a\u7ea2\u8272\u9ad8\u4eae\u663e\u793a\u7684\u4f4d\u7f6e\uff08\u7d22\u5f15\uff09<\/li>\n<li><code>title<\/code>\uff08\u5b57\u7b26\u4e32\uff09\uff1a\u5f39\u51fa\u6846\u9876\u90e8\u7684\u6807\u9898<\/li>\n<li><code>message<\/code>\uff08\u5b57\u7b26\u4e32\uff09\uff1a\u5f39\u51fa\u6846\u9876\u90e8\u6807\u9898\u4e0b\u65b9\u7684\u4fe1\u606f<\/li>\n<\/ul>\n<h3>showShareActionSheetWithOptions<\/h3>\n<pre><code>static showShareActionSheetWithOptions(options, failureCallback, successCallback)<\/code><\/pre>\n<p>\u5728iOS\u8bbe\u5907\u4e0a\u663e\u793a\u4e00\u4e2a\u5206\u4eab\u5f39\u51fa\u6846\uff0c\u5176\u4e2doptions\u53c2\u6570\u4e3a\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u5c5e\u6027\u5fc5\u987b\u5305\u542b\u4ee5\u4e0b\u4e00\u9879\u6216\u591a\u9879\uff1a<\/p>\n<ul>\n<li><code>message<\/code>\uff08\u5b57\u7b26\u4e32\uff09\uff1a\u8981\u5206\u4eab\u7684\u4fe1\u606f<\/li>\n<li><code>url<\/code>\uff08\u5b57\u7b26\u4e32\uff09\uff1a\u8981\u5206\u4eab\u7684URL\u5730\u5740<\/li>\n<\/ul>\n<blockquote>\n<p>\u6ce8\uff1a\u5982\u679curl\u6307\u5411\u672c\u5730\u6587\u4ef6\uff0c\u6216\u8005\u662f\u4e00\u4e2abase64\u7f16\u7801\u7684url\uff0c\u5219\u4f1a\u76f4\u63a5\u8bfb\u53d6\u5e76\u5206\u4eab\u76f8\u5e94\u7684\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u7528\u8fd9\u6837\u7684\u65b9\u5f0f\u6765\u5206\u4eab\u56fe\u7247\u3001\u89c6\u9891\u4ee5\u53caPDF\u6587\u4ef6\u7b49\u3002<\/p>\n<\/blockquote>\n<p>\u8303\u4f8b\uff1a<\/p>\n<pre><code class=\"language-javascript\">\/**\n * Sample React Native App\n * https:\/\/github.com\/facebook\/react-native\n * @flow\n *\/\n\nimport React, { Component } from &#039;react&#039;;\nimport {\n    AppRegistry,\n    StyleSheet,\n    Text,\n    View,\n    ActionSheetIOS,\n} from &#039;react-native&#039;;\n\nclass RNAPP extends Component {\n    render() {\n        return (\n            &lt;View style={styles.container}&gt;\n                &lt;Text style={styles.item} onPress={this.tip} &gt;showActionSheetWithOptions&lt;\/Text&gt;\n                &lt;Text style={styles.item} onPress={this.share} &gt;showShareActionSheetWithOptions&lt;\/Text&gt;\n            &lt;\/View&gt;\n        );\n    }\n\n    tip(){\n        ActionSheetIOS.showActionSheetWithOptions(\n            {\n                options: [&#039;\u62e8\u6253\u7535\u8bdd&#039;, &#039;\u53d1\u9001\u90ae\u4ef6&#039;, &#039;\u53d1\u9001\u77ed\u4fe1&#039;, &#039;\u53d6\u6d88&#039;],\n                cancelButtonIndex: 3,\n                destructiveButtonIndex: 0,\n                title: &#039;\u64cd\u4f5c&#039;,\n                message: &#039;\u8bf7\u9009\u62e9\u60a8\u7684\u64cd\u4f5c&#039;,\n            },\n            function(index) {\n                alert(index);\n            }\n        );\n    }\n\n    share() {\n        ActionSheetIOS.showShareActionSheetWithOptions(\n            {\n                message:&#039;React Native App \u5f00\u53d1\u793e\u533a&#039;,\n                url:&#039;http:\/\/www.rnapp.cc\/&#039;\n            },\n            function(err) {\n                alert(err);\n            },\n            function(suc) {\n                alert(suc);\n            }\n        );\n    }\n}\n\nconst styles = StyleSheet.create({\n    container: {\n        flex: 1,\n        marginTop:20,\n    },\n    item:{\n        marginTop:10,\n        marginLeft:5,\n        marginRight:5,\n        height:30,\n        borderWidth:1,\n        padding:6,\n        borderColor:&#039;#ddd&#039;,\n    }\n});\n\nAppRegistry.registerComponent(&#039;RNAPP&#039;, () =&gt; RNAPP);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1a\u5206\u4eab\u548c\u5f39\u51fa\u591a\u9879\u9009\u62e9\u64cd\u4f5c\uff01\u5728IOS\u5f00\u53d1\u4e2d\uff0cActionSheet\u63d0\u4f9b\u4e86\u8fd9\u6837\u7684\u529f\u80fd\uff0c\u800cReact Nativ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[163],"tags":[],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-react-native"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=509"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/509\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}