2017-09-17 35 views
0

我正在尝试导航beteween屏幕,但我不知道如何导航后的第一个屏幕。这个问题也是关于类的导航,因为所有的例子只显示常量内的道具。在注册表中第二次导航

文件:index.android.js

const AppNative = props => { 
return <AppScreen navigation={props.navigation} />; 
}; 
const MyApp = DrawerNavigator({ 
    Home: { screen: AppNative }, 
    Register: { screen: Register }, 
}); 
AppRegistry.registerComponent("AppNative",() => MyApp); 

文件:App.js

const AppScreen = props => { 
    const { navigate } = props.navigation; 
    return (
    <View> 
     <Button 
     navigation={props.navigation} 
     onPress={() => navigate("Register")} 
     title="Cadastrar com email" 
     /> 
    </View> 
); 
}; 
export default AppScreen; 

文件:Register.js当我在点击链接

class Register extends Component { 
    constructor(props) { 
    super(props); 
    } 
    render() { 
    const { navigate } = this.props.navigation; 
    //?????? 
    const RegisterNav = DrawerNavigator({ 
     Register: { screen: Register }, 
     OtherScreen: { screen: OtherScreen }, 
    }); 
    return (
     <View> 
      //?????? 
      <Button onPress={() => navigate("OtherScreen")}> 
      Entrar 
      </Button> 
     </View> 
     ); 
    } 
} 
export default Register; 

什么也没有发生文件Register.js

个相关性(的package.json):

"dependencies": { 
    "apsl-react-native-button": "^3.1.0", 
    "react": "16.0.0-alpha.12", 
    "react-native": "^0.48.2", 
    "react-native-maps": "^0.16.2", 
    "react-navigation": "^1.0.0-beta.11" 
}, 
+0

需要我声明我的所有屏幕js上有我的注册表? – bpedroso

回答

1

您正在试图内RegisterNav导航,但是导航方法属于你MyApp导航仪。

如果你在同一个导航器中声明所有的屏幕,它应该可以工作。

const MyApp = DrawerNavigator({ 
    Home: { screen: AppNative }, 
    Register: { screen: Register }, 
    OtherScreen: { screen: OtherScreen }, 
}); 
+0

我应该只有所有应用程序的导航器? – bpedroso

+0

不一定,你也可以嵌套导航器(https://reactnavigation.org/docs/intro/nesting),如果你想从导航器外部导航不要忘记传递'导航'道具'' – Freez

+0

不确定它是否适用于抽屉导航器,文档仅包含关于包含TabNavigator的StackNavigator – Freez