Comprehensive template for the React Native apps built at colorfy GmbH.
npx react-native init MyApp --template react-native-colorfy-template
Happy coding!
This template has virtually everything you might need to kick-start a React Native (0.67.3) app already built-in and set up:
- TypeScript, for type safety
- ESLint, for code linting
- Prettier, for code formatting
- Jest + Testing Library, for unit testing
- Detox + DetoxRecorder, for end-to-end testing
- Bitbucket Pipelines, for continuous integration
- Bitrise or AppCenter, for continuous deployment
- React Navigation v6, for screen navigation
- SVG Cleaner + React Native SVG, for cleaning & rendering
.svg
files directly - jpegoptim + OptiPNG, for minifying
.jpg
&.png
files - Modalfy, for handling custom modals
- Splash Screen, for a nice cross-platform way of dealing with splash screens
- Reanimated + Gesture Handler, for performant native driven (- gesture) animations
- FastImage, for performant image loading
- Localize, for strings localization in JavaScript
- date-fns, for date manipulation
- Device Info, for native device info
- zustand, zfy & MMKV, for state management & data persistence (with encryption if needed)
- Pre-commit, for running the test suite before each commit
- Support for
Dev
,Staging
&Prod
Android flavours/iOS targets out of the box - A bunch of useful commands listed down below
Click to expand
.
βββ __mocks__ // All the mocks needed to setup unit tests
βββ __tests__ // Holds all the unit tests (ran by Jest)
βββ e2e // Holds all the E2E tests (ran by Detox)
βββ scripts // Various useful scripts accessible via the commands in package.json
β βββ build-unsigned-ipa.sh // Builds an unsigned IPA of any iOS target
β βββ create-pipeline-badge.sh // Creates status SVG badge for the Bitbucket Pipelines to use
β βββ generate-signed-android-keystore.sh // Generates a keystore file to sign Android App Bundles/APKs
β βββ images.js // Generates the src/assets/index.tsx file
β βββ postinstall.sh // Runs after each modification to the project dependencies list to run Jetifier and update Pods
β βββ run-detox-ci.sh // Runs Detox in AppCenter (if @appcenter tag was used to setup project)
βββ src // App root folder
β βββ api // Contains all the API requests
β β βββ api.ts
β β βββ requests.ts
β βββ assets // Holds all of files, SVGs, images, gifs, videos, fonts, etc
β β βββ fonts/
β β βββ icn_activity.svg
β β βββ logo.png
β β βββ index.tsx // Generated file from where assets can be imported (`Assets.x`, `Icons.x`, `Images.x`, etc)
β βββ components // Global reusable components
β β βββ AnimatedWrapper.tsx // Otherwise one file per component
β β βββ AppText.tsx
β β βββ AsyncRenderWrapper.tsx
β β βββ Button.tsx
β β βββ FloatingLabelInput.tsx
β β βββ Row.tsx
β β βββ ScreenLoader.tsx
β βββ config
β β βββ app-config // Exports the CONFIG variable (with backend URL, target helpers, feature flags, etc)
β βββ core // Internal SDK that takes care of all the business logic + some helpers
β β βββ app-core.ts // Each subclass of the core is a TypeScript file
β β βββ core.ts // Root class of core (only file to be imported for use)
β β βββ events-core.ts
β β βββ user-core.ts
β βββ locales // Setup for the app localization (JS side, not native)
β β βββ de.json
β β βββ en.json
β β βββ index.ts // Contains all the helpers to add localization in the app
β βββ modals // Contains the modals components used by react-native-modalfy
β β βββ AlertModal.tsx
β βββ navigation // Used to hold all of the navigation logic
β β βββ AuthStack.tsx
β β βββ Navigation.tsx // Main navigation component file
β β βββ SettingsStack.tsx
β β βββ TabBar.tsx
β βββ screens // Used to hold all of the app screens at this one level, no nesting
β β βββ activity // Create a folder per screen
β β βββ components // If screen has components that are used only within the screen, put them here
β β βββ sections // If screen has sections that are used only within the screen, put them here
β β βββ Activity.tsx // Component file for the screen
β βββ store // State management with zustand
β β βββ middlewares // Folder for the custom store middlewares
β β βββ stores
β β β βββ app-store.ts // Each store has its own file
β β β βββ stores.ts
β β β βββ user-store.ts
β β βββ stores.ts // Main store file
β βββ styles // Global styling variables & device helpers
β β βββ colors.ts
β β βββ device.ts
β β βββ fonts.ts
β β βββ style-guide.ts // Entry file that exports all the styles & helpers
β βββ types // Folder that regroups all the TypeScript interfaces defined in the app
β β βββ modals-types.ts // One file per type item
β β βββ navigation-types.ts
β β βββ store-types.ts
β βββ utils // Helpers that don't really belong in the core
β βββ animate-color.ts
β βββ date.ts
β βββ linking.ts
β βββ navigation.ts
β βββ sleep.ts
β βββ strings.ts
βββ .eslintrc.js // Configuration for ESLint (linter)
βββ .prettierrc // Holds the code formatter configuration
βββ .svgrrc.js // Used to set up colors to replace in some .svg files
βββ app.json // Contains the app name used by various scripts throughout the app
βββ babel.config.js // Configuration file for Babel
βββ bitbucket-pipelines.yml // Configuration file for Bitbucket Pipelines (CI)
βββ build.sh // File containing useful shell scripts
βββ detox.config.js // Detox configuration (E2E testing)
βββ index.d.ts // Useful to set TypeScript interfaces needed for libraries that don't provided them
βββ index.js // Entry point of the app
βββ jest.config.js // Configuration file for Jest (unit test)
βββ tsconfig.json // Configuration file for the TypeScript compiler
An exhaustive list of all the commands available in package.json
and their use case.
Browse the commands
If you're missing anything here, you can check out the react-native-cli commands list.
Will run ./build.sh run
to build the Dev flavour/target in Debug mode on your phone (if connected to your computer) or in the Android
Emulator (if you have one setup & launched on your computer)/Xcode iOS Simulator.
Here is how you can use the ./build.sh run
command:
./build.sh run ios dev
or./build.sh run ios dev debug
./build.sh run android dev -c
or./build.sh run android dev --clean
(to clean the build folder and uninstall the app before building)
And from here you change the arguments ios
/android
, dev
(for staging
/prod
) and debug
(for release
) depending on your needs.
Browse the commands
Builds and generates a signed (or unsigned) application and opens your file manager to its location once done.
Here are examples of how you can use the ./build.sh build
command:
./build.sh build appbundle prod
(Signed Android App Bundle Prod flavour in Release mode)./build.sh build apk staging
(Signed Android APK Staging flavour in Release mode)./build.sh build apk prod --unsigned
(Unsigned Android APK Prod flavour in Release mode)./build.sh build ipa staging 42
(Signed iOS IPA Staging target in Release mode with build number 42)./build.sh build ipa prod 42 --unsigned
(Unsigned iOS IPA Staging target in Release mode build number 42)
Browse the commands
Runs ESLint on the whole codebase based on the rules set up in .eslintrc.js
and tries to fix lint errors whenever possible.
Runs the TypeScript compiler on all *.ts
/*.tsx
files based on the config set up in tsconfig.json
.
Runs the test suite specified in __tests__
via Jest.
Runs the 3 aforementioned commands.
Note: yarn test
is run by the CI/CD tool before any build. yarn test-commit
is run before any commit is made from your local machine. Unless for specific and approved reasons: make sure to always pass this command before pushing your code.
Runs the E2E test suite with Detox.
Here are examples of how you can use the ./build.sh detox
command:
./build.sh detox android staging
./build.sh detox ios prod release
./build.sh detox --ci
(as is, no other argument expected when this flag is used)
And from here you change the arguments ios
/android
, dev
(for staging
/prod
) and debug
(for release
) depending on your needs.
Note: ./build.sh detox --ci
runs the E2E test suite with Detox in the CI/CD tool with the appropriated flavour/target in Release mode. This is not meant for local use on your machine, prefer the aforementioned commands instead or refer to Detox documentation.
Browse the commands
Automatically imports the latest POEditor translations, cleans SVG, minifies JPEG & PNG files and generates the src/assets/index.tsx
file from where assets can be imported.
Note: For the images assets generation to work, you need to respect the file nomenclature rules:
- icons have to named with the format
icn_name.svg
and can only (!) be SVG files - images have to named with the format
img_name.png
and can be anything (PNG, JPEG, GIF).
Cleans the build directory and uninstalls the app from the device (Android only).
Generates a keystore file to sign Android App Bundles/APKs.
Note: Without a keystore, the release
variant won't be available.
Starts Metro, the JavaScript bundler for React Native. Mandatory steps to do anything productive today!
Runs after each use of yarn add
/yarn install
in the project to jetify the Android code, update the Pods on iOS (if you're using macOS).
This template is a very opinionated approach to React Native apps that the team uses at colorfy.
Therefore, we won't necessarily consider requests that do not align with our goals/vision/use cases for this template.
However, feel free to voice your opinions if need be: our position might change!
You can also consider doing so from the inside πβ¦