Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
alpha-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.
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
Built in implemented features.
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.
Library | Category | Version | Description |
---|---|---|---|
React Native | Mobile Framework | v0.73 | The best cross-platform mobile framework |
React | UI Framework | v18 | The most popular UI framework in the world |
TypeScript | Language | v5 | Static typechecking |
React Navigation | Navigation | v6 | Performant and consistent navigation framework |
React Native Localization | Internationalization | v3 | i18n support (including RTL!) |
Redux | State Management | v5 | Observable state tree |
Redux-toolkit | Redux integration | v2 | 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:
Automation Script: This Node.js script streamlines React Native screen module creation by generating a folder structure with key files based on a provided folder name.
Features:
Efficiency Boost: Standardizing screen module creation, the script promotes development efficiency in React Native projects.
Run the Script:
yarn screens screeName
This Node.js script generates a TypeScript enum for React Native icons based on image files within the "../src/assets/icons" directory. It filters and organizes icon filenames, ensuring compatibility with multiple resolutions, and exports them within the generated enum.
Suppose the "../src/assets/icons" directory contains icon files like "home@2x.png" and "home@3x.png." Running the script creates a TypeScript enum (Icons) in "../src/assets/icons/index.ts," providing organized references to these icons:
yarn icons
export enum Icons {
HOME_ICONS = require("./home.png"),
// Other icons...
}
This Node.js script creates a TypeScript enum for React Native images, sourcing filenames from the "../src/assets/images" directory. It filters and organizes image files, accommodating different resolutions, and exports them as enum properties for easy referencing.
Assuming the "../src/assets/images" directory includes files like "background@2x.jpg" and "logo.png," running the script generates a TypeScript enum (Images) in "../src/assets/images/index.ts," providing organized references to these images:
yarn images
export enum Images {
BACKGROUND_IMAGE = require("./background.jpg"),
LOGO_IMAGE = require("./logo.png"),
// Other images...
}
This Bash script performs a cleanup and dependency reinstall for a React Native project. It removes various generated and dependency-related files, clears the node_modules directory, and then reinstalls dependencies using yarn. Additionally, it runs bundle and pod install commands for iOS.
yarn refresh
This TypeScript script generates a module for managing SVG icons in a React Native project. It extracts SVG filenames from the "../src/assets/svgIcons" directory, imports them as React components, and creates an enum for easy referencing. Additionally, it provides a mapper object for dynamically accessing SVG icons.
Note: Ensure your project includes a suitable React SVG library for rendering these components.
Run this script to create a TypeScript module managing SVG icons in your React Native project:
yarn svgs
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";
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 components For example:
import { AppImage, Images } from "@src/components";
use it in component as
get local static Images from same assets
import { Images } from "@src/assets";
For Placing static image from local assets
<AppImage source="{Images.PLACEHOLDER_IMAGE}" style="{styles.newsImage}" />
To get from url or any base64
<AppImage source={"url || any"} style={styles.newsImage} />
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 components For example:
import { Icon, SvgIcon } from "@src/components";
get local static Icons and SVGIcons from same assets
import { Icons, SVGIcons } from "@src/assets";
use it in component as
<Icon icon="{Icons.DEBUG_ICONS}" style="{styles.debugIcon}" />
<SvgIcon
pathFill="{color.primaryColor}"
icon="{SVGIcons.SETTING}"
{...scaled(25)}
/>
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.
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.json
, babel.config.js
and metro.config.js
, to match your desired settings.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 alpha-react-native-boilerplate receives a total of 0 weekly downloads. As such, alpha-react-native-boilerplate popularity was classified as not popular.
We found that alpha-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 1 open source maintainer 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.