React Native CLI vs Expo :New React Native Apps.
There are two methods for initializing and developing your app: Expo, and the React Native CLI. Until recently there was a distinct third method, using Create React Native App (CRNA). CRNA has since been merged with the Expo project, and only continues to exist as a separate entity to provide backwards compatibility.
Expo falls into the first category of tools, providing a more robust and developer friendly development workflow at the cost of some flexibility. Apps bootstrapped with Expo also have access to a slew of useful features provided by the Expo SDK, like BarcodeScanner, MapView, ImagePicker, and so many more.
Initializing an app with the React Native CLI, via the react-native init
command provides flexibility at the cost of ease of development. A React Native app created with the react-native init
command is said to be a pure React Native app, since none of the native code is hidden away from the developer.
As a rule of thumb, if the documentation for a third party package states that you need to run the command react-native link
as part of the setup process, then this package can only be used with a pure React Native app.
So what do you do when you are half way through building an app with Expo, only to find out that a package integral to your app’s requirements is not supported by an Expo development workflow? Luckily Expo has a method for turning an Expo project into a pure React Native app, just as if it had been created with the react-native init
command. When a project is ejected, all of the Native code is unpacked into ios and android folders, and the App.js
file is split into App.js
and index.js
, exposing the code that mounts the root React Native component.
But what if your Expo app depends on features provided by the Expo SDK? After all, much of the value of developing with Expo comes from the excellent features the SDK provides, including AuthSession, Permissions, WebBrowser, and so much more.
That’s where ExpoKit comes into play. When you choose to eject from a project, you’re given the option of including ExpoKit as part of the ejected project. Including ExpoKit will ensure that all of the Expo dependencies being used in your app will continue to work, and also give you the ability to continue using all the features of the Expo SDK, even after the app has been ejected.
Expo
According to the expo.io site, Expo is “a free and open source toolchain built around React Native to help you build native iOS and Android projects using JavaScript and React.” Expo is becoming an ecosystem of its own, and is made up of 5 interconnected tools:
- XDE: the Expo Development Environment. The Expo team calls XDE the “graphical development environment,” and it has macOS, Windows, and Linux versions. This is the main tool you will use for creating, building, serving, and sharing React Native apps. Expo even has a workflow for publishing your compiled app to the App Store / Google Play Store!
- Expo CLI: The command line interface for Expo. If you prefer to live in the terminal, the CLI provides all of the power of the GUI based XDE in command line form.
- Expo Client: An app for Android and iOS. This app allows you to run your React Native project within the Expo app on the device without the need for installing. This allows developers to hot reload on a real device, or share development code with anyone else without the need for installing.
- Expo Snack: hosted at https://snack.expo.io, this web app allows you to work on a React Native app in the browser, with a live preview of the code you’re working. If you ever used CodePen or JSFiddle, Snack is the same concept applied to React Native apps.
- Expo SDK: This is the SDK that houses a wonderful collection of JavaScript APIs that provide Native functionality not found in the base React Native package, including working with the device’s accelerometer, camera, notifications, geolocation, among many others. This SDK comes baked in with every new project created with Expo.
These tools together makeup the Expo workflow. With the Expo XDE or CLI you can create and build new apps with the Expo SDK support baked in. The XDE/CLI also provides a simple way to serve your in-development app by automatically pushing your code to Amazon S3, and generating a url for the project. From there, the XDE/CLI generates a QR code linked to the hosted code. Open the Expo Client app on your iPhone or Android device, scan the QR code, and BOOM there’s your app, equipped with Live/Hot Reload! And since the app is hosted on Amazon S3, you can even share the in-development app with other developers in real-time. (Note that the QR code method of sharing an in-development Expo app has been disabled for iPhone by Apple, and is now an Android only feature. The app can still be shared via SMS, however.)
The XDE/CLI can also streamline building your final app.
2. react-native init
The original bootstrapping method for creating a new React Native app is the react-native init
command provided by the React Native CLI. I’ve listed this method last because it is no longer the official team’s recommended method for initializing React Native apps in their Getting Started guide.
In the React Native community, an app created with this method is said to be a pure React Native app, since all of the development and Native code files are exposed to the developer. While this provides the most freedom, it also forces the developer to maintain the Native code. If you’re a JavaScript developer that’s jumped onto the React Native bandwagon because you intend on writing Native apps solely with JavaScript, having to maintain the Native code in a React Native project is probably the biggest disadvantage of this method.
On the other hand, you’ll have access to third party plugins when working on an app that’s been bootstrapped with the react-native init command, and get direct access to the Native portion of the codebase. You’ll also be able to sidestep a few of the limitations in Expo currently, particularly the inability to use background audio or background GPS services.
3. CRNA or create-react-native-app
As mentioned previously, this method of bootstrapping has been deprecated since the CRNA project was merged with Expo. However at the time of this writing the official React Native Getting Started documentation still reference using it, so I have included some basic information about it.
CRNA (create-react-native-app) is a project by the open source React community react-community. It’s conceptually the same as the CRA (create-react-app) project that’s built and maintained by Facebook, but made for React Native projects. Initialize a new React Native project with CRNA takes a single command:
create-react-native-app my-app
Comments
Post a Comment