Showing
1 changed file
with
71 additions
and
8 deletions
| @@ -10,6 +10,7 @@ import { | @@ -10,6 +10,7 @@ import { | ||
| 10 | TouchableOpacity, | 10 | TouchableOpacity, |
| 11 | Clipboard, | 11 | Clipboard, |
| 12 | Alert, | 12 | Alert, |
| 13 | + Share | ||
| 13 | } from "react-native"; | 14 | } from "react-native"; |
| 14 | import { StackNavigator, TabNavigator } from "react-navigation"; | 15 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| 15 | 16 | ||
| @@ -17,9 +18,9 @@ export default class Discover extends Component { | @@ -17,9 +18,9 @@ export default class Discover extends Component { | ||
| 17 | constructor(props) { | 18 | constructor(props) { |
| 18 | super(props); | 19 | super(props); |
| 19 | this.state = { | 20 | this.state = { |
| 20 | - // image: "", | ||
| 21 | word: "", | 21 | word: "", |
| 22 | - date: {} | 22 | + date: {}, |
| 23 | + result: "" | ||
| 23 | }; | 24 | }; |
| 24 | } | 25 | } |
| 25 | handleCopyPress(string) { | 26 | handleCopyPress(string) { |
| @@ -62,6 +63,38 @@ export default class Discover extends Component { | @@ -62,6 +63,38 @@ export default class Discover extends Component { | ||
| 62 | copyWords(string) { | 63 | copyWords(string) { |
| 63 | Clipboard.setString(string); | 64 | Clipboard.setString(string); |
| 64 | } | 65 | } |
| 66 | + ShareSomething() { | ||
| 67 | + const that = this; | ||
| 68 | + console.log("share") | ||
| 69 | + Share.share({ | ||
| 70 | + title: "保护神", | ||
| 71 | + message: that.state.word, | ||
| 72 | + url: "http://www.baidu.com" | ||
| 73 | + // url: `http://reactnative.cn/docs/0.48/share.html?userid=${1}&articleid=${2}` | ||
| 74 | + },{ | ||
| 75 | + // dialogTitle: 'Share React Native website', | ||
| 76 | + excludedActivityTypes: [ | ||
| 77 | + 'com.apple.UIKit.activity.PostToTwitter' | ||
| 78 | + ], | ||
| 79 | + tintColor: 'green' | ||
| 80 | + }) | ||
| 81 | + .then(that._showResult) | ||
| 82 | + .catch(error => this.setState({ result: "error: " + error.message })); | ||
| 83 | + } | ||
| 84 | + _showResult(result) { | ||
| 85 | + if (result.action === Share.sharedAction) { | ||
| 86 | + if (result.activityType) { | ||
| 87 | + this.setState({ | ||
| 88 | + result: "shared with an activityType: " + result.activityType | ||
| 89 | + }); | ||
| 90 | + } else { | ||
| 91 | + this.setState({ result: "shared" }); | ||
| 92 | + } | ||
| 93 | + } else if (result.action === Share.dismissedAction) { | ||
| 94 | + this.setState({ result: "dismissed" }); | ||
| 95 | + } | ||
| 96 | + } | ||
| 97 | + | ||
| 65 | render() { | 98 | render() { |
| 66 | const { word, date } = this.state; | 99 | const { word, date } = this.state; |
| 67 | return ( | 100 | return ( |
| @@ -79,10 +112,26 @@ export default class Discover extends Component { | @@ -79,10 +112,26 @@ export default class Discover extends Component { | ||
| 79 | <View style={styles.wordConatier}> | 112 | <View style={styles.wordConatier}> |
| 80 | <Text style={styles.word}>{word}</Text> | 113 | <Text style={styles.word}>{word}</Text> |
| 81 | </View> | 114 | </View> |
| 82 | - <TouchableOpacity style={styles.button} onPress={() => {this.copyWords(word)}}> | 115 | + <TouchableOpacity |
| 83 | - <Image style={styles.btnImg} source={require("../../assets/discover/ic_copy.png")} /> | 116 | + style={styles.button} |
| 117 | + onPress={() => { | ||
| 118 | + this.copyWords(word); | ||
| 119 | + }} | ||
| 120 | + > | ||
| 121 | + <Image | ||
| 122 | + style={styles.btnImg} | ||
| 123 | + source={require("../../assets/discover/ic_copy.png")} | ||
| 124 | + /> | ||
| 84 | <Text style={styles.btnText}>复制文案</Text> | 125 | <Text style={styles.btnText}>复制文案</Text> |
| 85 | </TouchableOpacity> | 126 | </TouchableOpacity> |
| 127 | + <TouchableOpacity | ||
| 128 | + style={styles.shareContaier} | ||
| 129 | + onPress={() => { | ||
| 130 | + this.ShareSomething(); | ||
| 131 | + }} | ||
| 132 | + > | ||
| 133 | + <Text style={styles.shareText}>分享</Text> | ||
| 134 | + </TouchableOpacity> | ||
| 86 | </Image> | 135 | </Image> |
| 87 | ); | 136 | ); |
| 88 | } | 137 | } |
| @@ -128,7 +177,7 @@ const styles = StyleSheet.create({ | @@ -128,7 +177,7 @@ const styles = StyleSheet.create({ | ||
| 128 | paddingLeft: 22, | 177 | paddingLeft: 22, |
| 129 | paddingRight: 22, | 178 | paddingRight: 22, |
| 130 | paddingTop: 28, | 179 | paddingTop: 28, |
| 131 | - paddingBottom: 28, | 180 | + paddingBottom: 28 |
| 132 | }, | 181 | }, |
| 133 | word: { | 182 | word: { |
| 134 | fontSize: 15, | 183 | fontSize: 15, |
| @@ -142,15 +191,29 @@ const styles = StyleSheet.create({ | @@ -142,15 +191,29 @@ const styles = StyleSheet.create({ | ||
| 142 | justifyContent: "center", | 191 | justifyContent: "center", |
| 143 | alignItems: "center", | 192 | alignItems: "center", |
| 144 | position: "absolute", | 193 | position: "absolute", |
| 145 | - bottom: 150, | 194 | + bottom: 150 |
| 146 | }, | 195 | }, |
| 147 | btnImg: { | 196 | btnImg: { |
| 148 | width: 13, | 197 | width: 13, |
| 149 | height: 15, | 198 | height: 15, |
| 150 | - marginRight: 5, | 199 | + marginRight: 5 |
| 151 | }, | 200 | }, |
| 152 | btnText: { | 201 | btnText: { |
| 153 | color: "white", | 202 | color: "white", |
| 154 | - fontSize: 15, | 203 | + fontSize: 15 |
| 204 | + }, | ||
| 205 | + shareContaier: { | ||
| 206 | + width: Dimensions.get("window").width - 40, | ||
| 207 | + backgroundColor: "#1B9341", | ||
| 208 | + justifyContent: "center", | ||
| 209 | + alignItems: "center", | ||
| 210 | + marginVertical: 20, | ||
| 211 | + paddingVertical: 10, | ||
| 212 | + marginHorizontal: 20, | ||
| 213 | + borderRadius: 5 | ||
| 214 | + }, | ||
| 215 | + shareText: { | ||
| 216 | + color: "white", | ||
| 217 | + fontSize: 15 | ||
| 155 | } | 218 | } |
| 156 | }); | 219 | }); |
-
Please register or login to post a comment