Android 导航屏幕-反应本机
我创建了一个简单的Android应用程序,当文本被按下时,它会改变导航。应用程序运行正常,但当我触摸文本时,内容不会改变,也不会观察到导航。您可以查看错误。我还提供了代码:Android 导航屏幕-反应本机,android,react-native,react-native-android,react-native-navigation,Android,React Native,React Native Android,React Native Navigation,我创建了一个简单的Android应用程序,当文本被按下时,它会改变导航。应用程序运行正常,但当我触摸文本时,内容不会改变,也不会观察到导航。您可以查看错误。我还提供了代码: import React, { Component, PropTypes } from 'react'; import { Navigator, Text, TouchableHighlight, View, AppRegistry} from 'react-native'; export default class S
import React, { Component, PropTypes } from 'react';
import { Navigator, Text, TouchableHighlight, View, AppRegistry} from
'react-native';
export default class SimpleNavigationApp extends Component {
constructor(props){
super(props);
this.state={
title: 'My Initial Scene',
}
}
render() {
return (
<Navigator
initialRoute={{ title: 'My Initial Scene', index: 0 }}
renderScene={(route, navigator) =>
<MyScene
title={route.title}
// Function to call when a new scene should be displayed
onForward={ () => {
const nextIndex = route.index + 1;
navigator.push({
title: 'Scene ' + nextIndex,
index: nextIndex,
});
}}
// Function to call to go back to the previous scene
onBack={() => {
if (route.index > 0) {
navigator.pop();
}
}}
/>
}
/>
)
}
}
class dhrumil extends Component {
static propTypes = {
title: PropTypes.string.isRequired,
onForward: PropTypes.func.isRequired,
onBack: PropTypes.func.isRequired,
}
render() {
return (
<View>
<Text>Current Scene: { this.props.title }</Text>
<TouchableHighlight onPress={this.props.onForward}>
<Text>Tap me to load the next scene</Text>
</TouchableHighlight>
<TouchableHighlight onPress={this.props.onBack}>
<Text>Tap me to go back</Text>
</TouchableHighlight>
</View>
)
}
}
AppRegistry.registerComponent("dhrumil",()=>dhrumil);
import React,{Component,PropTypes}来自'React';
从导入{Navigator、Text、TouchableHighlight、View、AppRegistry}
“反应自然”;
导出默认类SimpleNavigationApp扩展组件{
建造师(道具){
超级(道具);
这个州={
标题:“我的第一场戏”,
}
}
render(){
返回(
{
const nextIndex=route.index+1;
导航器。推({
标题:“场景”+nextIndex,
索引:nextIndex,
});
}}
//函数调用以返回到上一个场景
onBack={()=>{
如果(route.index>0){
navigator.pop();
}
}}
/>
}
/>
)
}
}
类dhrumil扩展组件{
静态类型={
标题:PropTypes.string.isRequired,
onForward:PropTypes.func.isRequired,
onBack:PropTypes.func.isRequired,
}
render(){
返回(
当前场景:{this.props.title}
轻触我以加载下一个场景
轻拍我回去
)
}
}
AppRegistry.registerComponent(“dhrumil”,()=>dhrumil);
正如您在错误中看到的,标题也不会显示在文本“My Current Scene:”之后。如何解决此问题?首先,您的导出默认类SimpleNavigationApp从未被调用 您应该将它放在另一个js文件中,并将其导入到dhrumil类中 秒, 不再支持从“react native”导入{Navigator} 请阅读详细的导航文档