@umang-thakkar/base-template 1.0.5 → 1.0.7

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
@@ -5,6 +5,7 @@ A React Native boilerplate to kickstart your mobile app development faster, with
5
5
  - 🔁 Redux Toolkit for scalable state management
6
6
  - 📍 React Navigation for robust navigation
7
7
  - 🔗 React Query for powerful API data fetching and caching
8
+ - 🌙 Dark/Light theme support with system preference detection
8
9
  - 🗂️ Scalable folder structure
9
10
  - 🧰 Common utility functions
10
11
  - 📦 Pre-installed useful dependencies
@@ -15,6 +16,7 @@ A React Native boilerplate to kickstart your mobile app development faster, with
15
16
  - ✅ Redux Toolkit with example slices and hooks
16
17
  - ✅ React Navigation with Stack Navigator setup
17
18
  - ✅ React Query for API management (see `src/api/queries.ts`)
19
+ - ✅ Dark/Light theme support with automatic system detection
18
20
  - ✅ Organized folder structure for features, helpers, navigation, etc.
19
21
  - ✅ Useful helpers: debouncers, formatters, navigation service
20
22
  - ✅ TypeScript support
@@ -53,6 +55,7 @@ template/
53
55
  │ │ ├── typography.ts
54
56
  │ │ └── utility-functions.ts
55
57
  │ ├── hooks/ # Custom hooks
58
+ │ │ └── ThemeContext.tsx # Theme context and provider
56
59
  │ ├── navigation/ # Navigation setup
57
60
  │ │ ├── AppStack.tsx
58
61
  │ │ ├── AppStackParams.ts
@@ -65,6 +68,10 @@ template/
65
68
  │ ├── screens/ # App screens
66
69
  │ │ ├── HomeScreen.tsx
67
70
  │ │ └── SplashScreen.tsx
71
+ │ ├── theme/ # Theme configuration
72
+ │ │ ├── darkTheme.ts # Dark theme colors
73
+ │ │ ├── lightTheme.ts # Light theme colors
74
+ │ │ └── index.ts # Theme exports and types
68
75
  ├── vendor/ # Vendor files
69
76
  │ └── bundle/
70
77
  ├── package.json # Project dependencies
@@ -115,6 +122,46 @@ Note: Replace MyApp with your own project name.
115
122
  <Button title="Increment" onPress={() => dispatch(increment())} />;
116
123
  ```
117
124
 
125
+ ### 🌙 Dark/Light Theme Support
126
+
127
+ The template includes a complete theming system with automatic system preference detection:
128
+
129
+ - **Theme files**: Located in `src/theme/`
130
+ - `darkTheme.ts` - Dark theme colors
131
+ - `lightTheme.ts` - Light theme colors
132
+ - `index.ts` - Theme exports and TypeScript types
133
+
134
+ - **Theme Context**: `src/hooks/ThemeContext.tsx` provides theme management
135
+
136
+ - **Usage in components**:
137
+ ```tsx
138
+ import { useTheme } from '../hooks/ThemeContext';
139
+
140
+ const MyComponent = () => {
141
+ const { theme, mode, toggleTheme } = useTheme();
142
+
143
+ return (
144
+ <View style={{ backgroundColor: theme.background }}>
145
+ <Text style={{ color: theme.text }}>
146
+ Current theme: {mode}
147
+ </Text>
148
+ <TouchableOpacity
149
+ style={{ backgroundColor: theme.primary }}
150
+ onPress={toggleTheme}
151
+ >
152
+ <Text style={{ color: theme.text }}>Toggle Theme</Text>
153
+ </TouchableOpacity>
154
+ </View>
155
+ );
156
+ };
157
+ ```
158
+
159
+ - **Features**:
160
+ - Automatic detection of system color scheme preference
161
+ - Manual theme toggle functionality
162
+ - Listens for system theme changes
163
+ - TypeScript support for theme properties
164
+
118
165
  ### 🌐 Navigation
119
166
 
120
167
  - Navigation setup in `src/navigation/`.
@@ -143,6 +190,32 @@ Note: Replace MyApp with your own project name.
143
190
  - Add new API services under `src/api/`
144
191
  - Organize screens under `src/screens/`
145
192
  - Keep shared components in a `components/` folder (add as needed)
193
+ - Customize theme colors in `src/theme/darkTheme.ts` and `src/theme/lightTheme.ts`
194
+ - Extend theme properties by updating the theme type in `src/theme/index.ts`
195
+
196
+ ## 🎨 Theme Customization
197
+
198
+ To customize the theme colors, edit the theme files:
199
+
200
+ ```ts
201
+ // src/theme/lightTheme.ts
202
+ export const lightTheme = {
203
+ background: '#FFFFFF',
204
+ text: '#000000',
205
+ primary: '#4045EF',
206
+ secondary: '#F4F4F4',
207
+ // Add your custom colors here
208
+ };
209
+
210
+ // src/theme/darkTheme.ts
211
+ export const darkTheme = {
212
+ background: '#000000',
213
+ text: '#FFFFFF',
214
+ primary: '#4045EF',
215
+ secondary: '#1A1A1A',
216
+ // Add your custom colors here
217
+ };
218
+ ```
146
219
 
147
220
  ## 🤝 Contributing
148
221
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umang-thakkar/base-template",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "The template for react native to setup redux and other neccesary boilerplate codes",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -23,5 +23,18 @@
23
23
  "repository": {
24
24
  "type": "git",
25
25
  "url": "git+https://github.com/Umang2809/react-native-template.git"
26
- }
26
+ },
27
+ "keywords": [
28
+ "react-native",
29
+ "react-native-template",
30
+ "react-native-boilerplate",
31
+ "redux-toolkit",
32
+ "react-navigation",
33
+ "react-query",
34
+ "typescript",
35
+ "mobile-app",
36
+ "dark-mode",
37
+ "light-theme",
38
+ "rn-template"
39
+ ]
27
40
  }
package/template/App.tsx CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  import { Provider } from 'react-redux';
8
8
  import store from './src/redux/store';
9
9
  import Main from './Main';
10
+ import { ThemeProvider } from './src/hooks/ThemeContext';
10
11
  const queryClient = new QueryClient()
11
12
  function App() {
12
13
  const isDarkMode = useColorScheme() === 'dark';
@@ -15,7 +16,9 @@ function App() {
15
16
  <QueryClientProvider client={queryClient}>
16
17
  <Provider store={store}>
17
18
  <SafeAreaProvider>
18
- <Main />
19
+ <ThemeProvider>
20
+ <Main />
21
+ </ThemeProvider>
19
22
  </SafeAreaProvider>
20
23
  </Provider>
21
24
  </QueryClientProvider>
@@ -21,7 +21,7 @@
21
21
  "react": "19.1.0",
22
22
  "react-native": "0.81.0",
23
23
  "react-native-gesture-handler": "^2.28.0",
24
- "react-native-reanimated": "^4.0.2",
24
+ "react-native-reanimated": "^4.1.2",
25
25
  "react-native-safe-area-context": "^5.5.2",
26
26
  "react-native-screens": "^4.15.0",
27
27
  "react-native-worklets": "^0.4.1",
@@ -0,0 +1,43 @@
1
+ import React, { createContext, useContext, useEffect, useState } from 'react';
2
+ import { Appearance } from 'react-native';
3
+ import { themes, ThemeType } from '../theme';
4
+
5
+ type ThemeMode = 'light' | 'dark';
6
+
7
+ interface ThemeContextProps {
8
+ theme: ThemeType;
9
+ mode: ThemeMode;
10
+ toggleTheme: () => void;
11
+ }
12
+
13
+ const ThemeContext = createContext<ThemeContextProps | undefined>(undefined);
14
+
15
+ export const ThemeProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
16
+ const systemColorScheme = Appearance.getColorScheme() as ThemeMode;
17
+ const [mode, setMode] = useState<ThemeMode>(systemColorScheme || 'light');
18
+
19
+ const toggleTheme = () => setMode(prev => (prev === 'light' ? 'dark' : 'light'));
20
+
21
+ useEffect(() => {
22
+ const listener = Appearance.addChangeListener(({ colorScheme }) => {
23
+ if (colorScheme) {
24
+ setMode(colorScheme as ThemeMode);
25
+ }
26
+ });
27
+ return () => listener.remove();
28
+ }, []);
29
+
30
+ return (
31
+ <ThemeContext.Provider value={{ theme: themes[mode], mode, toggleTheme }}>
32
+ {children}
33
+ </ThemeContext.Provider>
34
+ );
35
+ };
36
+
37
+ export const useTheme = () => {
38
+ const context = useContext(ThemeContext);
39
+ if (!context) {
40
+ throw new Error('useTheme must be used within ThemeProvider');
41
+ }
42
+ return context;
43
+ };
@@ -1,14 +1,22 @@
1
1
  import * as React from 'react';
2
- import { Text, View, StyleSheet } from 'react-native';
2
+ import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
3
3
  import { SafeAreaView } from 'react-native-safe-area-context';
4
+ import { useTheme } from '../hooks/ThemeContext';
4
5
 
5
6
  interface Props { }
6
7
 
7
8
  const HomeScreen = (props: Props) => {
9
+ const { theme, toggleTheme, mode } = useTheme();
8
10
  return (
9
- <SafeAreaView>
10
- <View style={styles.container}>
11
- <Text>HomeScreen</Text>
11
+ <SafeAreaView style={{ flex: 1, backgroundColor: theme.background }}>
12
+ <View style={[styles.container, { backgroundColor: theme.background }]}>
13
+ <Text style={{ color: theme.text }}>Current theme: {mode}</Text>
14
+ <TouchableOpacity
15
+ style={[styles.button, { backgroundColor: theme.primary }]}
16
+ onPress={toggleTheme}
17
+ >
18
+ <Text style={{ color: theme.text }}>Toggle Theme</Text>
19
+ </TouchableOpacity>
12
20
  </View>
13
21
  </SafeAreaView>
14
22
  );
@@ -17,5 +25,14 @@ const HomeScreen = (props: Props) => {
17
25
  export default HomeScreen;
18
26
 
19
27
  const styles = StyleSheet.create({
20
- container: {}
28
+ container: {
29
+ flex: 1,
30
+ justifyContent: 'center',
31
+ alignItems: 'center',
32
+ },
33
+ button: {
34
+ marginTop: 20,
35
+ padding: 12,
36
+ borderRadius: 8,
37
+ },
21
38
  });
@@ -1,9 +1,24 @@
1
1
  import * as React from 'react';
2
2
  import { Text, View, StyleSheet } from 'react-native';
3
+ import { NativeStackNavigationProp } from '@react-navigation/native-stack';
4
+ import { RouteProp } from '@react-navigation/native';
5
+ import { AppStackParams } from '../navigation/AppStackParams';
6
+ import { useEffect } from 'react';
7
+ type Props = {
8
+ navigation: NativeStackNavigationProp<
9
+ AppStackParams,
10
+ 'SplashScreen',
11
+ 'SplashScreen'
12
+ >;
13
+ route: RouteProp<AppStackParams, 'SplashScreen'>;
14
+ };
3
15
 
4
- interface Props { }
5
-
6
- const SplashScreen = (props: Props) => {
16
+ const SplashScreen = ({ navigation }: Props) => {
17
+ useEffect(() => {
18
+ setTimeout(() => {
19
+ navigation.reset({ index: 0, routes: [{ name: 'HomeScreen' }] })
20
+ }, 1500);
21
+ }, [])
7
22
  return (
8
23
  <View style={styles.container}>
9
24
  <Text>SplashScreen</Text>
@@ -0,0 +1,6 @@
1
+ export const darkTheme = {
2
+ background: '#000000',
3
+ text: '#FFFFFF',
4
+ primary: '#4045EF',
5
+ secondary: '#1A1A1A',
6
+ };
@@ -0,0 +1,9 @@
1
+ import { lightTheme } from './lightTheme';
2
+ import { darkTheme } from './darkTheme';
3
+
4
+ export type ThemeType = typeof lightTheme;
5
+
6
+ export const themes = {
7
+ light: lightTheme,
8
+ dark: darkTheme,
9
+ };
@@ -0,0 +1,6 @@
1
+ export const lightTheme = {
2
+ background: '#FFFFFF',
3
+ text: '#000000',
4
+ primary: '#4045EF',
5
+ secondary: '#F4F4F4',
6
+ };
@@ -1948,13 +1948,6 @@
1948
1948
  resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.46.tgz#381daaca1360ff8a7c8dff63f32e69745b9fb1e1"
1949
1949
  integrity sha512-ynRvcq6wvqexJ9brDMS4BnBLzmr0e14d6ZJTEShTBWKymQiHwlAyGu0ZPEFI2Fh1U53F7tN9ufClWM5KvqkKOw==
1950
1950
 
1951
- "@types/hoist-non-react-statics@*":
1952
- version "3.3.7"
1953
- resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.7.tgz#306e3a3a73828522efa1341159da4846e7573a6c"
1954
- integrity sha512-PQTyIulDkIDro8P+IHbKCsw7U2xxBYflVzW/FgWdCAePD9xGSidgA76/GeJ6lBKoblyhf9pBY763gbrN+1dI8g==
1955
- dependencies:
1956
- hoist-non-react-statics "^3.3.0"
1957
-
1958
1951
  "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
1959
1952
  version "2.0.6"
1960
1953
  resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7"
@@ -1994,13 +1987,6 @@
1994
1987
  dependencies:
1995
1988
  undici-types "~7.10.0"
1996
1989
 
1997
- "@types/react-native@^0.70":
1998
- version "0.70.19"
1999
- resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.70.19.tgz#b4e651dcf7f49c69ff3a4c3072584cad93155582"
2000
- integrity sha512-c6WbyCgWTBgKKMESj/8b4w+zWcZSsCforson7UdXtXMecG3MxCinYi6ihhrHVPyUrVzORsvEzK8zg32z4pK6Sg==
2001
- dependencies:
2002
- "@types/react" "*"
2003
-
2004
1990
  "@types/react-test-renderer@^19.1.0":
2005
1991
  version "19.1.0"
2006
1992
  resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-19.1.0.tgz#1d0af8f2e1b5931e245b8b5b234d1502b854dc10"
@@ -2025,24 +2011,6 @@
2025
2011
  resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.3.tgz#6209321eb2c1712a7e7466422b8cb1fc0d9dd5d8"
2026
2012
  integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==
2027
2013
 
2028
- "@types/styled-components-react-native@^5.2.5":
2029
- version "5.2.5"
2030
- resolved "https://registry.yarnpkg.com/@types/styled-components-react-native/-/styled-components-react-native-5.2.5.tgz#224ff6b7a49b73d2c2563c5317a3e61da3f1fb87"
2031
- integrity sha512-hDYioy4gAusO9NJI0n1e0Dwne4zofRVjou8i+FdNNz4vOG/iEBS99Rl87ybytjx/WD3NXqZQJ5g98AA+ZW7JKA==
2032
- dependencies:
2033
- "@types/react" "*"
2034
- "@types/react-native" "^0.70"
2035
- "@types/styled-components" "*"
2036
-
2037
- "@types/styled-components@*":
2038
- version "5.1.34"
2039
- resolved "https://registry.yarnpkg.com/@types/styled-components/-/styled-components-5.1.34.tgz#4107df8ef8a7eaba4fa6b05f78f93fba4daf0300"
2040
- integrity sha512-mmiVvwpYklFIv9E8qfxuPyIt/OuyIrn6gMOAMOFUO3WJfSrSE+sGUoa4PiZj77Ut7bKZpaa6o1fBKS/4TOEvnA==
2041
- dependencies:
2042
- "@types/hoist-non-react-statics" "*"
2043
- "@types/react" "*"
2044
- csstype "^3.0.2"
2045
-
2046
2014
  "@types/use-sync-external-store@^0.0.6":
2047
2015
  version "0.0.6"
2048
2016
  resolved "https://registry.yarnpkg.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.6.tgz#60be8d21baab8c305132eb9cb912ed497852aadc"