[英]React Native: resolve “react-native-gesture-handler”
I tried to install react navigation following the its docs: https://reactnavigation.org/我尝试按照其文档安装反应导航: https://reactnavigation.org/
Here are the steps I made:以下是我所做的步骤:
run "npm install --save @react-navigation/native"
运行
"npm install --save @react-navigation/native"
run "expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view"
运行
"expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view"
run "npm install --save @react-navigation/stack"
运行
"npm install --save @react-navigation/stack"
And then inside my navigation folder, I created a file called MealsNavigator.js
file and inside:然后在我的导航文件夹中,我创建了一个名为
MealsNavigator.js
的文件,其中:
import { createStackNavigator } from '@react-navigation/stack';
import { createAppContainer } from '@react-navigation/native';
import CategoriesScreen from '../screens/CategoriesScreen';
import CategoryMealsScreen from '../screens/CategoryMealsScreen';
import MealDetailScreen from '../screens/MealDetailScreen';
const MealsNavigator = createStackNavigator({
Categories: CategoriesScreen,
CategoryMeals: {
screen: CategoryMealsScreen
},
MealDetail: MealDetailScreen
});
export default createAppContainer(MealsNavigator);
I then tried to use this inside my App.js
file to see if its working:然后我尝试在我的
App.js
文件中使用它来查看它是否工作:
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as Font from 'expo-font';
import { AppLoading } from 'expo';
import MealsNavigator from './navigation/MealsNavigator';
const fetchFonts = () => {
Font.loadAsync({
'poppins-regular': require('./assets/fonts/Poppins-Regular.otf'),
'poppins-bold': require('./assets/fonts/Poppins-Bold.otf')
})
};
export default function App() {
const [fontLoaded, setFontLoaded] = useState(false);
// This will make sure simply keep the flash screen open
// until our fonts loaded
if (!fontLoaded) {
return (
<AppLoading
startAsync={fetchFonts}
onFinish={() => setFontLoaded(true)}
/>
);
}
return <MealsNavigator />;
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
But in the end I ended up getting this error:但最后我得到了这个错误:
Unable to resolve "react-native-gesture-handler" from "node_modules/@react-navigation/stack/src/views/GestureHandler.native.tsx"
Any idea how to fix this?知道如何解决这个问题吗?
According to the docs which you have mentioned,根据您提到的文档,
npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view
This will be the perfect solution for you if you are using npm project
.如果您正在使用
npm project
,这将是您的完美解决方案。 The code you have mentioned is with expo
not with npm
.您提到的代码是
expo
而不是npm
。 I think this will solve your issue.我认为这将解决您的问题。 Moreover I would like to mention one more thing
npm install @react-navigation/native --save
I used to run code like this --save at the end though if you don't add --save still no issue will occur.此外,我想再提一件事
npm install @react-navigation/native --save
我曾经在最后运行这样的代码 --save 虽然如果你不添加 --save 仍然不会出现问题。 And I also use like this -而且我也这样使用-
npm install react-native-gesture-handler
npm install react-native-reanimated
......................................... .........................................................
And So on.等等。 Mean separately one by one.
一一分别的意思。 And If you are using Ubuntu 20.04 the in the terminal before
npm
use sudo
.如果您使用的是 Ubuntu 20.04,则在
npm
之前的终端中使用sudo
。 Thank you.谢谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.