
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@mindinventory/react-native-boilerplate
Advanced tools
The Boilerplate contains all the basic packages, common components and, prebuilt code architecture. It will save developer's project setup time.
Built in implemented features.
Attractive Code Architecture Our boilerplate comes with a clean and organized code structure that enhances readability and maintainability.
Advanced State Management with Redux and Context API Harness the power of both Redux and React's Context API for efficient state management. Redux with Thunk middleware handles complex state logic, while the Context API facilitates easy sharing of data between components, especially for app theme and localization management.
Environment Setup Hassle-free setup with detailed instructions, ensuring a smooth onboarding process for developers.
Eslint for Better Code Linting Catch and fix issues early with Eslint integration, promoting consistent and error-free code.
Husky Improves Your Commits and More Benefit from Husky's pre-commit hooks to enforce code quality and ensure that only well-formatted code makes it into your repository.
Light/Dark Custom Theme Modes Enjoy the flexibility of light and dark theme modes with easy customization options to suit your app's design. This feature is seamlessly managed through the Context API.
Local Storage (MMKV) Efficient and reliable local storage using MMKV, optimizing data persistence in your React Native application.
Localization Easily add multilingual support to your app with our localization feature, utilizing the power of the Context API for seamless language switching and management.
Navigation Seamless navigation setup with React Navigation, providing a smooth and intuitive user experience.
Network Request (API Implementation) Simplified API integration for making network requests, saving you time and effort in implementing backend communication.
Supported for Responsive UI Build responsive user interfaces that adapt to various screen sizes, providing a consistent user experience across devices.
TypeScript Harness the benefits of TypeScript for static typing, catching errors at compile-time, and improving code quality. The combination of TypeScript with Redux and Context API ensures a robust and type-safe application architecture.
This React Native boilerplate utilizes ESLint, a popular linting tool, to enforce consistent and high-quality code across your project. ESLint helps identify and fix common code issues, ensuring your codebase adheres to best practices and coding standards.
The ESLint configuration in this boilerplate includes the following features and plugins:
@commitlint/cli
: Enforces conventional commit messages.@commitlint/config-conventional
: Provides commit message linting rules following conventional commit format.eslint-plugin-import
: Provides rules for linting ES6 import/export syntax.eslint-plugin-import-order-autofix
: Sorts import statements automatically.eslint-plugin-no-inline-styles
: Detects and discourages the use of inline styles in React Native.eslint-plugin-prettier
: Integrates Prettier code formatting rules into ESLint.eslint-plugin-react-hooks
: Enforces rules for React Hooks.eslint-plugin-react-native
: Provides rules specific to React Native development.eslint-plugin-sort-keys-fix
: Sorts object keys in alphabetical order.configuration of this lint is added in .eslintrc.js
file.
This repository serves as a boilerplate for React Native projects, providing a solid foundation to kickstart your development process. It includes a collection of scripts to generate images and icons, making it easier to customize your app's visual assets.
Create a new project using the boilerplate :
npx react-native init APP_NAME --template @mindinventory/react-native-boilerplate
Library | Category | Version | Description |
---|---|---|---|
React Native | Mobile Framework | v0.72 | The best cross-platform mobile framework |
React | UI Framework | v18 | The most popular UI framework in the world |
TypeScript | Language | v4 | Static typechecking |
React Navigation | Navigation | v6 | Performant and consistent navigation framework |
React Native Localization | Internationalization | v13 | i18n support (including RTL!) |
Redux | State Management | v5 | Observable state tree |
Redux-toolkit | Redux integration | v3 | New redux library with some function helpers |
RN Reanimated | Animations | v3 | Beautiful and performant animations |
MMKV | Persistence | v2 | State persistence |
axios | REST client | v1 | Communicate with back-end |
Hermes | JS engine | Fine-tuned JS engine for RN |
The project structure follows a modular approach to organize your codebase in a scalable manner. Here's an overview of the key folders:
├── blueprints
│ ├── Text
│ ├── Image
│ └── Indicator
│ └── Button
│ └── TextInput
│ └── ...
blueprints: Contains the app elements that Customize as per app development required.
Text: Text element(typography) for app consist presets of all font family and font-size that we have to use in app. For Example:
import { Text } from "@app/blueprints";
<Text preset="h1">{contents("newsList", "breakingNews")}</Text>;
Image: React Native's Image component handles image caching like browsers for the most part using react-native-fast-image
library.
For Example:
import { Image } from "@app/blueprints";
<Image source={sourcePath} {...props} />;
Indicator: Show loader in app with customize way. use it form context of app. For Example:
const { loader } = useAppContext();
//to show Indicator
loader.current.show();
//to hide Indicator
loader.current.hide();
//get Indicator status
loader.current.isLoading;
Button: Animated scalability adds an extra layer of interactivity to your buttons with TouchableOpacity For Example:
import { Button } from "@app/blueprints";
<Button
buttonContainerStyle={{ marginTop: scaleHeight(15) }}
title="Go back"
{...TouchableOpacityProps}
/>;
TextInput: Material UI all input variant added. For Example:
import { Input } from "@app/blueprints";
<Input variant="standard" {...TextInputProps} />;
├── src
│ ├── assets
│ ├── components
│ ├── constants
│ ├── context
│ ├── hooks
│ ├── i18n
│ ├── navigation
│ ├── screens
│ ├── services
│ ├── store
│ ├── utils
└── MainApp.tsx
src: Contains the main source code of your application.
├── src
│ ├── services
│ ├──├──commercial
│ ├──├──├──response
│ ├──├──├──├── getLoginResponseAdapter.ts
│ ├──├──├──├── getNesListResponseAdapter.ts
│ ├──├──├──├── ...
│ ├── dtos
│ ├──├── LoginResponseDTO.ts
│ ├──├── NewsListResponseDTO.ts
│ ├──├── ...
│ ├── models
│ ├──├── login.ts
│ ├──├── news.ts
│ ├──├── ...
│ ├── apiHandler
│ ├── apiServices
│ ├── apiServices.type
│ ├── apiServicesEndPoints
│ ├── ...
└── ...
├── src
│ ├── screens
│ ├──├── newsList
│ ├──├──├── newsList.style.ts
│ ├──├──├── newListScreen.tsx
│ ├──├──├── useNewsList.ts
│ ├──├── login
│ ├──├──├── login.style.ts
│ ├──├──├── loginScreen.tsx
│ ├──├──├── useLogin.ts
│ ├── ...
└── ...
├── src
│ ├── assets
│ ├──├── fonts (all fonts in this)
│ ├──├── icons (app icons)
│ ├──├── svgIcons (svg app icons)
│ ├──├── images (local images used in app)
│ ├──├── ...
│ ├── components
│ ├──├── ... app reusable components
│ ├──├── index (export all in this)
│ ├──├── ...
│ ├── context
│ ├──├── storage (app local storage)
│ ├──├── ...
│ ├── i18n
│ ├──├── locales
│ ├──├──├── en.json
│ ├──├──├── ...
│ ├──├── index.ts
│ ├──├── ...
│ ├── utils
│ ├──├── color (include themes color of app)
│ ├──├── dimensions (for responsive UI helper fucntions)
│ ├──├── helper (include app helper function)
│ ├──├── ...
└── ...
├── src
│ ├── navigation
│ ├──├── appNavigation (stack of all screens in this)
│ ├──├── appNavigation.type (include all screen names and params in this)
│ ├──├── ...
└── ...
Modules are collection of source files and build settings that allow you to divide a project into discrete units of functionality. In this case apart from dividing by functionality/responsibility, existing the following dependence between them:
The above graph shows the app modularization:
:app
depends on :context
and indirectly depends on :store
by dynamic-features.:context
modules depends on :theming
, :i18n
, :navigation
:services
and :app
.:store
redux store for global state management with redux persist state persistence.The boilerplate comes with a few configuration files that you can customize to fit your project's needs:
This set of helper functions provides a convenient way to create responsive user interfaces in your React Native applications. It helps in scaling and sizing UI elements based on the device's screen dimensions.
The following functions are available in this helper module:
scaleWidth(val: number): number
- Scales a value proportionally based on the device's screen width and the predefined design width.scaleHeight(val: number): number
- Scales a value proportionally based on the device's screen height and the predefined design height.moderateScale(size: number, factor = 1): number
- Scales a size value using a factor to provide a moderate scaling effect.scaledSize(size: number): number
- Scales a size value proportionally based on the overall screen scale.screenWidth: number
- The width of the device's screen.screenHeight: number
- The height of the device's screen.To utilize these functions for creating a responsive UI, follow these steps:
Import the required functions and variables from the helper module:
import {
scaleWidth,
scaleHeight,
moderateScale,
scaledSize,
screenWidth,
screenHeight,
} from "@src/utils/dimensions";
Use the functions in your styles or component logic to achieve responsive sizing:
const styles = StyleSheet.create({
container: {
width: scaleWidth(300),
height: scaleHeight(200),
marginVertical: moderateScale(10),
fontSize: scaledSize(16),
},
});
In this example, the width and height of the container will be scaled proportionally based on the device's screen width and height. The moderateScale
function is used to provide a moderate scaling effect to the margin, and the scaledSize
function is used to scale the font size.
Adjust the predefined design width and height if needed:
export const designWidth = 375;
export const designHeight = 812;
Modify these values according to your design specifications to ensure accurate scaling.
scaleWidth
and scaleHeight
functions are useful for scaling dimensions, such as width, height, padding, or margin values.moderateScale
function can be used to achieve a more subtle scaling effect by providing a factor that controls the degree of scaling.scaledSize
function is handy for scaling font sizes or any other numerical values that need to adapt to different screen sizes.Feel free to customize and extend these functions as per your project requirements to achieve the desired responsive behavior.
This boilerplate provides a convenient set of scripts to generate images and icons. You can find these scripts in the scripts
directory. Follow the instructions below to generate your assets:
Generating Images:
Place your source images in the src/assets/images
directory.
Run the following command to automatically import the images into the assets/images/index.ts file:
npm run images
Get your images in app from context For example:
getIcons: return JSX.Element;
const { getImages } = useAppContext();
use it in component as
<TouchableOpacity>
{getImages(`imageSource || Images.PLACEHOLDER_IMAGE`, { resizeMode: 'contain', style:styles.debugIcon, })}
</TouchableOpacity>
Generating Icons:
Place your source icon image in the src/assets/icons
directory.
Run the following command to automatically import the icons into the assets/icons/index.ts file:
npm run icons
Get your icon in app from context For example:
getIcons: return JSX.Element;
const { getIcons } = useAppContext();
use it in component as
<TouchableOpacity>
{getIcons(Icons.DEBUG_ICONS, {
resizeMode: "contain",
style: styles.debugIcon,
})}
</TouchableOpacity>
Linking fonts:
Place your fonts in the src/assets/fonts
directory.
Run the following command to automatically link on native side.
npx react-native-asset
For linking of custom that not in google fonts required extra steps in iOS.
This boilerplate uses the react-native-config
library for environment variable setup. It allows you to define environment-specific variables in .env
files and access them in your code.
Create .env
files:
.env.development
for development environment variables.env.staging
for staging environment variables.env.production
for production environment variablesNote: You can create additional .env
files for other environments as needed.
Define environment-specific variables in the .env
files:
API_BASE_URL=https://api.example.com
API_KEY=your-api-key
Customize the variables based on your project's requirements.
Access environment variables in your code:
Declare env keys in constants/config
file
export type ConfigTypes = {
ENV: string;
API_URL: string;
};
Config your api in src/services/apiHandler.ts
in this file set your all api handling request get | post | put | delete
or any methods in it. Set your api base url in axios instances. Handle response status as per required.
Api Mapper with DTOs: API Mapper with DTOs is a utility that simplifies the process of making API requests and mapping the response data to Data Transfer Objects (DTOs) in a React Native application.
Usage:
Declare
Create DTOs Create the DTOs (Data Transfer Objects) that represent the structure of the API response data. Each DTO should define the properties that match the response data fields.
For example, let's create a UserDTO to represent user data:
export interface UserResponseDTO {
page: number;
per_page: number;
total: number;
total_pages: number;
data: DatumDTO[];
support: SupportDTO;
}
export interface DatumDTO {
id: number;
email: string;
first_name: string;
last_name: string;
avatar: string;
}
export interface SupportDTO {
url: string;
text: string;
}
Define API Endpoints
API endpoints in your React Native application in src/services/appServicesEndPoints.ts
. These endpoints should include the URL, HTTP method, and any required headers or parameters.
Call api as per serviceAdapter methods in src/services/appServices.ts
.
Create a function in class:
getNews = async (): Promise<NewsResult[]> => {
return new Promise((resolve, reject) => {
serviceAdapter<NewsResponseDTO, undefined>(
API_METHODS.GET,
ServicesEndPoints.NEWS
)
.then((res) => {
resolve(new getNewsListResponseAdapter().service(res));
})
.catch((error) => {
reject(error);
});
});
};
Map your response in src/services/commercial/adapters/response
with your api name like for newList getNewsListResponseAdapter.ts
Call your api mapper DTOs to in services as show in 3rd point.
npm start
Feel free to customize the React Native Boilerplate to fit your project's specific needs. Here are some areas you might consider modifying:
App Configuration: Update the app's configuration files, such as app.json
, babel.config.js
and metro.config.js
, to match your desired settings.
Directory Structure: Adjust the project's directory structure to better organize your codebase.
Styling and Theming: Modify the existing styles and themes or add your own to create a unique visual identity for your app.
Additional Scripts: Extend the scripts
directory with your own scripts to automate repetitive tasks specific to your project.
Contributions to this boilerplate are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the repository.
react-native-boilerplate is MIT-licensed.
If you use our open-source libraries in your project, please make sure to credit us and Give a star to www.mindinventory.com
FAQs
React Native Template
The npm package @mindinventory/react-native-boilerplate receives a total of 40 weekly downloads. As such, @mindinventory/react-native-boilerplate popularity was classified as not popular.
We found that @mindinventory/react-native-boilerplate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.