罗广聪

share

@@ -8,14 +8,33 @@ import { @@ -8,14 +8,33 @@ import {
8 ScrollView, 8 ScrollView,
9 Text, 9 Text,
10 FlatList, 10 FlatList,
11 - ListView 11 + ListView,
  12 + Share,
  13 + TouchableOpacity,
  14 + AsyncStorage
12 } from "react-native"; 15 } from "react-native";
13 import { StackNavigator, TabNavigator } from "react-navigation"; 16 import { StackNavigator, TabNavigator } from "react-navigation";
  17 +import post from "../utils/fetch";
14 18
15 export default class ArticleTemplate extends Component { 19 export default class ArticleTemplate extends Component {
  20 + static navigationOptions = ({ navigation }) => {
  21 + const { state, setParams, navigate } = navigation;
  22 + return {
  23 + headerRight: (
  24 + <TouchableOpacity
  25 + style={{ marginRight: 13 }}
  26 + onPress={() => state.params.share()}
  27 + >
  28 + <Text>分享</Text>
  29 + </TouchableOpacity>
  30 + )
  31 + };
  32 + };
16 constructor(props) { 33 constructor(props) {
17 super(props); 34 super(props);
18 this.state = { 35 this.state = {
  36 + IS_LOGIN: '',
  37 + USER_ID: '',
19 id: this.props.navigation.state.params.item.id, 38 id: this.props.navigation.state.params.item.id,
20 model: this.props.navigation.state.params.model, 39 model: this.props.navigation.state.params.model,
21 articleData: { 40 articleData: {
@@ -23,9 +42,44 @@ export default class ArticleTemplate extends Component { @@ -23,9 +42,44 @@ export default class ArticleTemplate extends Component {
23 } 42 }
24 }; 43 };
25 } 44 }
  45 +
26 componentWillMount() { 46 componentWillMount() {
27 console.log("will model", this.state.model); 47 console.log("will model", this.state.model);
28 this.getArticles(); 48 this.getArticles();
  49 + this.getAsyncStorage();
  50 + this.props.navigation.setParams({
  51 + share: this.share.bind(this)
  52 + });
  53 + }
  54 + share() {
  55 + const that = this;
  56 + console.log("share")
  57 + Share.share({
  58 + title: "保护神",
  59 + message: this.state.articleData.title,
  60 + url: `https://devpay.brae.co/insurance.html?uid=${this.state.USER_ID}&sid=${this.state.id}`
  61 + },{
  62 + // dialogTitle: 'Share React Native website',
  63 + excludedActivityTypes: [
  64 + 'com.apple.UIKit.activity.PostToTwitter'
  65 + ],
  66 + tintColor: 'green'
  67 + })
  68 + .then(that._showResult)
  69 + .catch(error => this.setState({ result: "error: " + error.message }));
  70 + }
  71 +
  72 + getAsyncStorage() {
  73 + const that = this;
  74 + AsyncStorage.multiGet(["IS_LOGIN", "USER_ID"], (err, result) => {
  75 + if (err) {
  76 + console.error(err);
  77 + }
  78 + that.setState({
  79 + IS_LOGIN: result[0][1],
  80 + USER_ID: result[1][1] != null ? result[1][1] : ""
  81 + });
  82 + });
29 } 83 }
30 getArticles() { 84 getArticles() {
31 let that = this, 85 let that = this,
@@ -8,6 +8,7 @@ import { @@ -8,6 +8,7 @@ import {
8 TouchableWithoutFeedback, 8 TouchableWithoutFeedback,
9 View, 9 View,
10 } from 'react-native'; 10 } from 'react-native';
  11 +import post from "../../utils/fetch";
11 12
12 const questions = [ 13 const questions = [
13 { question: '早上起床时,有持续的发丝掉落。', score: 5 }, 14 { question: '早上起床时,有持续的发丝掉落。', score: 5 },