React native 将字符串共享到其他不在react native中工作的本机应用程序
我一直在遵循教程,但是,当我在删除代码后运行应用程序时,它似乎不起作用。教程似乎相当简单,所以我不明白为什么它不起作用 我收到的错误消息是:React native 将字符串共享到其他不在react native中工作的本机应用程序,react-native,React Native,我一直在遵循教程,但是,当我在删除代码后运行应用程序时,它似乎不起作用。教程似乎相当简单,所以我不明白为什么它不起作用 我收到的错误消息是: 从“React”导入React 从“react native”导入{视图、文本、样式表、图像、共享} 类ShareLesson扩展了组件{ 建造师(道具){ 超级(道具); this.\u shareMessage=this.\u shareMessage.bind(this); this.\u showResult=this.\u showResult
从“React”导入React
从“react native”导入{视图、文本、样式表、图像、共享}
类ShareLesson扩展了组件{
建造师(道具){
超级(道具);
this.\u shareMessage=this.\u shareMessage.bind(this);
this.\u showResult=this.\u showResult.bind(this);
this.state={result:''};
}
_showResult(结果){
this.setState({result});
}
_shareMessage(){
分享({
消息:“这是一条简单的共享消息”
}).然后(这个结果);
}
render(){
返回(
分享
{JSON.stringify(this.state.result)}
);
}
}
选项卡组件
类选项卡扩展组件{
_更改表(一){
const{changeTab}=this.props
更改表(一)
}
_renderabcontent(键){
开关(钥匙){
‘今日’个案:
返回
“共享”案例:
返回
案例“savequote”:
返回
“更多菜单”案例:
返回
}
}
渲染(){
const tabs=this.props.tabs.tabs.map((tab,i)=>{
返回(
这个._changeTab(i)}
所选={this.props.tabs.index==i}>
{this.\u renderabcontent(tab.key)}
)
})
返回(
{tabs}
)
}
}
导出默认选项卡
您有选项卡组件吗?这就是错误所在from@MattAft问题已更新。您如何在_renderabcontent中导出/导入组件?从“../components/Share”导入共享从“../components/SaveQuote”导入保存从“../components/SaveQuote”导入主目录从“../containers/navRootContainer”导入更多菜单从“../components/moremon”上方的“
类选项卡扩展组件
在所有这些文件中,确保类前面有导出默认值
,因此对于ShareLesson,它将是导出默认类ShareLesson扩展组件
import React from 'react'
import { View, Text, StyleSheet, Image, Share } from 'react-native'
class ShareLesson extends Component {
constructor(props) {
super(props);
this._shareMessage = this._shareMessage.bind(this);
this._showResult = this._showResult.bind(this);
this.state = { result: ''};
}
_showResult(result) {
this.setState({result});
}
_shareMessage() {
Share.share({
message: 'This is a simple shared message'
}).then(this._showResult);
}
render() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this._shareMessage}>
<Text style={styles.welcome}>
Share
</Text>
</TouchableHighlight>
<Text>
{JSON.stringify(this.state.result)}
</Text>
<View>);
}
}
class Tabs extends Component {
_changeTab (i) {
const { changeTab } = this.props
changeTab(i)
}
_renderTabContent (key) {
switch (key) {
case 'today':
return <Home />
case 'share':
return <Share />
case 'savequote':
return <SaveQuote />
case 'moremenu':
return <MoreMenu />
}
}
render () {
const tabs = this.props.tabs.tabs.map((tab, i) => {
return (
<TabBarIOS.Item key={tab.key}
icon={tab.icon}
selectedIcon={tab.selectedIcon}
title={tab.title}
onPress={() => this._changeTab(i)}
selected={this.props.tabs.index === i}>
{this._renderTabContent(tab.key)}
</TabBarIOS.Item>
)
})
return (
<TabBarIOS tintColor='black'>
{tabs}
</TabBarIOS>
)
}
}
export default Tabs