Welcome to the React Native Template with Environment Configuration! We're thrilled to introduce you to a streamlined way to kickstart your React Native projects, tailored for different Software Development Life Cycle (SDLC) phases. Whether you're a seasoned developer or just getting started, this template is designed to simplify your workflow and make your app development process smoother and more efficient.
- Environment Isolation: Easily switch between different SDLC phases by selecting the appropriate environment file. No more manual configuration changes – simply update your environment file, and you're ready to go.
- Effortless Setup: Get started quickly with our template by cloning the repository and following the straightforward setup instructions. We've done the heavy lifting so you can focus on building your app.
- NPM scripts ready: This template comes with pre-configured npm scripts that simplify common development tasks such as building in different environments and running your React Native application.
- React Navigation - Routing and navigation for Expo and React Native apps
- Async Storage - Data storage system for React Native
- Axios - Promise based HTTP client for the browser and node.js
- Native Base - Accessible, utility-first component library for Android, iOS and Web
- React Native Config - Module to expose config variables to your javascript code in React Native
- React Native Rename - Rename react-native app with just one command
- React Native Vector Icons - Customizable Icons for React Native
- Zustand - A small, fast, and scalable bearbones state management solution
Follow these steps to set up and run your React Native project with our template:
Before you begin, ensure you have the following prerequisites installed:
Clone the template repository to your local machine using the following command:
$ git clone https://github.com/Shenggg2000/app-template.gitMove into the project folder using the following command:
cd app-templateBefore proceeding, configure your environment variables for each SDLC phase by following these steps:
- In the root directory of your project, locate the following files:
.env.example.dev.env.example.qa.env.example.uat.env.example.prod
- Rename these files as follows:
.env.dev.env.qa.env.uat.env.prod
- Open each of the renamed
.envfiles (.env.dev,.env.qa,.env.uat,.env.prod) and provide the specific environment variables and values relevant to each SDLC phase.
Install project dependencies using Yarn:
yarn installUse the following command to rename the app to your preferred name. Replace "yourappname" with your desired app name:
npx react-native-rename "yourappname" --skipGitStatusCheck --androidBundleID "com.yourappname"If you want the app name to include the environment name, follow these steps:
iOS
- Navigate to
ios/yourappname/Info.plist. - Update CFBundleDisplayName in line 8 from:
<key>CFBundleDisplayName</key>
<string>yourappname</string>to:
<key>CFBundleDisplayName</key>
<string>${APP_NAME}</string>Android
- Navigate to
android/app/src/main/res/values/strings.xml. - Update app_name in line 2 from:
<string name="app_name">yourappname</string>to:
<string name="app_name">@string/APP_NAME</string>This step is optional and should only be performed if you want to include the environment name in your app's display name.
Install pod dependencies for iOS by running:
npx pod-install iosStart the Metro server by running:
yarn run startOpen another terminal window and build the project in the development environment:
yarn run iosContinue with Firebase Cloud Messaging (FCM) Setup
Now, your React Native project is up and running with the configured environment settings. Happy coding!
Enhance the visual appeal of your React Native project by adding custom fonts. Follow these steps to integrate your preferred font family into the template:
Download your preferred font family from Google Fonts or other font providers. Ensure that you have the necessary .ttf font files.
Navigate to the assets/fonts directory in your project and replace the default .ttf files with your downloaded font family .ttf files.
Open your terminal in the root directory of your project and run the following command to link the font assets:
npx react-native-assetFor iOS, follow these additional steps:
- Open Xcode and navigate to your project's
iosfolder. - In Xcode, select all the font .ttf files that you placed in the
assets/fontsdirectory under the "Resources" folder. - In the right panel, tick the checkbox for all four targets to ensure that the fonts are included in the build.
Navigate to src/theme/config.ts in your project and locate the default font family name. Change it to your preferred font family name.
Start the Metro server by running the following command:
yarn run startOpen another terminal window and rebuild the project to apply the font changes:
yarn run iosYour React Native project is now configured with your custom font family, giving your app a unique and personalized look. Enjoy the enhanced typography in your application!
To enable Firebase Cloud Messaging (FCM) for your React Native project, follow these simple steps:
- Visit the Firebase Console.
- Click on "Add Project" to create a new Firebase project. Give it a name that reflects your app's purpose and click "Continue."
For Android:
- After creating the project, click on "Add app" from the project dashboard.
- Select the Android platform.
- Follow the setup instructions, and when prompted, download the
google-services.jsonfile.- Place the downloaded
google-services.jsonfile in theandroid/appdirectory of your React Native project.
- Place the downloaded
For iOS:
- After creating the project, click on "Add app" from the project dashboard.
- Select the iOS platform.
- Follow the setup instructions, and when prompted, download the
GoogleServices-Info.plistfile.- Open your Xcode project.
- Right-click on the
yourappnamefolder and select "Add Files to 'yourappname'." - Select the downloaded
GoogleServices-Info.plistfile. - Make sure all the targets and "Copy items if needed" are checked.
With these simple steps, your React Native app is now set up to use Firebase Cloud Messaging (FCM) for push notifications and other messaging features. You can now use FCM to engage with your users and send real-time updates.
What is CodePush? CodePush is a cloud-based service by Microsoft App Center that allows you to easily distribute and update your React Native app's JavaScript bundle and assets to your users' devices without requiring an App Store submission. It's a powerful tool for delivering over-the-air updates to your app.
Learn more about CodePush on the official website.
This template simplifies the CodePush setup process for React Native projects. Developers only need to change the secret and development key in the environment variables to get started. If you're new to CodePush, follow these initial steps:
- Register for AppCenter Account: If you haven't already, register for an AppCenter account. AppCenter is the platform that hosts CodePush.
- Install AppCenter CLI: Set up the AppCenter CLI on your development device by following the installation instructions provided in the AppCenter CLI documentation.
Once you've completed the initial setup, follow these steps to create a new project in AppCenter and obtain the necessary keys:
- Add a New App in AppCenter:
- Log in to your AppCenter account.
- Click on "Add new app" with the following settings:
- OS: Android/iOS
- Platform: React Native
- Obtain the App Secret:
- Once the app is created, you'll find the app secret on the "Overview" tab of your project.
- Create a Standard Deployment:
- Navigate to "Distribute" > "CodePush" within your project.
- Click on "Create a standard deployment."
- Get the Deployment Key:
- Click on the 'wrench' icon on the top right corner of your CodePush deployment to access the deployment settings. You'll find the deployment key here.
- Update Environment Variables:
- Replace both the 'secret' and 'deployment key' in your
.envfile with the values you obtained from AppCenter.
- Replace both the 'secret' and 'deployment key' in your
With these steps, you've successfully set up CodePush for your React Native project. You can now leverage CodePush to push updates to your app quickly and efficiently.
