• This repository has been archived on 07/May/2022
  • Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minimal template with best practices and automation scripts for improved developer experience.

react-native-template

Build Status npm downloads npm version

Template landing screen preview Reactotron preview


A minimal template with architecture and boilerplate to let you focus on writing features right away.

Preconfigured with

Contents

Documentation

Getting Started

Create a new project using the template.

  • Note: the command will fail if you have the global legacy react-native-cli installed. Make sure you uninstall it first. More info at react-native-community/cli.

RN 0.63.2

$ npx react-native init MyApp --template @osamaq/react-native-template

Optional Steps

Connect To Sentry

This template comes with Sentry, but its disabled until you connect your account.

To connect your account:

$ cd MyApp/

# For MacOS
$ npx sentry-wizard -i reactNative -p ios android

# Other Platforms
$ npx sentry-wizard -i reactNative -p android

Insert your sentry DSN in each .env file (dev, staging and production) and you're all done.

Install Reactotron Flipper Plugin

This allows you to use Reactotron within Flipper.

Flipper -> Manage Plugins -> Install Plugins -> flipper-plugin-reactotron

Libraries

Let's briefly go over the benefit of each library included in this template.

TypeScript

For type safety Β―\(ツ)/Β―

But in all seriousness, if you are considering this template I assume you are a TypeScript fan. If you happen to be a JavaScript user, this template might be overwhelming. If you would like to start learning TypeScript, I suggest bootstrapping with this instead react-native-community/react-native-template-typescript so you can learn at your own pace.

SWR

This library simplifies data fetching and cache management. It allows you to easily show cached data, while the new data is being loaded from the API.

  • Caveat: currently it only supports in-memory caching for data.

  • Alternative: React Query/Apollo.

apisauce

Its a wrapper around axios with extended functionality. I'm happy with its API and I like the problem matcher.

Redux/Redux Toolkit

I'm happy using Redux Toolkit. It's a lot more concise now and I enjoy the redux ecosystem of plugins.

SWR reduces our dependency on Redux for global state. And sometimes React Navigation can be used to send data to the next screen. I try to leverage these two before reaching out to global state.

If you prefer something else, remove redux and go with that. Do not waste time trying a new state management solution.

Redux Observable

This is used alongside Redux for complex background work. Most people will rarely need to use something like this. In fact, if you aren't sure, just remove it (also uninstall its dependency, rxjs).

React Navigation

It is the most popular navigation library. For most apps, this is the best choice.

Reactotron/Flipper

Using this template there will be two main deubgging tools in your toolbelt. Reactotron and Flipper.

I mainly use Reactotron for reading API calls, asyncstorage operations, redux actions etc. It organizes everything in a neat way. It also has a killer image overlay feature, which allows you to get the UI design pixel prefect.

Flipper could be used for lower level debugging, such as viewing your database or React component tree. There is also a Flipper plugin for using Reactotron within it, so you only need to start one application.

Flipper -> Manage Plugins -> Install Plugins -> flipper-plugin-reactotron

Sentry

Benefitial in debugging issues that occur only in release builds. You can view error stack traces for unhandled exceptions. You can also choose to log specific errors in some catch blocks to study how often they occur in production.

In this template, there is a custom Redux middleware that adds Redux actions as breadcrumbs to Sentry reports for even easier debugging.

This is similar to redux-sentry-middleware but I've yet to test that one.

react-native-bootsplash

Works great for controlling your splash screen.

react-native-svg

Prefer using SVG over images all the time (remember to optimize your SVGs).

react-native-config

If you have different development, staging and production variables, this library is very helpful. It allows you to declare environment variables that can be accessed by all 3 sides (android, ios, JavaScript).

Android: by default, running react-native run-android will use the development .env file. To load .env.staging we must use:

ENVFILE=.env.staging react-native run-android

Note: the above works on MacOS. For windows its a bit different. See Different Environments.

iOS: two additional schemes are created in the Xcode project for staging and production. The corresponding .env file is set via the scheme's pre-action:

Scheme's pre-action setting the .env file

NPM scripts for running the app with the desired configuration are included for convenience.

Reanimated/Redash

Necessary when creating complex gesture based animations that are highly performant. Redash contains boilerplate helpers for Reanimated.

AsyncStorage

For caching simple data such as user perferences.

FastImage

Drop in replacement for the <Image/> component. I've found this to give a performance boost on android when rendering many images.

Detox

For end-to-end testing.

Mirage JS

Mirage is an in-memory server for intercepting API calls and returning whatever data you want. Very useful for developing before the backend is deployed, and for confirming how the app reacts to different API call outcomes.

Fastlane

Fastlane community has an endless amount of mobile development automation plugins. I currently use it mainly for automatic versioning, and often for deploying to Microsoft's App Center in one command.

This template also has a fastlane command for adding version badges to app icons. Useful outside of production as it makes it easier for QA to tell the app version.

App icon with version badge

If you appreciate those libraries and find them useful, please consider supporting them.

Directory Structure

root
β”œβ”€β”€ __tests__
β”œβ”€β”€ android
β”œβ”€β”€ e2e
β”œβ”€β”€ fastlane
β”œβ”€β”€ ios
β”œβ”€β”€ scripts
└── src
    └── common
    |   β”œβ”€β”€ assets
    |   β”œβ”€β”€ components
    |   β”œβ”€β”€ exceptions
    |   β”œβ”€β”€ helpers
    |   β”œβ”€β”€ hooks
    |   β”œβ”€β”€ theme
    |   └── types
    └── features
    |   β”œβ”€β”€ error-boundary
    |   β”œβ”€β”€ home
    |   β”œβ”€β”€ landing
    |   └── navigation
    └── redux
    |   β”œβ”€β”€ middleware
    |   └── slices
    └── services
        β”œβ”€β”€ cache
        β”œβ”€β”€ navigation
        └── network
            β”œβ”€β”€ github
            └── mock

Quick Overview

Quickly get an idea about each folder's role.

Directory Short Description
root Root directory. Contains many configuration files and all other folders.
__tests__ (Default; as per official template)
android Android project. Includes modifications to integrate libraries.
e2e Detox end-to-end tests and configurations.
fastlane Useful fastlane automation scripts.
ios iOS project. Includes modifications to integrate libraries.
scripts Handy node scripts for code generation.
src Most of the app's code is here.
common Shared code between different features.
assets Shared images, fonts etc.
components Shared React components.
exceptions Shared custom exceptions.
helpers Shared utlities.
hooks Shared hooks.
theme Shared styles; app's theme.
types Shared general types.
features Feature directories.
error-boundary Root error boundary.
home Home screen. Has simple data fetching and global state examples.
landing Template's initial screen.
navigation Contains a simple stack navigator.
redux Redux integration.
middleware Redux custom middleware. For now, a simple Sentry breadcrumb logger.
slices Redux state slices.
services App's services.
cache Cache service; AsyncStorage wrapper.
navigation Navigation service (navigate from outside React components).
network Networking related services.
github Example GitHub API client (REST).
mock MirageJS in-memory server for mocking backend APIs.

If you would like to learn more without going through the codebase, read the file walkthrough here.

Credits

This template is modified from react-native-typescript-template. Thank you ❀️

More Repositories

1

react-native-image-colors

Fetch prominent colors from an image.
Swift
536
star
2

spotify-lite

Spotify Lite made with React Native for iOS and Android
TypeScript
382
star
3

reactnative-fastlane-appcenter

πŸš€ A fastlane step-by-step guide for signing, building and uploading new React Native apps to visual studio app center.
160
star
4

liveness-detection-react-native

Intro to Liveness Detection with React Native
TypeScript
31
star
5

react-native-revolver-view

A revolving picker view.
TypeScript
28
star
6

react-native-balloon-slider

Slider with a floating balloon animation. Works on iOS, Android and the web.
TypeScript
26
star
7

react-native-freeotp

Generate the same TOTP tokens as FreeOTP from your React Native app.
Swift
7
star
8

videomag-vibration-analysis

Textile classification through vibrations captured from video.
MATLAB
5
star
9

react-native-mqtt-example

Using a CloudMQTT instance and react_native_mqtt library
JavaScript
3
star
10

jsi-playground-cxx

Java
2
star
11

camera_experiment

TypeScript
2
star
12

osamaqarem

2
star
13

android-mvrx-basics-1

Thinking in React for Native Android Apps
Kotlin
2
star
14

android-mvrx-basics-2

Android with MvRx, Retrofit, Moshi, Requery, RxJava, Navigation, Android KTX, Kotlin Android Extensions.
Kotlin
2
star
15

android-mvp-basics

Android with Thirty-inch, Retrofit, GSON, RxJava and Requery basic examples.
Java
2
star
16

rn-navigation-experiment

Java
2
star
17

intro-to-react-slides

Internal sharing session @ Innov8tif – 11th March
JavaScript
2
star
18

nextjs-tailwind-typescript-template

NextJS + Tailwind + TypeScript
JavaScript
2
star