罗广聪

share

... ... @@ -8,14 +8,33 @@ import {
ScrollView,
Text,
FlatList,
ListView
ListView,
Share,
TouchableOpacity,
AsyncStorage
} from "react-native";
import { StackNavigator, TabNavigator } from "react-navigation";
import post from "../utils/fetch";
export default class ArticleTemplate extends Component {
static navigationOptions = ({ navigation }) => {
const { state, setParams, navigate } = navigation;
return {
headerRight: (
<TouchableOpacity
style={{ marginRight: 13 }}
onPress={() => state.params.share()}
>
<Text>分享</Text>
</TouchableOpacity>
)
};
};
constructor(props) {
super(props);
this.state = {
IS_LOGIN: '',
USER_ID: '',
id: this.props.navigation.state.params.item.id,
model: this.props.navigation.state.params.model,
articleData: {
... ... @@ -23,9 +42,44 @@ export default class ArticleTemplate extends Component {
}
};
}
componentWillMount() {
console.log("will model", this.state.model);
this.getArticles();
this.getAsyncStorage();
this.props.navigation.setParams({
share: this.share.bind(this)
});
}
share() {
const that = this;
console.log("share")
Share.share({
title: "保护神",
message: this.state.articleData.title,
url: `https://devpay.brae.co/insurance.html?uid=${this.state.USER_ID}&sid=${this.state.id}`
},{
// dialogTitle: 'Share React Native website',
excludedActivityTypes: [
'com.apple.UIKit.activity.PostToTwitter'
],
tintColor: 'green'
})
.then(that._showResult)
.catch(error => this.setState({ result: "error: " + error.message }));
}
getAsyncStorage() {
const that = this;
AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => {
if (err) {
console.error(err);
}
that.setState({
IS_LOGIN: result[0][1],
USER_ID: result[1][1] != null ? result[1][1] : ""
});
});
}
getArticles() {
let that = this,
... ...
... ... @@ -8,6 +8,7 @@ import {
TouchableWithoutFeedback,
View,
} from 'react-native';
import post from "../../utils/fetch";
const questions = [
{ question: '早上起床时,有持续的发丝掉落。', score: 5 },
... ...