Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Navigation (using Expo) - location of the MainActivity.java file?

I am going through the React Navigation documentation.

In the React Navgation - Getting Started instructions, it says that "To finalise installation of react-native-gesture-handler for Android", I need to edit the MainActivity.java file.
However I don't have that file in my project, or any other similar directory pertaining to it (./android).

I created my project using expo-cli, in particular:

# To create a new React Native project  
$ expo init project-name


# And to run the App in Expo  
$ expo start

I am wondering if I have to create a build and how is it done, in order for Expo to create the files used by Android and iOS builds, or is there something else that I'm missing?

like image 932
ross-u Avatar asked Jan 05 '19 10:01

ross-u


People also ask

Can I use React navigation with Expo?

React Navigation is the most popular navigation library in the React Native ecosystem and the best choice for most apps. It is maintained by the Expo team and supports Android, iOS, and the web. This video demonstrates using React Navigation on iOS, Android, and web.


1 Answers

Expo

As you used Expo to create your app you will not have an android folder as these are abstracted away from you.

If you wish to use a dependency that requires you to edit native code then you need to eject your application. https://docs.expo.io/versions/latest/expokit/eject

From your command line run expo eject and it will build the necessary ios and android folders for you. However there are several ramifications if you eject your app. You should read the above link carefully.

react-navigation

However, as Expo recommend using react-navigation you don't need to install the react-native-gesture-handler as it is already installed in Expo https://reactnavigation.org/blog/2018/11/17/react-navigation-3.0.html#installation

First, install the library using your favorite package manager:

yarn add react-navigation@^3.0.0

Next, install react-native-gesture-handler. If you’re using Expo you don’t need to do anything here, it’s included in the SDK.

It even mentions it on the installation instructions page https://reactnavigation.org/docs/en/getting-started.html#installation

Next, install react-native-gesture-handler. If you’re using Expo you don’t need to do anything here, it’s included in the SDK. Otherwise:

react-native-gesture-handler

Similarly checking the documentation for react-native-gesture-handler it says:

Gesture Handler is already part of Expo and there is no extra configuration required. However, consider that the Expo SDK team may take some time to include the newest version of the library - so Expo might not always support all our latest features as soon as they are out.

https://kmagiera.github.io/react-native-gesture-handler/docs/getting-started.html#with-expo-https-expoio

Creating a build with Expo

There is no point repeating the steps here to create a build with Expo it goes into quite some detail in the Expo documentation which can be found here https://docs.expo.io/versions/latest/distribution/building-standalone-apps

like image 78
Andrew Avatar answered Nov 02 '22 06:11

Andrew