@@ -7,12 +7,13 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import con
77
88## 示例
99
10- <Tabs groupId =" syntax " defaultValue ={constants.defaultSyntax } values ={constants.syntax } >
11- <TabItem value =" functional " >
10+ <Tabs groupId =" language " queryString defaultValue ={constants.defaultSnackLanguage } values ={constants.snackLanguages } >
11+ <TabItem value =" javascript " >
1212
13- ``` SnackPlayer name=Function%20Component%20Example &supportedPlatforms=ios,android
13+ ``` SnackPlayer name=Example &supportedPlatforms=ios,android&ext=js
1414import React from 'react';
15- import { Share, View, Button } from 'react-native';
15+ import {Alert, Share, Button} from 'react-native';
16+ import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
1617
1718const ShareExample = () => {
1819 const onShare = async () => {
@@ -31,34 +32,36 @@ const ShareExample = () => {
3132 // dismissed
3233 }
3334 } catch (error) {
34- alert(error.message);
35+ Alert. alert(error.message);
3536 }
3637 };
3738 return (
38- <View style={{ marginTop: 50 }}>
39- <Button onPress={onShare} title="Share" />
40- </View>
39+ <SafeAreaProvider>
40+ <SafeAreaView>
41+ <Button onPress={onShare} title="Share" />
42+ </SafeAreaView>
43+ </SafeAreaProvider>
4144 );
4245};
4346
4447export default ShareExample;
4548```
4649
4750</TabItem >
48- <TabItem value =" classical " >
51+ <TabItem value =" typescript " >
4952
50- ``` SnackPlayer name=Class%20Component%20Example&supportedPlatforms=ios,android
51- import React, { Component } from 'react';
52- import { Share, View, Button } from 'react-native';
53+ ``` SnackPlayer name=Example&supportedPlatforms=ios,android&ext=tsx
54+ import React from 'react';
55+ import {Alert, Share, Button} from 'react-native';
56+ import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
5357
54- class ShareExample extends Component {
55- onShare = async () => {
58+ const ShareExample = () => {
59+ const onShare = async () => {
5660 try {
5761 const result = await Share.share({
5862 message:
5963 'React Native | A framework for building native apps using React',
6064 });
61-
6265 if (result.action === Share.sharedAction) {
6366 if (result.activityType) {
6467 // shared with activity type of result.activityType
@@ -68,69 +71,66 @@ class ShareExample extends Component {
6871 } else if (result.action === Share.dismissedAction) {
6972 // dismissed
7073 }
71- } catch (error) {
72- alert(error.message);
74+ } catch (error: any ) {
75+ Alert. alert(error.message);
7376 }
7477 };
75-
76- render() {
77- return (
78- <View style={{ marginTop: 50 }}>
79- <Button onPress={this.onShare} title="Share" />
80- </View>
81- );
82- }
83- }
78+ return (
79+ <SafeAreaProvider>
80+ <SafeAreaView>
81+ <Button onPress={onShare} title="Share" />
82+ </SafeAreaView>
83+ </SafeAreaProvider>
84+ );
85+ };
8486
8587export default ShareExample;
8688```
8789
8890</TabItem >
8991</Tabs >
9092
91- ---
92-
93- # 文档
93+ # 参考文档
9494
9595## 方法
9696
9797### ` share() `
9898
99- ``` jsx
100- static share (content, options)
99+ ``` tsx
100+ static share (content : ShareContent , options ?: ShareOptions );
101101```
102102
103103打开一个对话框来分享文本内容。
104104
105- 在 iOS 中,返回一个 Promise,最终会解析为一个对象,包含有 ` action ` 和 ` activityType ` 两个属性。如果用户取消对话框,则 Promise 仍将被解析,最终返回的 ` action ` 属性会是 ` Share.dismissedAction ` ,而其他属性为 undefined。Note that some share options will not appear or work on the iOS simulator.
105+ 在 iOS 中,返回一个 Promise,最终会解析为一个包含 ` action ` 和 ` activityType ` 的对象。如果用户关闭了对话框, Promise 仍然会被解析,此时 action 为 ` Share.dismissedAction ` ,其他属性均为 undefined。请注意,某些分享选项在 iOS 模拟器上可能无法显示或正常工作。
106106
107- 在 Android 中同样返回一个 Promise,但返回的 ` action ` 始终为` Share.sharedAction ` 。
107+ 在 Android 中,返回一个 Promise,其 action 始终为 ` Share.sharedAction ` 。
108108
109109** 属性:**
110110
111- | 名称 | 类型 | 说明 |
112- | -------------------------------------------------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
113- | content <div className =" label basic required " >必需</div > | object | ` message ` - 要分享的消息<br />` url ` - 要分享的网址 <div class =" label ios " >iOS</div ><br />` title ` - 消息的标题 <div class =" label android " >Android</div ><hr />` url ` 或 ` message ` 至少要提供一个 |
114- | options | object | ` dialogTitle ` <div class =" label android " >Android</div ><br />` excludedActivityTypes ` <div class =" label ios " >iOS</div ><br />` subject ` - 通过邮件分享的标题 <div class =" label ios " >iOS</div ><br />` tintColor ` <div class =" label ios " >iOS</div > |
111+ | 名称 | 类型 | 说明 |
112+ | ------------------------------------------------------------ | ------ | --------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
113+ | content <div className =" label basic required " >必需</div > | object | ` message ` - 要分享的消息<br />` url ` - 要分享的网址 <div className =" label ios " >iOS</div ><br />` title ` - 消息的标题 <div className =" label android " >Android</div ><hr />至少需要提供 ` url ` 或 ` message ` 中的一个。 |
114+ | options | object | ` dialogTitle ` <div className =" label android " >Android</div ><br />` excludedActivityTypes ` <div className =" label ios " >iOS</div ><br />` subject ` - 通过邮件分享时的主题 <div className =" label ios " >iOS</div ><br />` tintColor ` <div className = " label ios " >iOS</ div >< br /> ` anchor ` - 操作表应锚定到的节点(用于 iPad) < div className =" label ios " >iOS</div > |
115115
116116---
117117
118118## 属性
119119
120120### ` sharedAction `
121121
122- ``` jsx
123- static sharedAction
122+ ``` tsx
123+ static sharedAction : ' sharedAction ' ;
124124```
125125
126126表示内容已成功分享。
127127
128128---
129129
130- ### ` dismissedAction ` <div class =" label ios " >iOS</div >
130+ ### ` dismissedAction ` <div className =" label ios " >iOS</div >
131131
132- ``` jsx
133- static dismissedAction
132+ ``` tsx
133+ static dismissedAction : ' dismissedAction ' ;
134134```
135135
136- 表示对话框被取消 。
136+ 表示对话框已被关闭 。
0 commit comments