[英]React Navigation Invariant violation: Attempt to get native tag
I am getting an error when trying to set up a simple navigation app using react-navigation. 尝试使用react-navigation设置简单的导航应用程序时出错。
Here's index.js: 这是index.js:
/** @format */
import { AppRegistry } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import SecondScreen from './app/screens/SecondScreen';
import FirstScreen from './app/screens/FirstScreen';
import { name as appName } from './app.json';
const App = createStackNavigator(
{
SecondScreen,
FirstScreen,
},
{
initialRouteName: 'FirstScreen',
},
);
AppRegistry.registerComponent(appName, () => App);
Here's FirstScreen.js: 这是FirstScreen.js:
import React, { Component } from 'react';
import { Button } from 'react-native';
export default class ReadingScreen extends Component {
static navigationOptions = {
header: null,
};
render() {
return <Button title="CLICK ME" onPress={this.props.navigation.navigate('SelectScreen')} />;
}
}
When I make the initial screen the SecondScreen everything is fine, but when it's like this I get this error: 当我在初始屏幕上创建SecondScreen一切都很好,但是当它像这样时我得到这个错误:
Invariant Violation: Attempt to get native tag from node not marked as "native"
Help would be appreciated! 帮助将不胜感激! I've been looking for a solution all day!
我一整天都在寻找解决方案!
Here are my versions: 这是我的版本:
"react": "16.4.1",
"react-native": "0.56.0",
"react-navigation": "^2.12.0"
Same error, i can't navigate, it just hangs out and throws same error but when i am debugging remotely it works, i think it has to do with cocoa pods being installed in xcode project or something. 相同的错误,我无法导航,它只是挂出并抛出相同的错误,但当我远程调试它工作,我认为它与xcode项目中安装的可可豆荚有关。 Weird thing is that a few days ago this project did run OK.
奇怪的是,前几天这个项目确实运行良好。
The only different thing i did is to reinstall and update dependences in react, maybe it's an error on current react-navigation version i was version 2.11.2 and when now it is 2.12. 我做的唯一不同的事情是重新安装和更新react的依赖,也许这是当前的反应导航版本的错误我是2.11.2版本,现在它是2.12。
Yes!! 是!! Solved it, it was the version.
解决了它,它是版本。 I downgrated react-navigation from 2.12.0 to 2.11.2 and it worked!
我将反应导航从2.12.0降级到2.11.2并且工作正常!
I think its to do with your button component. 我认为这与你的按钮组件有关。 You need to pass a function:
你需要传递一个函数:
so instead of: 而不是:
onPress={this.props.navigation.navigate('SelectScreen')}
you do: 你做:
onPress={() => this.props.navigation.navigate('SelectScreen')}
Full code: 完整代码:
export default class ReadingScreen extends Component {
static navigationOptions = {
header: null,
};
render() {
const { navigate } = this.props.navigation
return <Button title="CLICK ME" onPress={() => navigate('SelectScreen')} />;
}
}
I'm getting the same error. 我收到同样的错误。 The weird thing is, it's working as it should when I'm debugging JS remotely.
奇怪的是,当我远程调试JS时,它的工作正常。
Also I noticed it only happens when I try to navigate to another screen in the stack navigator I'm already in (basically, when I try to push a screen to the stack). 另外我注意到它只发生在我尝试导航到我已经在的堆栈导航器中的另一个屏幕时(基本上,当我尝试将屏幕推到堆栈时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.