如何使用我的react nav解决依赖性问题



所以我是一个新手,正在努力学习开发应用程序。我试图学习如何使用React Navigation,所以我安装了它和dependencies,但当我尝试使用它时,我遇到了一些错误。运行npm启动后第一个出现在cmd中:

Some of your project's dependencies are not compatible with currently installed expo package version:
- react-native-screens - expected version range: 2.0.0-alpha.12 - actual version installed: ^2.0.0-alpha.12
Your project may not work correctly until you install the correct versions of the packages.
To install the correct versions of these packages, please run: expo install [package-name ...]

然后当我在安卓sim中启动应用程序时,我会得到这个:

Unable to resolve "@react-navigation/drawer" from "App.js"
Failed building JavaScript bundle.

这是我的代码:

import React from 'react';
import { StyleSheet, Text, View, Platform, Image, ImageBackground } from 'react-native';
import {Button} from 'native-base';
import { render } from 'react-dom';
import Search from './src/search';
import Landing from './src/landing';
import {NavigationContainer} from '@react-navigation/native'
import {createDrawerNavigator} from '@react-navigation/drawer'
import {createStackNavigator} from '@react-navigation/stack'
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs'
import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'

var myBackground = require('./assets/icons/landing.jpg');
const Drawer = createDrawerNavigator();
const Stack = createStackNavigator();
const MaterialBottomTabs = createMaterialBottomTabNavigator();
const MaterialTopTabs = createMaterialTopTabNavigator();

export default class App extends React.Component {
state = {
}
createHomeStack = () =>
<Stack.Navigator>
<Stack.Screen  name="Feed"/>
</Stack.Navigator>
createTopTabs = () =>
{
return <MaterialTopTabs.Navigator>
<MaterialTopTabs.Screen name="Tab1" Component={Landing}/>
</MaterialTopTabs.Navigator>
}
render() {
return (
<View style={styles.container}>
<NavigationContainer>
<Drawer.Navigator>
<Drawer.Screen name="Home" Component="Landing"/>
<Drawer.Screen name="Search" Component="Search"/>
<Drawer.Screen name="Home"/>
</Drawer.Navigator>
</NavigationContainer>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: Platform.OS === "android" ? 50 : 0
},
});

有人知道我为什么会犯这些错误吗?在开始之前,我安装了React Nav。提前感谢!

Package.json:

{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"@react-native-community/masked-view": "^0.1.5",
"@react-navigation/native": "^5.0.8",
"expo": "~36.0.0",
"native-base": "^2.13.8",
"react": "~16.9.0",
"react-dom": "~16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz",
"react-native-gesture-handler": "^1.5.6",
"react-native-reanimated": "^1.4.0",
"react-native-safe-area-context": "^0.6.0",
"react-native-screens": "^2.0.0-alpha.12",
"react-native-web": "~0.11.7"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"babel-preset-expo": "~8.0.0"
},
"private": true
}

因此,正如您的pacakge.json所示,您还没有安装用于抽屉和堆叠的包。解决抽屉问题后,您将遇到堆叠问题。。按照以下步骤复制您的问题

有关React Navigation Version 5.x 的更多信息

使用以下方法安装抽屉包:

npm i -s @react-navigation/drawer

使用以下方法安装导航堆栈:

npm i -s @react-navigation/stack

使用以下方法安装材料底部标签:

npm i -s @react-navigation/material-bottom-tabs

使用以下方法安装材料顶部选项卡:

npm i -s @react-navigation/material-top-tabs
  • 您应该按照以上所有步骤解决项目中的问题

安装完以上所有依赖项后,您需要清理并重建项目,并从模拟器中卸载以前的版本,然后再次运行

关于选项卡导航

关于抽屉导航

相关内容

  • 没有找到相关文章

最新更新