This project is a React Native boilerplate that can be used to kickstart a mobile application.it is based on ThecodingMachine boilerplate.
The boilerplate provides an architecture optimized for building solid cross-platform mobile applications through separation of concerns between the UI and business logic. It is extremely documented so that each piece of code that lands in your application can be understood and used.
If you love this boilerplate, give us a star, you will be a ray of sunshine in our lives :)
The driving goal of the architecture of the boilerplate is separation of concerns. Namely:
-
Presentational components are separated from containers (aka "screens").
Presentational components are small components that are concerned with how things look. Containers usually define whole application screens and are concerned with how things work: they include presentational components and wire everything together.
If you are interested you can read more about it here.
-
State is managed using global Redux stores.
When applications grow, sharing state and its changes can become very hard. Questions like "How can I access this data?" or "When did this change?" are common, just like passing data around components just to be able to use it in nested components.
With Redux, state is shared using global stores, and changes are predictable: actions are applied by reducers to the state. While the pattern can be a bit much for small projects, the clear separation of responsibilities and predictability helps with bigger applications.
If you are interested you can read more about it here.
-
Application side-effects (API calls, etc.) are separated from UI and state manipulation using Redux Saga.
Using Redux Saga has two benefits: keeping application side-effects and related business logic out of UI components, as well as executing that logic in an asynchronous way without ending in callback hell.
Sagas are triggered by Redux actions and can also trigger Redux actions to alter state. By using JavaScript generators (
yield
), sagas are written in a synchronous-like manner while still executing asynchronously. -
You have a GraphQL endpoint? no problem! we configured Apolloclient in the boilerplate Apollo GraphQL.
Using Apollo has two benefits: Using Queries to simplify your requests and removing the complexity of redux saga ofCourse if you don't have Gql endpoint feel free to remove apollo or vice versa.
The boilerplate contains:
- a React Native (v0.62.2) application (in "ejected" mode to allow using dependencies that rely on native code)
- a clear directory layout to provide a base architecture for your application
- Redux (v4.0.5) to help manage state
- Redux Persist (v6.0) to persist the Redux state
- Redux Sagas (v1.1.3) to separate side-effects and logic from state and UI logic
- React Navigation (v5.6.1) with a
NavigationService
to handle routing and navigation in the app, with a splash screen setup by default - reduxsauce (v1.1.3) to facilitate using Redux
- axios to make API calls (v0.19.2)
- Responsive-screen handle Responsivnes
- prettier and eslint preconfigured for React Native
The boilerplate includes an example (displaying fake user data) from UI components to the saga. The example is easy to remove so that it doesn't get in the way.
App/Components
: presentational componentsApp/Config
: configuration of the applicationApp/Containers
: container components, i.e. the application's screensApp/Assets
: assets (image, audio files, ...) used by the applicationApp/Navigators
: react navigation navigatorsApp/Sagas
: redux sagasApp/Services
: application services, e.g. API clients or GraphQL QueriesApp/Stores
: redux actions, reducers and storesApp/Theme
: base styles for the application
For more information on each directory, click the link and read the directory's README.
The boilerplate will follow new React-Native releases as soon as libraries and tools used here are compatible.
Node 12 or greater is required. Development for iOS requires a Mac and Xcode 9 or up, and will target iOS 9 and up.
You also need to install the dependencies required by React Native:
- for Android development
- for iOS development
To create a new project using the boilerplate:
- clone this repository
- remove the previous git history:
rm -rf .git/
- install the npm dependencies by running
yarn
- rename the React Native project to your own project name:
yarn run rename -- <YourProjectName>
(the default name isBoilerplate
) - remove the LICENSE file and the "License" section from the README if your project is not open source
Feel free to remove the section "Using the boilerplate" from the README (you will not need it anymore in your project). You are encouraged to keep the rest of the documentation in your project so that it is self-explanatory.
You can now create a new git repository for your project (using git init
) and create the first commit.
Assuming you have all the requirements installed, you can setup and run the project by running:
yarn install
to install the dependencies- create your configuration file
App/Config/index.js
fromindex.dev.js
(if you are in dev environment) and fill the missing values - run the following steps for your platform
- only the first time you run the project, you need to generate a debug key with:
cd android/app
keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
cd ../..
to come back to the root folder
yarn start
to start the metro bundler, in a dedicated terminalyarn android
to run the Android application (remember to start a simulator or connect an Android phone)
cd ios
pod install
to install pod dependenciescd ..
to come back to the root folderyarn start
to start the metro bundler, in a dedicated terminalyarn ios
to run the iOS application (remember to start a simulator or connect an iPhone phone)
"android": runs android app
"ios": runs ios app
"ios-responsive": runs ios app on iphone x and iphone 6 you can add other devices based on the script
dev: runs both android and ios
clean: cleans all the android gradle and build cache and xcodebuild cache also removes watchman watchers
build-and or build-ios: builds android app with a signed apk(makse sure to apply the proper config for app sigining), build-ios will only build on emulator nothing else!
rename: rename the app in all the places needed in android and ios, use with -b <bundle id> on android to change tghe bundle id also.
pod: install pods in the ios folder and navigate to root
pod-update: runs pod --repo-update on ios
- Using Fastlane to automate builds and store deployments (iOS and Android)
- You may want to use CocoaPods to manage your dependencies (iOS only)
If your application fails to start after using the yarn run rename
command, please take a look at this issue
This project is released under the MIT License.
Improver Digital is a Digital agency based in Istanbul and, Turkey and LA(Soon).Feel free to check our website if you want your ideas turn into business
as mentioned this boilerplate were inspired by theCodingMachine Starter.yet the dependencies were going a little bit out of date however if you are comfortable using older dependencies's version (react navigation v4) it is doable but we recommend using this repo.
The other option is mcnamee's Starter Kit, which is unfortunately limited by Expo and misses Redux Saga.
If we look at the rest (and ignore unmaintained projects), many popular boilerplates are too opinionated: they include 3rd party services or very strong architecture choices that we are not comfortable with. To name a few: Snowflake runs with a Hapi Server running on Redhat OpenShift, Hasura's boilerplate uses Hasura's SaaS for authentication, Apollo's StarterKit is targeted at GraphQL using Apollo, the Meteor Boilerplate targets Meteor…
Finally some did not contain the architecture we are looking for (the separation of concerns with Redux, Sagas, etc.), for example re-start.
One interesting exception is Ignite IR Boilerplate "Andross", but after consideration we decided not to use it because of the large amount of unnecessary code/components it provided.