@vijayp-07/react-native-boiler-plate 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +355 -64
- package/package.json +1 -1
- package/template/README.md +108 -5
- package/template/src/api/apiMethods.ts +65 -0
- package/template/src/api/axiosInstance.ts +10 -20
- package/template/src/api/endPoints.ts +18 -0
- package/template/src/api/index.ts +3 -0
- package/template/src/appRedux/modules/ProfileSlice.ts +3 -3
- package/template/src/assets/images/IC_HidePassword.svg +4 -0
- package/template/src/assets/images/IC_ShowPassword.svg +4 -0
- package/template/src/assets/images/index.ts +4 -0
- package/template/src/components/Container.tsx +62 -0
- package/template/src/components/PrimaryFlashMessage.tsx +0 -2
- package/template/src/components/PrimaryLoader.tsx +1 -1
- package/template/src/components/PrimaryTextInput.tsx +84 -0
- package/template/src/components/index.ts +4 -0
- package/template/src/i18n/en.json +12 -8
- package/template/src/i18n/es.json +13 -9
- package/template/src/i18n/hi.json +34 -0
- package/template/src/i18n/i18n.ts +5 -1
- package/template/src/screens/Home/index.tsx +3 -10
- package/template/src/screens/Login/index.tsx +69 -17
- package/template/src/screens/ModalScreen/index.tsx +1 -1
- package/template/src/screens/Profile/index.tsx +11 -3
- package/template/src/services/authService.ts +23 -0
- package/template/src/services/index.ts +1 -0
- package/template/src/types/index.ts +72 -6
- package/template/yarn.lock +7488 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vijayp-07/react-native-boiler-plate
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A production-ready React Native boilerplate with navigation, Redux, i18n, axios, and more — pre-configured so you can focus on building features.
|
|
4
4
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
@@ -8,77 +8,368 @@ A professional, production-ready React Native template with TypeScript, Redux To
|
|
|
8
8
|
npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-native-boiler-plate
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
├──
|
|
38
|
-
├──
|
|
39
|
-
├──
|
|
40
|
-
├──
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
├──
|
|
44
|
-
├──
|
|
45
|
-
├──
|
|
46
|
-
└──
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Navigation:** React Navigation with separate `AuthStack`, `AppStack`, `TabNavigator`, and a typed `RootNavigationRef` for navigating outside components
|
|
14
|
+
- **Redux:** Redux Toolkit setup with `LoaderSlice` and `ProfileSlice`, typed `useAppSelector` / `useAppDispatch` hooks
|
|
15
|
+
- **Axios:** Pre-configured `axiosInstance` with request/response interceptors for auth token injection and error handling (401, 500, network errors)
|
|
16
|
+
- **API Layer:** Generic `apiGet`, `apiPost`, `apiPut`, `apiPatch`, `apiDelete` helpers wrapping `axiosInstance` with unified `ApiResponseType` response shape. Centralised `endPoints` object for all API paths
|
|
17
|
+
- **Auth Service:** `loginService` in `src/services/authService.ts` — ready-to-use login API call with device info attached
|
|
18
|
+
- **Internationalization (i18n):** i18next + react-i18next with English, Spanish, and **Hindi** locale support
|
|
19
|
+
- **TypeScript:** Full type coverage including navigation param lists, screen props, `ApiResponseType`, `LoginPayload`, `LoginResponse`, and `Languages` union type
|
|
20
|
+
- **Babel Aliases:** Clean imports via path aliases (e.g. `@screens`, `@components`, `@appRedux`)
|
|
21
|
+
- **Custom Components:** `PrimaryLoader`, `PrimaryText`, `PrimaryButton`, `PrimaryFlashMessage`, `PrimaryScrollView`, `NoInternetModalPopUp`, `Container`, `PrimaryTextInput`
|
|
22
|
+
- **Asset Management:** Fonts (Poppins) and SVG images with centralized exports, including `IC_HidePassword` and `IC_ShowPassword`
|
|
23
|
+
- **Async Storage:** Utility wrappers for AsyncStorage via `@common`
|
|
24
|
+
- **Network Detection:** `NoInternetModalPopUp` using `@react-native-community/netinfo`
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- Node >= 22.11.0
|
|
29
|
+
- React Native 0.84.1
|
|
30
|
+
- React 19.2.3
|
|
31
|
+
|
|
32
|
+
## Project Structure
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
📁src
|
|
36
|
+
│
|
|
37
|
+
├── 📁api
|
|
38
|
+
│ ├── axiosInstance.ts # Axios instance with request/response interceptors
|
|
39
|
+
│ ├── apiMethods.ts # Generic apiGet/apiPost/apiPut/apiPatch/apiDelete helpers
|
|
40
|
+
│ ├── endpoints.ts # Centralised API endpoint paths grouped by feature
|
|
41
|
+
│ └── index.ts
|
|
42
|
+
│
|
|
43
|
+
├── 📁appRedux
|
|
44
|
+
│ ├── 📁modules
|
|
45
|
+
│ │ ├── LoaderSlice.ts # Global loader state
|
|
46
|
+
│ │ └── ProfileSlice.ts # User auth/profile state
|
|
47
|
+
│ └── index.ts # Store setup, typed hooks, slice exports
|
|
48
|
+
│
|
|
49
|
+
├── 📁assets
|
|
50
|
+
│ ├── 📁fonts
|
|
51
|
+
│ │ ├── Poppins-*.ttf
|
|
52
|
+
│ │ └── index.ts
|
|
53
|
+
│ ├── 📁images
|
|
54
|
+
│ │ ├── IC_Home_Active.svg
|
|
55
|
+
│ │ ├── IC_Home_UnActive.svg
|
|
56
|
+
│ │ ├── IC_Setting_Active.svg
|
|
57
|
+
│ │ ├── IC_Setting_UnActive.svg
|
|
58
|
+
│ │ ├── IC_HidePassword.svg
|
|
59
|
+
│ │ ├── IC_ShowPassword.svg
|
|
60
|
+
│ │ └── index.ts
|
|
61
|
+
│ └── index.ts
|
|
62
|
+
│
|
|
63
|
+
├── 📁common
|
|
64
|
+
│ ├── asyncServices.ts # AsyncStorage get/set/clear helpers
|
|
65
|
+
│ ├── constant.ts # App-wide constants (BASE_URL, ASYNC_KEY, etc.)
|
|
66
|
+
│ ├── helperFunctions.ts # Utility functions (showDangerMessage, prettyPrint, etc.)
|
|
67
|
+
│ └── index.ts
|
|
68
|
+
│
|
|
69
|
+
├── 📁components
|
|
70
|
+
│ ├── Container.tsx # Safe-area-aware full-screen wrapper with padding control
|
|
71
|
+
│ ├── NoInternetModalPopUp.tsx
|
|
72
|
+
│ ├── PrimaryButton.tsx
|
|
73
|
+
│ ├── PrimaryFlashMessage.tsx # Animated toast with fade in/out, per-type styling
|
|
74
|
+
│ ├── PrimaryLoader.tsx
|
|
75
|
+
│ ├── PrimaryScrollView.tsx # Keyboard-aware ScrollView, auto-scrolls to focused input
|
|
76
|
+
│ ├── PrimaryText.tsx
|
|
77
|
+
│ ├── PrimaryTextInput.tsx # TextInput with password show/hide toggle
|
|
78
|
+
│ └── index.ts
|
|
79
|
+
│
|
|
80
|
+
├── 📁hooks
|
|
81
|
+
│ └── index.ts
|
|
82
|
+
│
|
|
83
|
+
├── 📁i18n
|
|
84
|
+
│ ├── en.json # English translations
|
|
85
|
+
│ ├── es.json # Spanish translations
|
|
86
|
+
│ ├── hi.json # Hindi translations
|
|
87
|
+
│ ├── i18n.ts # i18next configuration
|
|
88
|
+
│ └── index.ts
|
|
89
|
+
│
|
|
90
|
+
├── 📁navigation
|
|
91
|
+
│ ├── AuthStack.tsx # Unauthenticated screens (LogIn)
|
|
92
|
+
│ ├── AppStack.tsx # Authenticated screens (TabNavigation, ModalScreen)
|
|
93
|
+
│ ├── MainNavigation.tsx # Root NavigationContainer, switches Auth/App stack
|
|
94
|
+
│ ├── RootNavigationRef.ts # Typed navigationRef + navigate/goBack/resetRoot helpers
|
|
95
|
+
│ ├── TabNavigator.tsx # Bottom tab navigator (Home, Profile)
|
|
96
|
+
│ └── index.ts
|
|
97
|
+
│
|
|
98
|
+
├── 📁screens
|
|
99
|
+
│ ├── 📁Home
|
|
100
|
+
│ │ └── index.tsx
|
|
101
|
+
│ ├── 📁Login
|
|
102
|
+
│ │ └── index.tsx
|
|
103
|
+
│ ├── 📁ModalScreen
|
|
104
|
+
│ │ └── index.tsx
|
|
105
|
+
│ ├── 📁Profile
|
|
106
|
+
│ │ └── index.tsx
|
|
107
|
+
│ └── index.ts
|
|
108
|
+
│
|
|
109
|
+
├── 📁services
|
|
110
|
+
│ ├── authService.ts # Login API call (loginService)
|
|
111
|
+
│ └── index.ts
|
|
112
|
+
│
|
|
113
|
+
├── 📁static
|
|
114
|
+
│ └── index.ts
|
|
115
|
+
│
|
|
116
|
+
├── 📁theme
|
|
117
|
+
│ ├── colors.ts
|
|
118
|
+
│ ├── dimensions.ts # perfectSize helper
|
|
119
|
+
│ ├── styles.ts
|
|
120
|
+
│ └── index.ts
|
|
121
|
+
│
|
|
122
|
+
├── 📁types
|
|
123
|
+
│ ├── declarations.d.ts # SVG and module declarations
|
|
124
|
+
│ └── index.ts # Navigation param lists, screen props, ApiResponseType, LoginPayload, LoginResponse, Languages
|
|
125
|
+
│
|
|
126
|
+
└── index.tsx # App entry point
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Custom Components
|
|
130
|
+
|
|
131
|
+
### Container
|
|
132
|
+
|
|
133
|
+
A safe-area-aware full-screen wrapper. Automatically applies top/bottom safe area insets and supports granular padding control per side.
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import {Container} from '@components';
|
|
137
|
+
|
|
138
|
+
<Container backgroundColor="#fff" padding={16}>
|
|
139
|
+
{/* screen content */}
|
|
140
|
+
</Container>
|
|
141
|
+
|
|
142
|
+
// Hide bottom safe area (e.g. screens with a fixed bottom bar)
|
|
143
|
+
<Container hideBottomSafeArea>
|
|
144
|
+
{/* screen content */}
|
|
145
|
+
</Container>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### PrimaryTextInput
|
|
149
|
+
|
|
150
|
+
A styled `TextInput` with a built-in password show/hide toggle. Supports all standard `TextInputProps` plus `isPassword` and `containerStyle`.
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import {PrimaryTextInput} from '@components';
|
|
154
|
+
|
|
155
|
+
<PrimaryTextInput
|
|
156
|
+
placeholder="Email"
|
|
157
|
+
value={email}
|
|
158
|
+
onChangeText={setEmail}
|
|
159
|
+
/>
|
|
160
|
+
|
|
161
|
+
<PrimaryTextInput
|
|
162
|
+
placeholder="Password"
|
|
163
|
+
isPassword
|
|
164
|
+
value={password}
|
|
165
|
+
onChangeText={setPassword}
|
|
166
|
+
/>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### PrimaryFlashMessage
|
|
170
|
+
|
|
171
|
+
Animated toast notification with per-type styling (success, danger, warning, info). Fade in/out animation is driven by `animationDuration`. Rendered via a custom `FlashMessageComponent` for full layout control.
|
|
52
172
|
|
|
53
173
|
```ts
|
|
54
|
-
import {
|
|
55
|
-
|
|
56
|
-
|
|
174
|
+
import {showSuccessMessage, showDangerMessage} from '@common';
|
|
175
|
+
|
|
176
|
+
// Success
|
|
177
|
+
showSuccessMessage('Saved!');
|
|
178
|
+
|
|
179
|
+
// Error
|
|
180
|
+
showDangerMessage('Something went wrong');
|
|
181
|
+
|
|
182
|
+
// With description
|
|
183
|
+
showDangerMessage('Check your input', {description: 'Email is invalid'});
|
|
184
|
+
|
|
185
|
+
// With a local FlashMessage ref
|
|
186
|
+
showSuccessMessage('Profile updated!', {}, flashRef);
|
|
187
|
+
showDangerMessage('Upload failed', {description: 'Try again'}, flashRef);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### PrimaryScrollView
|
|
191
|
+
|
|
192
|
+
A keyboard-aware `ScrollView` that automatically scrolls the focused `TextInput` into view when the keyboard opens. The scroll offset is calculated dynamically based on the actual height of the focused input.
|
|
193
|
+
|
|
194
|
+
```tsx
|
|
195
|
+
import {PrimaryScrollView} from '@components';
|
|
196
|
+
|
|
197
|
+
<PrimaryScrollView>
|
|
198
|
+
<TextInput placeholder="Email" />
|
|
199
|
+
<TextInput placeholder="Password" />
|
|
200
|
+
</PrimaryScrollView>;
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
To adjust the gap above the focused input, change the padding value inside `PrimaryScrollView.tsx`:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
// Adjust the padding value (height - perfectSize(12)) to control the gap above the focused input.
|
|
207
|
+
y: Math.max(0, y - height - perfectSize(12));
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## API Layer
|
|
211
|
+
|
|
212
|
+
### API Methods
|
|
213
|
+
|
|
214
|
+
Generic typed helpers wrapping `axiosInstance`. All return a unified `ApiResponseType<T>` — no need for try/catch in your services.
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import {apiGet, apiPost, apiPut, apiPatch, apiDelete} from '@api';
|
|
218
|
+
|
|
219
|
+
const res = await apiGet<User[]>('/users');
|
|
220
|
+
const res = await apiPost<LoginResponse>(endPoints.auth.login, payload);
|
|
57
221
|
```
|
|
58
222
|
|
|
59
|
-
|
|
223
|
+
### Endpoints
|
|
224
|
+
|
|
225
|
+
All API paths are centralised in `src/api/endpoints.ts`, grouped by feature:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import {endPoints} from '@api';
|
|
229
|
+
|
|
230
|
+
endPoints.auth.login // '/auth/login'
|
|
231
|
+
endPoints.auth.register // '/auth/register'
|
|
232
|
+
endPoints.auth.forgotPassword // '/auth/forgot-password'
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Add new feature groups directly in `endpoints.ts`.
|
|
236
|
+
|
|
237
|
+
### Auth Service
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
import {loginService} from '@services';
|
|
241
|
+
|
|
242
|
+
const res = await loginService({email: 'user@example.com', password: 'secret'});
|
|
243
|
+
if (res.success) {
|
|
244
|
+
// res.data is typed as LoginResponse
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Internationalisation (i18n)
|
|
249
|
+
|
|
250
|
+
Three locales are supported out of the box: **English** (`en`), **Spanish** (`es`), and **Hindi** (`hi`).
|
|
251
|
+
|
|
252
|
+
The `Languages` type (`'en' | 'es' | 'hi'`) is used across `ProfileSlice`, `onChangeLanguage`, and `setLanguage` for full type safety.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
import {setLanguage} from '@appRedux';
|
|
256
|
+
|
|
257
|
+
dispatch(setLanguage('hi')); // switch to Hindi
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
To add a new language:
|
|
261
|
+
1. Add a new JSON file in `src/i18n/` (e.g. `fr.json`)
|
|
262
|
+
2. Import and register it in `i18n.ts`
|
|
263
|
+
3. Add `'fr'` to the `Languages` type in `src/types/index.ts`
|
|
264
|
+
|
|
265
|
+
## Navigation Structure
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
MainNavigation (NavigationContainer)
|
|
269
|
+
│
|
|
270
|
+
├── AuthStack → LogIn
|
|
271
|
+
│
|
|
272
|
+
└── AppStack
|
|
273
|
+
├── TabNavigator
|
|
274
|
+
│ ├── Home
|
|
275
|
+
│ └── Profile
|
|
276
|
+
└── ModalScreen (transparentModal)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Screen Prop Types
|
|
280
|
+
|
|
281
|
+
| Type | Use for |
|
|
282
|
+
| ----------------------------- | ---------------------------------------------------- |
|
|
283
|
+
| `AuthStackScreenProps<T>` | Screens inside `AuthStack` (e.g. `LogIn`) |
|
|
284
|
+
| `AppStackScreenProps<T>` | Screens inside `AppStack` (e.g. `ModalScreen`) |
|
|
285
|
+
| `TabNavigationScreenProps<T>` | Tab screens that only use tab navigation |
|
|
286
|
+
| `CompositeTabScreenProps<T>` | Tab screens that also navigate to `AppStack` screens |
|
|
287
|
+
|
|
288
|
+
### Navigating Outside Components
|
|
289
|
+
|
|
290
|
+
Use the helpers from `@navigation` anywhere (services, redux, axios interceptors):
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
import {navigate, goBack, resetRoot} from '@navigation';
|
|
294
|
+
|
|
295
|
+
navigate('LogIn');
|
|
296
|
+
navigate('ModalScreen');
|
|
297
|
+
resetRoot({index: 0, routes: [{name: 'LogIn'}]});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Babel Aliases
|
|
301
|
+
|
|
302
|
+
| Alias | Path |
|
|
303
|
+
| ------------- | --------------------- |
|
|
304
|
+
| `@api` | `./src/api` |
|
|
305
|
+
| `@appRedux` | `./src/appRedux` |
|
|
306
|
+
| `@assets` | `./src/assets` |
|
|
307
|
+
| `@common` | `./src/common` |
|
|
308
|
+
| `@components` | `./src/components` |
|
|
309
|
+
| `@fonts` | `./src/assets/fonts` |
|
|
310
|
+
| `@hooks` | `./src/hooks` |
|
|
311
|
+
| `@i18n` | `./src/i18n` |
|
|
312
|
+
| `@images` | `./src/assets/images` |
|
|
313
|
+
| `@navigation` | `./src/navigation` |
|
|
314
|
+
| `@screens` | `./src/screens` |
|
|
315
|
+
| `@services` | `./src/services` |
|
|
316
|
+
| `@static` | `./src/static` |
|
|
317
|
+
| `@theme` | `./src/theme` |
|
|
318
|
+
| `@types` | `./src/types` |
|
|
319
|
+
|
|
320
|
+
## Adding a New Alias
|
|
321
|
+
|
|
322
|
+
1. Create a folder inside `src/` with an `index.ts` that exports everything from it.
|
|
323
|
+
|
|
324
|
+
2. Add the alias to `babel.config.js`:
|
|
325
|
+
|
|
326
|
+
```js
|
|
327
|
+
alias: {
|
|
328
|
+
'@newAlias': './src/newFolder',
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
3. Add the path to `tsconfig.json`:
|
|
333
|
+
|
|
334
|
+
```json
|
|
335
|
+
"paths": {
|
|
336
|
+
"@newAlias": ["./src/newFolder"]
|
|
337
|
+
}
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Getting Started
|
|
341
|
+
|
|
342
|
+
Install dependencies:
|
|
60
343
|
|
|
61
344
|
```bash
|
|
62
|
-
|
|
63
|
-
yarn ios # Run on iOS
|
|
64
|
-
yarn start # Start Metro bundler
|
|
65
|
-
yarn lint # Run ESLint
|
|
66
|
-
yarn lint:fix # Auto-fix lint issues
|
|
67
|
-
yarn format # Format with Prettier
|
|
68
|
-
yarn test # Run Jest tests
|
|
69
|
-
yarn test:coverage # Run tests with coverage
|
|
70
|
-
yarn clean # Clean React Native cache
|
|
71
|
-
yarn clean:android # Clean Android build
|
|
72
|
-
yarn clean:ios # Clean iOS build
|
|
345
|
+
npm install
|
|
73
346
|
```
|
|
74
347
|
|
|
75
|
-
|
|
348
|
+
iOS — install pods (first time or after native dependency changes):
|
|
76
349
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
350
|
+
```bash
|
|
351
|
+
bundle install
|
|
352
|
+
bundle exec pod install
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Run on Android:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
npm run android
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Run on iOS:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
npm run ios
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Start Metro:
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
npm start
|
|
371
|
+
```
|
|
81
372
|
|
|
82
|
-
|
|
373
|
+
---
|
|
83
374
|
|
|
84
|
-
|
|
375
|
+
Powered by [React Native](https://reactnative.dev)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vijayp-07/react-native-boiler-plate",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A professional, production-ready React Native boilerplate template with TypeScript, Redux Toolkit, React Navigation, Axios, i18n, SVG support, and scalable architecture.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
package/template/README.md
CHANGED
|
@@ -13,11 +13,13 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
13
13
|
- **Navigation:** React Navigation with separate `AuthStack`, `AppStack`, `TabNavigator`, and a typed `RootNavigationRef` for navigating outside components
|
|
14
14
|
- **Redux:** Redux Toolkit setup with `LoaderSlice` and `ProfileSlice`, typed `useAppSelector` / `useAppDispatch` hooks
|
|
15
15
|
- **Axios:** Pre-configured `axiosInstance` with request/response interceptors for auth token injection and error handling (401, 500, network errors)
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
16
|
+
- **API Layer:** Generic `apiGet`, `apiPost`, `apiPut`, `apiPatch`, `apiDelete` helpers wrapping `axiosInstance` with unified `ApiResponseType` response shape. Centralised `endPoints` object for all API paths
|
|
17
|
+
- **Auth Service:** `loginService` in `src/services/authService.ts` — ready-to-use login API call with device info attached
|
|
18
|
+
- **Internationalization (i18n):** i18next + react-i18next with English, Spanish, and **Hindi** locale support
|
|
19
|
+
- **TypeScript:** Full type coverage including navigation param lists, screen props, `ApiResponseType`, `LoginPayload`, `LoginResponse`, and `Languages` union type
|
|
18
20
|
- **Babel Aliases:** Clean imports via path aliases (e.g. `@screens`, `@components`, `@appRedux`)
|
|
19
|
-
- **Custom Components:** `PrimaryLoader`, `PrimaryText`, `PrimaryButton`, `PrimaryFlashMessage`, `PrimaryScrollView`, `NoInternetModalPopUp`
|
|
20
|
-
- **Asset Management:** Fonts (Poppins) and SVG images with centralized exports
|
|
21
|
+
- **Custom Components:** `PrimaryLoader`, `PrimaryText`, `PrimaryButton`, `PrimaryFlashMessage`, `PrimaryScrollView`, `NoInternetModalPopUp`, `Container`, `PrimaryTextInput`
|
|
22
|
+
- **Asset Management:** Fonts (Poppins) and SVG images with centralized exports, including `IC_HidePassword` and `IC_ShowPassword`
|
|
21
23
|
- **Async Storage:** Utility wrappers for AsyncStorage via `@common`
|
|
22
24
|
- **Network Detection:** `NoInternetModalPopUp` using `@react-native-community/netinfo`
|
|
23
25
|
|
|
@@ -34,6 +36,8 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
34
36
|
│
|
|
35
37
|
├── 📁api
|
|
36
38
|
│ ├── axiosInstance.ts # Axios instance with request/response interceptors
|
|
39
|
+
│ ├── apiMethods.ts # Generic apiGet/apiPost/apiPut/apiPatch/apiDelete helpers
|
|
40
|
+
│ ├── endpoints.ts # Centralised API endpoint paths grouped by feature
|
|
37
41
|
│ └── index.ts
|
|
38
42
|
│
|
|
39
43
|
├── 📁appRedux
|
|
@@ -51,6 +55,8 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
51
55
|
│ │ ├── IC_Home_UnActive.svg
|
|
52
56
|
│ │ ├── IC_Setting_Active.svg
|
|
53
57
|
│ │ ├── IC_Setting_UnActive.svg
|
|
58
|
+
│ │ ├── IC_HidePassword.svg
|
|
59
|
+
│ │ ├── IC_ShowPassword.svg
|
|
54
60
|
│ │ └── index.ts
|
|
55
61
|
│ └── index.ts
|
|
56
62
|
│
|
|
@@ -61,12 +67,14 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
61
67
|
│ └── index.ts
|
|
62
68
|
│
|
|
63
69
|
├── 📁components
|
|
70
|
+
│ ├── Container.tsx # Safe-area-aware full-screen wrapper with padding control
|
|
64
71
|
│ ├── NoInternetModalPopUp.tsx
|
|
65
72
|
│ ├── PrimaryButton.tsx
|
|
66
73
|
│ ├── PrimaryFlashMessage.tsx # Animated toast with fade in/out, per-type styling
|
|
67
74
|
│ ├── PrimaryLoader.tsx
|
|
68
75
|
│ ├── PrimaryScrollView.tsx # Keyboard-aware ScrollView, auto-scrolls to focused input
|
|
69
76
|
│ ├── PrimaryText.tsx
|
|
77
|
+
│ ├── PrimaryTextInput.tsx # TextInput with password show/hide toggle
|
|
70
78
|
│ └── index.ts
|
|
71
79
|
│
|
|
72
80
|
├── 📁hooks
|
|
@@ -75,6 +83,7 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
75
83
|
├── 📁i18n
|
|
76
84
|
│ ├── en.json # English translations
|
|
77
85
|
│ ├── es.json # Spanish translations
|
|
86
|
+
│ ├── hi.json # Hindi translations
|
|
78
87
|
│ ├── i18n.ts # i18next configuration
|
|
79
88
|
│ └── index.ts
|
|
80
89
|
│
|
|
@@ -98,6 +107,7 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
98
107
|
│ └── index.ts
|
|
99
108
|
│
|
|
100
109
|
├── 📁services
|
|
110
|
+
│ ├── authService.ts # Login API call (loginService)
|
|
101
111
|
│ └── index.ts
|
|
102
112
|
│
|
|
103
113
|
├── 📁static
|
|
@@ -111,13 +121,51 @@ npx @react-native-community/cli@latest init MyApp --template @vijayp-07/react-na
|
|
|
111
121
|
│
|
|
112
122
|
├── 📁types
|
|
113
123
|
│ ├── declarations.d.ts # SVG and module declarations
|
|
114
|
-
│ └── index.ts # Navigation param lists
|
|
124
|
+
│ └── index.ts # Navigation param lists, screen props, ApiResponseType, LoginPayload, LoginResponse, Languages
|
|
115
125
|
│
|
|
116
126
|
└── index.tsx # App entry point
|
|
117
127
|
```
|
|
118
128
|
|
|
119
129
|
## Custom Components
|
|
120
130
|
|
|
131
|
+
### Container
|
|
132
|
+
|
|
133
|
+
A safe-area-aware full-screen wrapper. Automatically applies top/bottom safe area insets and supports granular padding control per side.
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import {Container} from '@components';
|
|
137
|
+
|
|
138
|
+
<Container backgroundColor="#fff" padding={16}>
|
|
139
|
+
{/* screen content */}
|
|
140
|
+
</Container>
|
|
141
|
+
|
|
142
|
+
// Hide bottom safe area (e.g. screens with a fixed bottom bar)
|
|
143
|
+
<Container hideBottomSafeArea>
|
|
144
|
+
{/* screen content */}
|
|
145
|
+
</Container>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### PrimaryTextInput
|
|
149
|
+
|
|
150
|
+
A styled `TextInput` with a built-in password show/hide toggle. Supports all standard `TextInputProps` plus `isPassword` and `containerStyle`.
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import {PrimaryTextInput} from '@components';
|
|
154
|
+
|
|
155
|
+
<PrimaryTextInput
|
|
156
|
+
placeholder="Email"
|
|
157
|
+
value={email}
|
|
158
|
+
onChangeText={setEmail}
|
|
159
|
+
/>
|
|
160
|
+
|
|
161
|
+
<PrimaryTextInput
|
|
162
|
+
placeholder="Password"
|
|
163
|
+
isPassword
|
|
164
|
+
value={password}
|
|
165
|
+
onChangeText={setPassword}
|
|
166
|
+
/>
|
|
167
|
+
```
|
|
168
|
+
|
|
121
169
|
### PrimaryFlashMessage
|
|
122
170
|
|
|
123
171
|
Animated toast notification with per-type styling (success, danger, warning, info). Fade in/out animation is driven by `animationDuration`. Rendered via a custom `FlashMessageComponent` for full layout control.
|
|
@@ -159,6 +207,61 @@ To adjust the gap above the focused input, change the padding value inside `Prim
|
|
|
159
207
|
y: Math.max(0, y - height - perfectSize(12));
|
|
160
208
|
```
|
|
161
209
|
|
|
210
|
+
## API Layer
|
|
211
|
+
|
|
212
|
+
### API Methods
|
|
213
|
+
|
|
214
|
+
Generic typed helpers wrapping `axiosInstance`. All return a unified `ApiResponseType<T>` — no need for try/catch in your services.
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import {apiGet, apiPost, apiPut, apiPatch, apiDelete} from '@api';
|
|
218
|
+
|
|
219
|
+
const res = await apiGet<User[]>('/users');
|
|
220
|
+
const res = await apiPost<LoginResponse>(endPoints.auth.login, payload);
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Endpoints
|
|
224
|
+
|
|
225
|
+
All API paths are centralised in `src/api/endpoints.ts`, grouped by feature:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import {endPoints} from '@api';
|
|
229
|
+
|
|
230
|
+
endPoints.auth.login // '/auth/login'
|
|
231
|
+
endPoints.auth.register // '/auth/register'
|
|
232
|
+
endPoints.auth.forgotPassword // '/auth/forgot-password'
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Add new feature groups directly in `endpoints.ts`.
|
|
236
|
+
|
|
237
|
+
### Auth Service
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
import {loginService} from '@services';
|
|
241
|
+
|
|
242
|
+
const res = await loginService({email: 'user@example.com', password: 'secret'});
|
|
243
|
+
if (res.success) {
|
|
244
|
+
// res.data is typed as LoginResponse
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Internationalisation (i18n)
|
|
249
|
+
|
|
250
|
+
Three locales are supported out of the box: **English** (`en`), **Spanish** (`es`), and **Hindi** (`hi`).
|
|
251
|
+
|
|
252
|
+
The `Languages` type (`'en' | 'es' | 'hi'`) is used across `ProfileSlice`, `onChangeLanguage`, and `setLanguage` for full type safety.
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
import {setLanguage} from '@appRedux';
|
|
256
|
+
|
|
257
|
+
dispatch(setLanguage('hi')); // switch to Hindi
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
To add a new language:
|
|
261
|
+
1. Add a new JSON file in `src/i18n/` (e.g. `fr.json`)
|
|
262
|
+
2. Import and register it in `i18n.ts`
|
|
263
|
+
3. Add `'fr'` to the `Languages` type in `src/types/index.ts`
|
|
264
|
+
|
|
162
265
|
## Navigation Structure
|
|
163
266
|
|
|
164
267
|
```
|