我刚刚将RNN更新到了版本2,但我第一次按下就卡住了
我收到错误消息:
undefined is not an object (evaluating '_reactNativeNavigation.default.push')
关于堆栈溢出的其他答案到目前为止对我没有多大帮助
我想我的问题与this.props.componentId
有关,但是我在官方文档中也找不到任何帮助。
或者它可能是由于对堆栈的错误调用造成的,因为我从未使用过App.js
中设置的id属性
我还想知道是否必须为每个屏幕手动提供一个ID,或者如文档中所述,它将由RNN自动完成
如果有人可以引导我,我会迷失-_-
我的代码:
App.js
import { Navigation } from 'react-native-navigation';
import { Provider } from 'react-redux';
import LandingScreen from './src/screens/Landing/Landing';
import AuthScreen from './src/screens/Auth/Auth';
import configureStore from './src/store/configureStore';
import strings from './src/global/strings';
const store = configureStore();
// Landing
Navigation.registerComponentWithRedux(strings.screens.screenLanding, () => LandingScreen, Provider, store);
// Auth
Navigation.registerComponentWithRedux(strings.screens.screenAuth, () => AuthScreen, Provider, store);
// Start App
Navigation.events().registerAppLaunchedListener(() => {
Navigation.setRoot({
root: {
stack:{
id:"appStack",
children: [
{
component: {
name: strings.screens.screenLanding,
options: {
topBar:{
title:{
text:"Welcome"
}
}
}
}
}
]
},
}
});
});
Landing.js
import React, { Component } from 'react';
import { View, Button } from 'react-native';
import Navigation from 'react-native-navigation';
import strings from '../../global/strings';
class Landing extends Component {
goToScreen = (screenName) => {
Navigation.push(this.props.componentId, {
component: {
name: screenName
}
})
}
render() {
return (
<View>
<Button
title="Connexion"
onPress={() => this.goToScreen(strings.screens.screenAuth.toString())}
/>
</View>
)
}
}
export default Landing;
答案 0 :(得分:1)
,如{strong> jinshin1013 在RNN issue tracker在Landing.js中的
所示我应该具有这样的导入导航:
import { Navigation } from 'react-native-navigation