Skip to content

colorfy-software/react-native-colorfy-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Comprehensive template for the React Native apps built at colorfy GmbH.

npm version

🚦 Quick start

npx react-native init MyApp --template react-native-colorfy-template

Happy coding!

πŸ’« Features

This template has virtually everything you might need to kick-start a React Native (0.67.3) app already built-in and set up:

πŸ—‚ Project structure

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

πŸ“š Commands

An exhaustive list of all the commands available in package.json and their use case.


πŸ“± Running on device

Browse the commands

If you're missing anything here, you can check out the react-native-cli commands list.

yarn android | yarn ios

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.


πŸ› οΈ Building apps

Browse the commands

./build.sh build

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)

πŸ§ͺ Testing code

Browse the commands

yarn lint

Runs ESLint on the whole codebase based on the rules set up in .eslintrc.js and tries to fix lint errors whenever possible.

yarn type

Runs the TypeScript compiler on all *.ts/*.tsx files based on the config set up in tsconfig.json.

yarn unit

Runs the test suite specified in __tests__ via Jest.

yarn test | yarn test-commit

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.

./build.sh detox

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.


πŸ—ƒ Miscellaneous

Browse the commands

./build.sh assets

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).

./build.sh clean android | ./build.sh clean ios

Cleans the build directory and uninstalls the app from the device (Android only).

./build.sh keystore

Generates a keystore file to sign Android App Bundles/APKs.

Note: Without a keystore, the release variant won't be available.

yarn start

Starts Metro, the JavaScript bundler for React Native. Mandatory steps to do anything productive today!

yarn postinstall

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).

🀝 Contributing

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 πŸ‘€β€¦