按照本教程,我发现了这个错误。我不确定这是我的错,还是代码中的错误。
Share.share似乎不起作用。我在网上找不到任何关于这个函数的东西。
错误消息

Share.js
import React, { Component } from 'react'
import { View, Text, StyleSheet, Image, TouchableHighlight } from 'react-native'
class Share extends Component {
constructor(props){
super(props);
this._shareMessage = this._shareMessage.bind(this);
this._showResult = this._showResult.bind(this);
this.state = {result: 'Hello'};
}
_showResult(result){
this.setState({result})
}
_shareMessage() {
Share.share({
message: 'This is a fancy shared message'
}).then(this._showResult);
}
render(){
return (
<View style={styles.container}>
<TouchableHighlight onPress = {this._shareMessage}>
<Text style={styles.text}>Share</Text>
</TouchableHighlight>
<Text>
{JSON.stringify(this.state.result)}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#10a2f0',
alignItems: 'center'
},
text: {
color: 'rgb(0,10,200)',
marginTop: 100,
fontSize: 24,
textAlign: 'center'
},
image: {
width: 250,
height: 250
}
})
export default Share发布于 2017-02-01 15:35:12
您还需要导入Share类:
import { View, Text, StyleSheet, Image, TouchableHighlight, Share } from 'react-native'此外,您还应该将类名更改为其他名称(如ShareExample)
尽量使用this文档。
https://stackoverflow.com/questions/41967251
复制相似问题