首页 > 解决方案 > How to install react-navigation in an ejected expo project?

问题描述

I am trying to install react-navigation in my ejected expo app by following the official install instructions on this page. Within the instructions below the typical addition of the package and linking via react-native link there is additional code to be added into the file MainActivity.java.

Now my problem is that in the install instructions the class MainActivity extends the class ReactActivity, but since I use an ejected expo app in my code it extends the class DetachActivity, which seems to be incompatible with the given code of the install instruction and therefore I am really clueless how to approach that incompatibility problem (especially since I am not even able to find anything via google about that - is it even a dark secret nobody talks about?).

Some approaches I tried but did not work:

I would really appreciate some wise tips! Also, I am not very familiar with java but am totally willing to learn some new stuff!

标签: javaandroidreact-nativereact-navigationexpo

解决方案


2019 年 12 月更新

下面无视。如今,Expo 正在将它们的内置依赖项分离为 react-native-gesture-handler。所以我们需要安装它。 参考

解决方案

总结一下,

回到您从博览会中退出项目的提交。并安装react-navigation. 请勿将其他安装为react-native-gesture-handler.

就这样。

为什么

如果您从 expo 中退出项目,这些项目将依赖 ExpoKit,因此不需要再次安装已经构建的模块。并且react-native-gesture-handler是这些模块之一。因此,也不需要react-native link

Native module com.swmansion.gesturehandler.react.RNGestureHandlerModule tried to override versioned.host.exp.exponent.modules.api.components.gesturehandler.react.RNGestureHandlerModule for module name RNGestureHandlerModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice. If this was your intention, set canOverrideExistingModule=true.

此消息可能是RNGestureHandlerModule您再次安装造成的。


推荐阅读