Showing
1 changed file
with
37 additions
and
6 deletions
| @@ -7,6 +7,8 @@ import { | @@ -7,6 +7,8 @@ import { | ||
| 7 | Dimensions, | 7 | Dimensions, |
| 8 | ScrollView, | 8 | ScrollView, |
| 9 | Text, | 9 | Text, |
| 10 | + Clipboard, | ||
| 11 | + TouchableOpacity | ||
| 10 | } from "react-native"; | 12 | } from "react-native"; |
| 11 | import { StackNavigator, TabNavigator } from "react-navigation"; | 13 | import { StackNavigator, TabNavigator } from "react-navigation"; |
| 12 | 14 | ||
| @@ -15,8 +17,12 @@ export default class Discover extends Component { | @@ -15,8 +17,12 @@ export default class Discover extends Component { | ||
| 15 | super(props); | 17 | super(props); |
| 16 | this.state = { | 18 | this.state = { |
| 17 | image: "", | 19 | image: "", |
| 20 | + word: "", | ||
| 18 | }; | 21 | }; |
| 19 | } | 22 | } |
| 23 | + handleCopyPress(string) { | ||
| 24 | + Clipboard.setString(string); | ||
| 25 | + } | ||
| 20 | componentWillMount() { | 26 | componentWillMount() { |
| 21 | this.getImages(); | 27 | this.getImages(); |
| 22 | } | 28 | } |
| @@ -32,7 +38,7 @@ export default class Discover extends Component { | @@ -32,7 +38,7 @@ export default class Discover extends Component { | ||
| 32 | } | 38 | } |
| 33 | }) | 39 | }) |
| 34 | .then(resp => { | 40 | .then(resp => { |
| 35 | - console.log("大爷",resp); | 41 | + console.log("大爷", resp); |
| 36 | if (resp.status === 200) { | 42 | if (resp.status === 200) { |
| 37 | return resp.json(); | 43 | return resp.json(); |
| 38 | } else { | 44 | } else { |
| @@ -44,23 +50,28 @@ export default class Discover extends Component { | @@ -44,23 +50,28 @@ export default class Discover extends Component { | ||
| 44 | alert(respJson.cnmsg); | 50 | alert(respJson.cnmsg); |
| 45 | } else { | 51 | } else { |
| 46 | that.setState({ | 52 | that.setState({ |
| 47 | - image: respJson.data.image | 53 | + image: respJson.data.image, |
| 54 | + word: respJson.data.word | ||
| 48 | }); | 55 | }); |
| 49 | console.log("图片文章", respJson.data); | 56 | console.log("图片文章", respJson.data); |
| 50 | } | 57 | } |
| 51 | }); | 58 | }); |
| 52 | } | 59 | } |
| 53 | render() { | 60 | render() { |
| 54 | - const { image } = this.state; | 61 | + const { image,word } = this.state; |
| 55 | return ( | 62 | return ( |
| 56 | <View style={styles.container}> | 63 | <View style={styles.container}> |
| 57 | - {/* <Text>图片首页</Text> */} | ||
| 58 | <Image | 64 | <Image |
| 59 | style={styles.image} | 65 | style={styles.image} |
| 60 | - source={{uri: image}} | 66 | + source={{ uri: image }} |
| 61 | resizeMode="contain" | 67 | resizeMode="contain" |
| 62 | > | 68 | > |
| 63 | - <Text>中央文案</Text> | 69 | + <Text selectable={true} style={styles.word}> |
| 70 | + {word} | ||
| 71 | + </Text> | ||
| 72 | + <TouchableOpacity style={styles.button} onPress={() => {this.handleCopyPress(word)}}> | ||
| 73 | + <Text style={styles.buttonText}>复制文案</Text> | ||
| 74 | + </TouchableOpacity> | ||
| 64 | </Image> | 75 | </Image> |
| 65 | </View> | 76 | </View> |
| 66 | ); | 77 | ); |
| @@ -76,6 +87,26 @@ const styles = StyleSheet.create({ | @@ -76,6 +87,26 @@ const styles = StyleSheet.create({ | ||
| 76 | width: Dimensions.get("window").width, | 87 | width: Dimensions.get("window").width, |
| 77 | height: Dimensions.get("window").height, | 88 | height: Dimensions.get("window").height, |
| 78 | justifyContent: "center", | 89 | justifyContent: "center", |
| 90 | + alignItems: "center" | ||
| 91 | + }, | ||
| 92 | + word: { | ||
| 93 | + marginLeft: 15, | ||
| 94 | + marginRight: 15, | ||
| 95 | + fontSize: 15, | ||
| 96 | + lineHeight: 25, | ||
| 97 | + color: "white", | ||
| 98 | + backgroundColor: "rgba(0,0,0,0)" | ||
| 99 | + }, | ||
| 100 | + button: { | ||
| 101 | + width: 80, | ||
| 102 | + height: 40, | ||
| 103 | + marginTop: 20, | ||
| 104 | + backgroundColor: "rgba(0,0,0,0.2)", | ||
| 105 | + justifyContent: "center", | ||
| 79 | alignItems: "center", | 106 | alignItems: "center", |
| 107 | + borderRadius: 5, | ||
| 108 | + }, | ||
| 109 | + buttonText: { | ||
| 110 | + color: "white", | ||
| 80 | } | 111 | } |
| 81 | }); | 112 | }); |
-
Please register or login to post a comment