React-Native Navigator 已弃用并已从此包中删除
React-Native Navigator is deprecated and has been removed from this package
我收到以下错误。
Navigator 已弃用并已从此包中删除。现在可以从 react-native-deprecated-custom-components 而不是 react-native 安装和导入它。在 http://facebook.github.io/react-native/docs/navigation.html
了解替代导航解决方案
然后我会更新 react-native-deprecated-custom-components 包,但问题没有解决
Package.Json
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.2",
"react-native-deprecated-custom-components": "^0.1.0",
"sendbird": "^3.0.30"
},
main.js
var React = require('react-native')
var {
Navigator,
StyleSheet
} = React;
var Login = require('./components/login');
import NavigationExperimental from 'react-native-deprecated-custom-components';
var ROUTES = {
login: Login
};
module.exports = React.createClass({
renderScene: function(route, navigator) {
var Component = ROUTES[route.name];
return <Component route={route} navigator={navigator} />;
},
render: function() {
return (
<NavigationExperimental.Navigator
style={ styles.container }
initialRoute={ {name: 'login'} }
renderScene={this.renderScene}
configureScene={ () => { return Navigator.SceneConfigs.FloatFromRight; } }
/>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1
}
});
谁让我知道如何解决这个问题
您现在应该使用 Stack Navigator
import { StackNavigator } from 'react-navigation';
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
<Button
onPress={() => navigate('Chat')}
title="Chat with Lucy"
/>
我使用下面的代码来解决我的问题
main.js
var React = require('react-native')
var {
Navigator,
StyleSheet
} = React;
var Login = require('./components/login');
import NavigationExperimental from 'react-native-deprecated-custom-components';
var ROUTES = {
login: Login
};
module.exports = React.createClass({
renderScene: function(route, navigator) {
var Component = ROUTES[route.name];
return <Component route={route} navigator={navigator} />;
},
render: function() {
return (
<NavigationExperimental.Navigator
style={ styles.container }
initialRoute={ {name: 'login'} }
renderScene={this.renderScene}
configureScene={ () => { return NavigationExperimental.Navigator.SceneConfigs.FloatFromRight; } }
/>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1
}
});
谁让我知道如何解决这个问题
我改台词了
configureScene={ () => { return NavigationExperimental.Navigator.SceneConfigs.FloatFromRight; } }
到
configureScene={ () => { return NavigationExperimental.Navigator.SceneConfigs.FloatFromRight; } }
解决我的问题
如果有人在甚至没有尝试使用 Navigator
的情况下看到它,那可能是因为您有一个 import
行,例如
import * as RN from 'react-native'
(Webstorm 特别有自动插入这些的习惯)
这会为 RN 的所有导出调用 get
ter,触发 Navigator
的错误。而是使用:
import {Things, You, Need} from 'react-native'
我收到以下错误。
Navigator 已弃用并已从此包中删除。现在可以从 react-native-deprecated-custom-components 而不是 react-native 安装和导入它。在 http://facebook.github.io/react-native/docs/navigation.html
了解替代导航解决方案然后我会更新 react-native-deprecated-custom-components 包,但问题没有解决
Package.Json
"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.2",
"react-native-deprecated-custom-components": "^0.1.0",
"sendbird": "^3.0.30"
},
main.js
var React = require('react-native')
var {
Navigator,
StyleSheet
} = React;
var Login = require('./components/login');
import NavigationExperimental from 'react-native-deprecated-custom-components';
var ROUTES = {
login: Login
};
module.exports = React.createClass({
renderScene: function(route, navigator) {
var Component = ROUTES[route.name];
return <Component route={route} navigator={navigator} />;
},
render: function() {
return (
<NavigationExperimental.Navigator
style={ styles.container }
initialRoute={ {name: 'login'} }
renderScene={this.renderScene}
configureScene={ () => { return Navigator.SceneConfigs.FloatFromRight; } }
/>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1
}
});
谁让我知道如何解决这个问题
您现在应该使用 Stack Navigator
import { StackNavigator } from 'react-navigation';
const SimpleApp = StackNavigator({
Home: { screen: HomeScreen },
Chat: { screen: ChatScreen },
});
<Button
onPress={() => navigate('Chat')}
title="Chat with Lucy"
/>
我使用下面的代码来解决我的问题
main.js
var React = require('react-native')
var {
Navigator,
StyleSheet
} = React;
var Login = require('./components/login');
import NavigationExperimental from 'react-native-deprecated-custom-components';
var ROUTES = {
login: Login
};
module.exports = React.createClass({
renderScene: function(route, navigator) {
var Component = ROUTES[route.name];
return <Component route={route} navigator={navigator} />;
},
render: function() {
return (
<NavigationExperimental.Navigator
style={ styles.container }
initialRoute={ {name: 'login'} }
renderScene={this.renderScene}
configureScene={ () => { return NavigationExperimental.Navigator.SceneConfigs.FloatFromRight; } }
/>
);
}
});
var styles = StyleSheet.create({
container: {
flex: 1
}
});
谁让我知道如何解决这个问题
我改台词了
configureScene={ () => { return NavigationExperimental.Navigator.SceneConfigs.FloatFromRight; } }
到
configureScene={ () => { return NavigationExperimental.Navigator.SceneConfigs.FloatFromRight; } }
解决我的问题
如果有人在甚至没有尝试使用 Navigator
的情况下看到它,那可能是因为您有一个 import
行,例如
import * as RN from 'react-native'
(Webstorm 特别有自动插入这些的习惯)
这会为 RN 的所有导出调用 get
ter,触发 Navigator
的错误。而是使用:
import {Things, You, Need} from 'react-native'