简体   繁体   English

React Native:解决“react-native-gesture-handler”

[英]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 -而且我也这样使用-

  1. npm install react-native-gesture-handler

  2. 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.

相关问题 React Navigation:警告 react-native-gesture-handler - React Navigation: Warning react-native-gesture-handler 使用 react-native-gesture-handler 时出错 - Error when using react-native-gesture-handler 在 react-native-gesture-handler/Swipeable 如何向其添加 post API - In react-native-gesture-handler/Swipeable how to add post API to it react-native-gesture-handler 无法识别双击 - react-native-gesture-handler not recognize double tap 如何使用 react-native-gesture-handler 匹配孩子的大小 - How to match size to children using react-native-gesture-handler 来自 react-native 和 react-native-gesture-handler 的 Touchables 之间的区别 - Difference between Touchables from react-native and react-native-gesture-handler 我无法使用 expo 安装 react 导航(未安装 react-native-gesture-handler) - I am unable to install react navigation using expo (react-native-gesture-handler isn't installed) Position 在使用来自 react-native-gesture-handler 的 PanGestureHandler 时重置为 0 - Position resets to 0 while using PanGestureHandler from react-native-gesture-handler react-native-gesture-handler 平移/拖动和旋转时旋转错误的值 - react-native-gesture-handler pan/drag and rotate wrong values when rotated 如何使用 React Navigation 6.x Native Stack Navigator (RN&gt;0.6) 实现 React-native-gesture-handler? - How do you implement React-native-gesture-handler with React Navigation 6.x Native Stack Navigator (RN>0.6)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM