@modhamanish/rn-mm-template 1.0.1 → 1.0.2

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.
@@ -9,6 +9,7 @@ import {
9
9
  } from 'react';
10
10
  import { darkTheme, lightTheme, ThemeType } from '../theme/Colors';
11
11
  import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
12
+ import storageHelper from '../utils/storageHelper';
12
13
 
13
14
  export type ThemeContextType = {
14
15
  colors: ThemeType['colors'];
@@ -31,6 +32,11 @@ export const ThemeProvider: FC<ThemeProviderProps> = ({ children }) => {
31
32
  lightTheme.colors,
32
33
  );
33
34
 
35
+ useEffect(() => {
36
+ const theme = storageHelper.getItem(storageHelper.STORAGE_KEYS.THEME);
37
+ setCurrentTheme(theme === 'dark' ? 'dark' : 'light');
38
+ }, []);
39
+
34
40
  useEffect(() => {
35
41
  if (currentTheme === 'dark') {
36
42
  setColors(darkTheme.colors);
@@ -40,7 +46,15 @@ export const ThemeProvider: FC<ThemeProviderProps> = ({ children }) => {
40
46
  }, [currentTheme]);
41
47
 
42
48
  const toggleTheme = useCallback(() => {
43
- setCurrentTheme(prev => (prev === 'dark' ? 'light' : 'dark'));
49
+ setCurrentTheme(prev => {
50
+ if (prev === 'dark') {
51
+ storageHelper.saveItem(storageHelper.STORAGE_KEYS.THEME, 'light');
52
+ return 'light';
53
+ } else {
54
+ storageHelper.saveItem(storageHelper.STORAGE_KEYS.THEME, 'dark');
55
+ return 'dark';
56
+ }
57
+ });
44
58
  }, []);
45
59
 
46
60
  return (
@@ -5,6 +5,7 @@ export const storage = createMMKV();
5
5
  enum STORAGE_KEYS {
6
6
  USER = 'user',
7
7
  LANGUAGE = 'language',
8
+ THEME = 'theme',
8
9
  }
9
10
 
10
11
  const saveItem = (key: STORAGE_KEYS, value: string) => {
package/README.md CHANGED
@@ -7,7 +7,7 @@ Welcome to **MMTemplate**! This is a robust and modern React Native template bui
7
7
  To initialize a new project using this template, run the following command:
8
8
 
9
9
  ```bash
10
- npx @react-native-community/cli@latest init AwesomeProject --template https://github.com/modhamanish/mm-template
10
+ npx @react-native-community/cli@latest init AwesomeProject --template @modhamanish/rn-mm-template
11
11
  ```
12
12
 
13
13
  Replace `AwesomeProject` with your desired project name.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modhamanish/rn-mm-template",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A robust and modern React Native template built with TypeScript, designed to jumpstart your mobile application development.",
5
5
  "repository": "https://github.com/modhamanish/mm-template.git",
6
6
  "author": "Manish Modha",