- Build native mobile apps using JavaScript and React
- With React Native, you don't build a
mobile web app, anHTML5 app, or ahybrid app. You build a real mobile app that's indistinguishable from an app built usingObjective-CorJava.- React Native uses the same fundamental UI building blocks as regular iOS and Android apps. You just put those building blocks together using JavaScript and React.
- Install the command line tool for creating a react native project.
npm install -g create-react-native-app
- Now as the tool is installed - creating project without installing or configuring any tools to build native code - no
XcodeorAndroid Studiois required.
create-react-native-app cefaloSchoolProj1
- Now running the app will require installation of
Expoapp in your phone andexpocommand line client in your machine.
npm install -g exp
- If you use react-native-cli tool you can also create new project using the command:
react-native init cefaloSchoolProj1
-
To run the previously created
RNproject - runyarn start- A QR code will be visible
- Scan the code from your expo app in mobile
- The packager will run - and the app will be visible
- Any code change will be take effect instantly.
- Exporting app for publishing in
play storeorapp storeis very easy.
-
This
expo systemhas some issues such as:- This system do not permit to use custom native module (hence almost all third party modules)
- You cannot add React Native to your existing native app in this way.
-
If you want to run the app in device or simulator - Or if you want to add react native to your existing native apps you need some extra steps:
- First you have to
ejectthe project from the existing system using commandyarn run eject - You will be asked some questions about moving to
regularreact native project, usingexpo sdkorcancel. - You will be asked the projects name and how it will appear on phone - based on which the json file will be updated and entry points will be created.
- You need to install react-native-cli using command
npm install -g react-native-cli - You need to install
watchmenInstalling Watchmen for different platforms - For iOS projects -- you need to show Xcode the command line tool from
Preferences >> Locations >> Command Line Tools - For Android projects -- you need to install and configure Android Studio for:
- Android SDK
- Android SDK Platform
- Android Virtual Device
- For details and for all platform support: React Native Getting Started in the "Building Project with Native Code".
- The command to run in the iOS simulator is:
react-native run-ios- To run in android - first you have to run the android emulator (either from Android Studio device manager or from command line:
emulator @Nexus_6_API_25). Then run:
react-native run-android - First you have to
-
The
index.jsis the main entry point the main module is loaded here. -
AppRegistryis the JS entry point to running all React Native apps. App root components should register themselves withAppRegistry.registerComponent, then the native system can load the bundle for the app and then actually run the app when it's ready by invokingAppRegistry.runApplication. -
The
App.jsis the main component of our application. This can be used as the frame of the application or even can hold main layout or such functionality. -
For different implementation for iOS or Android platform we can check via
PlatformAPI of react native or on a higher end change we can create two separate files for Android and iOS named:App.ios.jsApp.android.js(this is true for all other component files too)
-
We will create three (or more) based on design preferences and requirements in the root directory for further operations:
componentsservicesstyles
-
We can design the components in either horizontal or vertical approach:
- Horizontal:
- Create component
jsfiles in component directory; - Create all API calls or other contextual processing in services directory
- Create stylesheets for all the components (either by same name of the components or by common names) in styles directory
- Create component
- Vertical:
- Create directory named after the component within components directory [lets say the component name is login].
- Inside the login directory put login.js, login-style.js and login-services.js files. Follow this for other components too.
- Horizontal:
- For starting:
- We will cover more on this at Class#11 [January 03, 2018]
https://snack.expo.io/BkNzfZ3xG