罗广聪

share

... ... @@ -10,6 +10,7 @@ import {
TouchableOpacity,
Clipboard,
Alert,
Share
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
... ... @@ -17,9 +18,9 @@ export default class Discover extends Component {
constructor(props) {
super(props);
this.state = {
// image: "",
word: "",
date: {}
date: {},
result: ""
};
}
handleCopyPress(string) {
... ... @@ -62,6 +63,38 @@ export default class Discover extends Component {
copyWords(string) {
Clipboard.setString(string);
}
ShareSomething() {
const that = this;
console.log("share")
Share.share({
title: "保护神",
message: that.state.word,
url: "http://www.baidu.com"
// url: `http://reactnative.cn/docs/0.48/share.html?userid=${1}&articleid=${2}`
},{
// dialogTitle: 'Share React Native website',
excludedActivityTypes: [
'com.apple.UIKit.activity.PostToTwitter'
],
tintColor: 'green'
})
.then(that._showResult)
.catch(error => this.setState({ result: "error: " + error.message }));
}
_showResult(result) {
if (result.action === Share.sharedAction) {
if (result.activityType) {
this.setState({
result: "shared with an activityType: " + result.activityType
});
} else {
this.setState({ result: "shared" });
}
} else if (result.action === Share.dismissedAction) {
this.setState({ result: "dismissed" });
}
}
render() {
const { word, date } = this.state;
return (
... ... @@ -79,10 +112,26 @@ export default class Discover extends Component {
<View style={styles.wordConatier}>
<Text style={styles.word}>{word}</Text>
</View>
<TouchableOpacity style={styles.button} onPress={() => {this.copyWords(word)}}>
<Image style={styles.btnImg} source={require("../../assets/discover/ic_copy.png")} />
<TouchableOpacity
style={styles.button}
onPress={() => {
this.copyWords(word);
}}
>
<Image
style={styles.btnImg}
source={require("../../assets/discover/ic_copy.png")}
/>
<Text style={styles.btnText}>复制文案</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.shareContaier}
onPress={() => {
this.ShareSomething();
}}
>
<Text style={styles.shareText}>分享</Text>
</TouchableOpacity>
</Image>
);
}
... ... @@ -128,7 +177,7 @@ const styles = StyleSheet.create({
paddingLeft: 22,
paddingRight: 22,
paddingTop: 28,
paddingBottom: 28,
paddingBottom: 28
},
word: {
fontSize: 15,
... ... @@ -142,15 +191,29 @@ const styles = StyleSheet.create({
justifyContent: "center",
alignItems: "center",
position: "absolute",
bottom: 150,
bottom: 150
},
btnImg: {
width: 13,
height: 15,
marginRight: 5,
marginRight: 5
},
btnText: {
color: "white",
fontSize: 15,
fontSize: 15
},
shareContaier: {
width: Dimensions.get("window").width - 40,
backgroundColor: "#1B9341",
justifyContent: "center",
alignItems: "center",
marginVertical: 20,
paddingVertical: 10,
marginHorizontal: 20,
borderRadius: 5
},
shareText: {
color: "white",
fontSize: 15
}
});
... ...