@umang-thakkar/base-template 1.0.8 → 1.1.0

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 CHANGED
@@ -3,6 +3,7 @@
3
3
  A React Native boilerplate to kickstart your mobile app development faster, with preconfigured essentials like:
4
4
 
5
5
  - 🔁 Redux Toolkit for scalable state management
6
+ - 💾 Redux Persist for auth persistence across sessions
6
7
  - 📍 React Navigation for robust navigation
7
8
  - 🔗 React Query for powerful API data fetching and caching
8
9
  - 🌙 Dark/Light theme support with system preference detection
@@ -14,6 +15,7 @@ A React Native boilerplate to kickstart your mobile app development faster, with
14
15
  ## 📦 Features
15
16
 
16
17
  - ✅ Redux Toolkit with example slices and hooks
18
+ - ✅ Redux Persist with auth slice persistence (user data + access token)
17
19
  - ✅ React Navigation with Stack Navigator setup
18
20
  - ✅ React Query for API management (see `src/api/queries.ts`)
19
21
  - ✅ Dark/Light theme support with automatic system detection
@@ -62,12 +64,14 @@ template/
62
64
  │ │ └── screens.ts
63
65
  │ ├── redux/ # Redux store, slices, types
64
66
  │ │ ├── action.ts
65
- │ │ ├── slice.ts
66
- │ │ ├── store.ts
67
+ │ │ ├── slices/
68
+ │ │ │ └── authSlice.ts # Auth slice with user data + token state
69
+ │ │ ├── store.ts # Store with redux-persist configuration
67
70
  │ │ └── types.d.ts
68
71
  │ ├── screens/ # App screens
69
72
  │ │ ├── HomeScreen.tsx
70
- │ │ └── SplashScreen.tsx
73
+ │ │ ├── LoginScreen.tsx # Demo login screen — saves user + token to auth slice
74
+ │ │ └── SplashScreen.tsx # Reads accessToken from Redux to decide initial route
71
75
  │ ├── theme/ # Theme configuration
72
76
  │ │ ├── darkTheme.ts # Dark theme colors
73
77
  │ │ ├── lightTheme.ts # Light theme colors
@@ -81,30 +85,32 @@ template/
81
85
 
82
86
  ## 🚀 Getting Started
83
87
 
84
- 1. Create a new project using this template:
88
+ 1. Create a new project using this template:
85
89
  ```sh
86
90
  npx @react-native-community/cli init MyApp --template @umang-thakkar/base-template
87
91
  ```
92
+
88
93
  ```
89
94
  Note: Replace MyApp with your own project name.
90
95
  ```
91
96
 
92
97
  2. Install dependencies:
93
- ```sh
94
- npm install
95
- ```
98
+ ```sh
99
+ npm install
100
+ ```
96
101
  3. Start Metro server:
97
- ```sh
98
- npx react-native start
99
- ```
102
+ ```sh
103
+ npx react-native start
104
+ ```
100
105
  4. Run the app:
101
- ```sh
102
- # For Android
103
- npx react-native run-android
104
-
105
- # For iOS
106
- npx react-native run-ios
107
- ```
106
+
107
+ ```sh
108
+ # For Android
109
+ npx react-native run-android
110
+
111
+ # For iOS
112
+ npx react-native run-ios
113
+ ```
108
114
 
109
115
  > **Note**: With React Native 0.60+, iOS dependencies are automatically linked using autolinking. Manual pod installation is no longer required for most cases.
110
116
 
@@ -122,30 +128,91 @@ Note: Replace MyApp with your own project name.
122
128
  <Button title="Increment" onPress={() => dispatch(increment())} />;
123
129
  ```
124
130
 
131
+ ### 💾 Redux Persist (Auth Persistence)
132
+
133
+ Redux Persist is pre-configured in the template to persist the `auth` slice across app restarts. The user's data and `accessToken` survive kills and relaunches — no need to log in again.
134
+
135
+ > `redux-persist` and `@react-native-async-storage/async-storage` are already installed and configured.
136
+
137
+ **What's included out of the box:**
138
+
139
+ `src/redux/slices/authSlice.ts` stores `user` and `accessToken` with the following actions:
140
+
141
+ | Action | Description |
142
+ | ---------------- | ---------------------------------------------- |
143
+ | `setCredentials` | Sets both `user` and `accessToken` after login |
144
+ | `setUser` | Updates only the `user` object |
145
+ | `setAccessToken` | Updates only the `accessToken` |
146
+ | `clearAuth` | Clears all auth state on logout |
147
+
148
+ `src/redux/store.ts` configures `persistReducer` to persist only the `auth` slice via `AsyncStorage` and exports `persistor`.
149
+
150
+ `App.tsx` wraps the app with `PersistGate` so persisted state is fully rehydrated before the UI renders.
151
+
152
+ `src/screens/SplashScreen.tsx` reads `accessToken` from Redux on startup — if present, navigates to `HomeScreen`, otherwise to `LoginScreen`.
153
+
154
+ `src/screens/LoginScreen.tsx` is a demo login screen that dispatches `setCredentials` with dummy `user` and `accessToken` data to demonstrate the persistence flow.
155
+
156
+ **Usage example — login:**
157
+
158
+ ```tsx
159
+ import { useAppDispatch } from "../redux/store";
160
+ import { setCredentials } from "../redux/slices/authSlice";
161
+
162
+ const dispatch = useAppDispatch();
163
+
164
+ // After a successful login API call:
165
+ dispatch(setCredentials({ user: userData, accessToken: token }));
166
+ // State is automatically persisted to AsyncStorage
167
+ ```
168
+
169
+ **Usage example — logout:**
170
+
171
+ ```tsx
172
+ import { useAppDispatch } from "../redux/store";
173
+ import { clearAuth } from "../redux/slices/authSlice";
174
+
175
+ const dispatch = useAppDispatch();
176
+ dispatch(clearAuth()); // Clears Redux state and AsyncStorage
177
+ ```
178
+
179
+ **Usage example — read auth state:**
180
+
181
+ ```tsx
182
+ import { useAppSelector } from "../redux/store";
183
+
184
+ const { user, accessToken } = useAppSelector((state) => state.auth);
185
+ ```
186
+
187
+ **How it works end-to-end:**
188
+
189
+ - On login → dispatch `setCredentials` → persisted to `AsyncStorage`
190
+ - On app restart → `PersistGate` rehydrates `auth` → `SplashScreen` sees `accessToken` → navigates directly to `HomeScreen`
191
+ - On logout → dispatch `clearAuth` → persisted data cleared → `SplashScreen` routes to `LoginScreen`
192
+
125
193
  ### 🌙 Dark/Light Theme Support
126
194
 
127
195
  The template includes a complete theming system with automatic system preference detection:
128
196
 
129
197
  - **Theme files**: Located in `src/theme/`
130
198
  - `darkTheme.ts` - Dark theme colors
131
- - `lightTheme.ts` - Light theme colors
199
+ - `lightTheme.ts` - Light theme colors
132
200
  - `index.ts` - Theme exports and TypeScript types
133
201
 
134
202
  - **Theme Context**: `src/hooks/ThemeContext.tsx` provides theme management
135
203
 
136
204
  - **Usage in components**:
205
+
137
206
  ```tsx
138
- import { useTheme } from '../hooks/ThemeContext';
139
-
207
+ import { useTheme } from "../hooks/ThemeContext";
208
+
140
209
  const MyComponent = () => {
141
210
  const { theme, mode, toggleTheme } = useTheme();
142
-
211
+
143
212
  return (
144
213
  <View style={{ backgroundColor: theme.background }}>
145
- <Text style={{ color: theme.text }}>
146
- Current theme: {mode}
147
- </Text>
148
- <TouchableOpacity
214
+ <Text style={{ color: theme.text }}>Current theme: {mode}</Text>
215
+ <TouchableOpacity
149
216
  style={{ backgroundColor: theme.primary }}
150
217
  onPress={toggleTheme}
151
218
  >
@@ -172,9 +239,12 @@ The template includes a complete theming system with automatic system preference
172
239
  - API calls and React Query hooks are in `src/api/queries.ts`.
173
240
  - Example usage:
174
241
  ```ts
175
- import { useQuery } from 'react-query';
176
- import { fetchData } from '../api/queries';
177
- const { data, isLoading } = useQuery('data', fetchData);
242
+ import { useQuery } from "@tanstack/react-query";
243
+ import { fetchData } from "../api/queries";
244
+ const { data, isLoading } = useQuery({
245
+ queryKey: ["data"],
246
+ queryFn: fetchData,
247
+ });
178
248
  ```
179
249
 
180
250
  ### 🧰 Utility Functions
@@ -192,6 +262,8 @@ The template includes a complete theming system with automatic system preference
192
262
  - Keep shared components in a `components/` folder (add as needed)
193
263
  - Customize theme colors in `src/theme/darkTheme.ts` and `src/theme/lightTheme.ts`
194
264
  - Extend theme properties by updating the theme type in `src/theme/index.ts`
265
+ - To persist additional slices, create a separate `persistConfig` per slice and wrap with `persistReducer`
266
+ - To exclude sensitive fields from persistence, use the `blacklist` array in the persist config instead of `whitelist`
195
267
 
196
268
  ## 🎨 Theme Customization
197
269
 
@@ -200,19 +272,19 @@ To customize the theme colors, edit the theme files:
200
272
  ```ts
201
273
  // src/theme/lightTheme.ts
202
274
  export const lightTheme = {
203
- background: '#FFFFFF',
204
- text: '#000000',
205
- primary: '#4045EF',
206
- secondary: '#F4F4F4',
275
+ background: "#FFFFFF",
276
+ text: "#000000",
277
+ primary: "#4045EF",
278
+ secondary: "#F4F4F4",
207
279
  // Add your custom colors here
208
280
  };
209
281
 
210
- // src/theme/darkTheme.ts
282
+ // src/theme/darkTheme.ts
211
283
  export const darkTheme = {
212
- background: '#000000',
213
- text: '#FFFFFF',
214
- primary: '#4045EF',
215
- secondary: '#1A1A1A',
284
+ background: "#000000",
285
+ text: "#FFFFFF",
286
+ primary: "#4045EF",
287
+ secondary: "#1A1A1A",
216
288
  // Add your custom colors here
217
289
  };
218
290
  ```
@@ -227,4 +299,4 @@ Created with ❤️ by **[Umang Thakkar](https://github.com/Umang2809)**
227
299
 
228
300
  ## 📜 License
229
301
 
230
- MIT © [Umang Thakkar](https://github.com/Umang2809)
302
+ MIT © [Umang Thakkar](https://github.com/Umang2809)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umang-thakkar/base-template",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "The template for react native to setup redux and other neccesary boilerplate codes",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -0,0 +1,12 @@
1
+ node_modules/
2
+ .expo/
3
+ .expo-shared/
4
+ dist/
5
+ build/
6
+ android/
7
+ ios/
8
+ .bundle/
9
+ *.jsbundle
10
+ coverage/
11
+ .next/
12
+ out/
@@ -0,0 +1,130 @@
1
+ {
2
+ "root": true,
3
+ "extends": [
4
+ "@react-native",
5
+ "@react-native-community",
6
+ "plugin:@tanstack/eslint-plugin-query/recommended",
7
+ ],
8
+ "parser": "@typescript-eslint/parser",
9
+ "parserOptions": {
10
+ "ecmaVersion": 2021,
11
+ "sourceType": "module",
12
+ "ecmaFeatures": {
13
+ "jsx": true,
14
+ },
15
+ },
16
+ "plugins": [
17
+ "react",
18
+ "react-native",
19
+ "react-hooks",
20
+ "@typescript-eslint",
21
+ "@tanstack/query",
22
+ ],
23
+ "env": {
24
+ "browser": true,
25
+ "es2021": true,
26
+ "node": true,
27
+ "react-native/react-native": true,
28
+ },
29
+ "rules": {
30
+ // React best practices
31
+ "react/react-in-jsx-scope": "off",
32
+ "react/prop-types": "off",
33
+ "react/display-name": "warn",
34
+ "react-hooks/rules-of-hooks": "error",
35
+ "react-hooks/exhaustive-deps": "warn",
36
+
37
+ // TypeScript best practices
38
+ "@typescript-eslint/no-unused-vars": [
39
+ "warn",
40
+ {
41
+ "argsIgnorePattern": "^_",
42
+ "varsIgnorePattern": "^_",
43
+ },
44
+ ],
45
+ "@typescript-eslint/no-explicit-any": "warn",
46
+ "@typescript-eslint/explicit-function-return-types": "off",
47
+ "@typescript-eslint/no-non-null-assertion": "warn",
48
+
49
+ // React Native best practices
50
+ "react-native/no-unused-styles": "warn",
51
+ "react-native/split-platform-components": "warn",
52
+ "react-native/no-inline-styles": "warn",
53
+ "react-native/no-color-literals": "warn",
54
+
55
+ // General best practices
56
+ "no-console": [
57
+ "warn",
58
+ {
59
+ "allow": ["warn", "error", "info"],
60
+ },
61
+ ],
62
+ "no-debugger": "warn",
63
+ "no-var": "error",
64
+ "prefer-const": "error",
65
+ "eqeqeq": ["error", "always"],
66
+ "curly": ["error", "all"],
67
+ "brace-style": ["error", "1tbs"],
68
+ "space-before-function-paren": [
69
+ "error",
70
+ {
71
+ "anonymous": "always",
72
+ "named": "never",
73
+ "asyncArrow": "always",
74
+ },
75
+ ],
76
+ "semi": ["error", "always"],
77
+ "quotes": ["error", "single", { "avoidEscape": true }],
78
+ "indent": ["error", 2],
79
+
80
+ // Import organization
81
+ "sort-imports": "off",
82
+ "import/order": [
83
+ "warn",
84
+ {
85
+ "groups": [
86
+ "builtin",
87
+ "external",
88
+ "internal",
89
+ "parent",
90
+ "sibling",
91
+ "index",
92
+ ],
93
+ "pathGroups": [
94
+ {
95
+ "pattern": "react*",
96
+ "group": "external",
97
+ "position": "before",
98
+ },
99
+ ],
100
+ "alphabeticalOrder": true,
101
+ },
102
+ ],
103
+
104
+ // React Query best practices
105
+ "@tanstack/query/exhaustive-deps": "error",
106
+ "@tanstack/query/prefer-query-object-syntax": "warn",
107
+ },
108
+ "settings": {
109
+ "react": {
110
+ "version": "detect",
111
+ },
112
+ },
113
+ "overrides": [
114
+ {
115
+ "files": ["**/__tests__/**", "**/*.test.ts", "**/*.test.tsx"],
116
+ "env": {
117
+ "jest": true,
118
+ },
119
+ "rules": {
120
+ "@typescript-eslint/no-explicit-any": "off",
121
+ },
122
+ },
123
+ {
124
+ "files": ["**/*.d.ts"],
125
+ "rules": {
126
+ "@typescript-eslint/no-unused-vars": "off",
127
+ },
128
+ },
129
+ ],
130
+ }
package/template/App.tsx CHANGED
@@ -1,37 +1,38 @@
1
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
2
- import { StyleSheet, useColorScheme, View } from 'react-native';
3
- import {
4
- SafeAreaProvider,
5
- useSafeAreaInsets,
6
- } from 'react-native-safe-area-context';
7
- import { Provider } from 'react-redux';
8
- import store from './src/redux/store';
9
- import Main from './Main';
10
- import { ThemeProvider } from './src/hooks/ThemeContext';
11
- const queryClient = new QueryClient()
12
- function App() {
13
- const isDarkMode = useColorScheme() === 'dark';
14
-
15
- return (
16
- <QueryClientProvider client={queryClient}>
17
- <Provider store={store}>
18
- <SafeAreaProvider>
19
- <ThemeProvider>
20
- <Main />
21
- </ThemeProvider>
22
- </SafeAreaProvider>
23
- </Provider>
24
- </QueryClientProvider>
25
- );
26
- }
1
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
+ import { StyleSheet } from "react-native";
3
+ import { SafeAreaProvider } from "react-native-safe-area-context";
4
+ import { Provider } from "react-redux";
5
+ import store, { persistor } from "./src/redux/store";
6
+ import { PersistGate } from "redux-persist/integration/react";
7
+ import Main from "./Main";
8
+ import { ThemeProvider } from "./src/hooks/ThemeContext";
9
+ import { ErrorBoundary } from "./src/components/ErrorBoundary";
27
10
 
28
- function AppContent() {
29
- const safeAreaInsets = useSafeAreaInsets();
11
+ const queryClient = new QueryClient({
12
+ defaultOptions: {
13
+ queries: {
14
+ retry: 1,
15
+ staleTime: 1000 * 60 * 5, // 5 minutes
16
+ gcTime: 1000 * 60 * 10, // 10 minutes (formerly cacheTime)
17
+ },
18
+ },
19
+ });
30
20
 
21
+ function App() {
31
22
  return (
32
- <View style={styles.container}>
33
-
34
- </View>
23
+ <ErrorBoundary>
24
+ <QueryClientProvider client={queryClient}>
25
+ <Provider store={store}>
26
+ <PersistGate loading={null} persistor={persistor}>
27
+ <SafeAreaProvider>
28
+ <ThemeProvider>
29
+ <Main />
30
+ </ThemeProvider>
31
+ </SafeAreaProvider>
32
+ </PersistGate>
33
+ </Provider>
34
+ </QueryClientProvider>
35
+ </ErrorBoundary>
35
36
  );
36
37
  }
37
38
 
package/template/Main.tsx CHANGED
@@ -1,14 +1,14 @@
1
- import { NavigationContainer } from '@react-navigation/native';
2
- import React from 'react';
3
- import AppStack from './src/navigation/AppStack';
4
-
1
+ import { NavigationContainer } from "@react-navigation/native";
2
+ import React from "react";
3
+ import AppStack from "./src/navigation/AppStack";
4
+ import { navigationRef } from "./src/helper/navigation-service";
5
5
 
6
6
  const Main = () => {
7
- return (
8
- <NavigationContainer>
9
- <AppStack />
10
- </NavigationContainer>
11
- )
12
- }
7
+ return (
8
+ <NavigationContainer ref={navigationRef}>
9
+ <AppStack />
10
+ </NavigationContainer>
11
+ );
12
+ };
13
13
 
14
- export default Main
14
+ export default Main;
@@ -19,9 +19,9 @@ react {
19
19
 
20
20
  /* Variants */
21
21
  // The list of variants to that are debuggable. For those we're going to
22
- // skip the bundling of the JS bundle and the assets. By default is just 'debug'.
22
+ // skip the bundling of the JS bundle and the assets. Default is "debug", "debugOptimized".
23
23
  // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
24
- // debuggableVariants = ["liteDebug", "prodDebug"]
24
+ // debuggableVariants = ["liteDebug", "liteDebugOptimized", "prodDebug", "prodDebugOptimized"]
25
25
 
26
26
  /* Bundling */
27
27
  // A list containing the node command and its flags. Default is just 'node'.
@@ -5,6 +5,7 @@
5
5
  <application
6
6
  android:name=".MainApplication"
7
7
  android:label="@string/app_name"
8
+ android:usesCleartextTraffic="${usesCleartextTraffic}"
8
9
  android:icon="@mipmap/ic_launcher"
9
10
  android:roundIcon="@mipmap/ic_launcher_round"
10
11
  android:allowBackup="false"
@@ -5,31 +5,20 @@ import com.facebook.react.PackageList
5
5
  import com.facebook.react.ReactApplication
6
6
  import com.facebook.react.ReactHost
7
7
  import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
8
- import com.facebook.react.ReactNativeHost
9
- import com.facebook.react.ReactPackage
10
8
  import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
11
- import com.facebook.react.defaults.DefaultReactNativeHost
12
9
 
13
10
  class MainApplication : Application(), ReactApplication {
14
11
 
15
- override val reactNativeHost: ReactNativeHost =
16
- object : DefaultReactNativeHost(this) {
17
- override fun getPackages(): List<ReactPackage> =
18
- PackageList(this).packages.apply {
19
- // Packages that cannot be autolinked yet can be added manually here, for example:
20
- // add(MyReactNativePackage())
21
- }
22
-
23
- override fun getJSMainModuleName(): String = "index"
24
-
25
- override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
26
-
27
- override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
28
- override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
29
- }
30
-
31
- override val reactHost: ReactHost
32
- get() = getDefaultReactHost(applicationContext, reactNativeHost)
12
+ override val reactHost: ReactHost by lazy {
13
+ getDefaultReactHost(
14
+ context = applicationContext,
15
+ packageList =
16
+ PackageList(this).packages.apply {
17
+ // Packages that cannot be autolinked yet can be added manually here, for example:
18
+ // add(MyReactNativePackage())
19
+ },
20
+ )
21
+ }
33
22
 
34
23
  override fun onCreate() {
35
24
  super.onCreate()
@@ -1,6 +1,6 @@
1
1
  distributionBase=GRADLE_USER_HOME
2
2
  distributionPath=wrapper/dists
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
4
4
  networkTimeout=10000
5
5
  validateDistributionUrl=true
6
6
  zipStoreBase=GRADLE_USER_HOME
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  #
4
- # Copyright © 2015-2021 the original authors.
4
+ # Copyright © 2015 the original authors.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -2,6 +2,8 @@
2
2
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
3
  <plist version="1.0">
4
4
  <dict>
5
+ <key>CADisableMinimumFrameDurationOnPhone</key>
6
+ <true/>
5
7
  <key>CFBundleDevelopmentRegion</key>
6
8
  <string>en</string>
7
9
  <key>CFBundleDisplayName</key>
@@ -26,6 +28,7 @@
26
28
  <true/>
27
29
  <key>NSAppTransportSecurity</key>
28
30
  <dict>
31
+ <!-- Do not change NSAllowsArbitraryLoads to true, or you will risk app rejection! -->
29
32
  <key>NSAllowsArbitraryLoads</key>
30
33
  <false/>
31
34
  <key>NSAllowsLocalNetworking</key>
@@ -33,8 +36,6 @@
33
36
  </dict>
34
37
  <key>NSLocationWhenInUseUsageDescription</key>
35
38
  <string></string>
36
- <key>RCTNewArchEnabled</key>
37
- <false/>
38
39
  <key>UILaunchStoryboardName</key>
39
40
  <string>LaunchScreen</string>
40
41
  <key>UIRequiredDeviceCapabilities</key>
@@ -44,8 +45,13 @@
44
45
  <key>UISupportedInterfaceOrientations</key>
45
46
  <array>
46
47
  <string>UIInterfaceOrientationPortrait</string>
48
+ </array>
49
+ <key>UISupportedInterfaceOrientations~ipad</key>
50
+ <array>
47
51
  <string>UIInterfaceOrientationLandscapeLeft</string>
48
52
  <string>UIInterfaceOrientationLandscapeRight</string>
53
+ <string>UIInterfaceOrientationPortrait</string>
54
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
49
55
  </array>
50
56
  <key>UIViewControllerBasedStatusBarAppearance</key>
51
57
  <false/>