@umituz/react-native-design-system 4.23.48 → 4.23.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-design-system",
3
- "version": "4.23.48",
3
+ "version": "4.23.50",
4
4
  "description": "Universal design system for React Native apps - Consolidated package with atoms, molecules, organisms, theme, typography, responsive, safe area, exception, infinite scroll, UUID, image, timezone, offline, onboarding, and loading utilities",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -1,31 +1,16 @@
1
1
  import { useMemo } from 'react';
2
- import { useDesignSystemTheme } from '../infrastructure/globalThemeStore';
2
+ import { useTheme } from '../infrastructure/stores/themeStore';
3
3
  import { createDesignTokens } from '../core/TokenFactory';
4
4
  import { useResponsive } from '../../responsive/useResponsive';
5
5
  import { type DesignTokens } from '../types/ThemeTypes';
6
6
 
7
7
  /**
8
8
  * Hook to access current design tokens (colors, spacing, typography, etc.)
9
- *
10
- * Responsive by default - Scales based on device type
11
- * ✅ Theme-aware - Automatically updates on light/dark mode changes
12
- * ✅ Dynamic - Supports custom color overrides
13
- *
14
- * @returns {DesignTokens} The current responsive design tokens
15
- *
16
- * @example
17
- * ```tsx
18
- * const tokens = useAppDesignTokens();
19
- * return (
20
- * <View style={{
21
- * padding: tokens.spacing.md,
22
- * backgroundColor: tokens.colors.backgroundPrimary
23
- * }} />
24
- * );
25
- * ```
9
+ *
10
+ * Uses useTheme directly - single source of truth for theme state.
26
11
  */
27
12
  export const useAppDesignTokens = (): DesignTokens => {
28
- const { themeMode, customColors } = useDesignSystemTheme();
13
+ const { themeMode, customColors } = useTheme();
29
14
  const { spacingMultiplier, getFontSize } = useResponsive();
30
15
 
31
16
  return useMemo(
@@ -44,12 +44,12 @@ export const DesignSystemProvider: React.FC<DesignSystemProviderProps> = ({
44
44
  const [fontsLoaded, fontError] = fonts ? useFonts(fonts) : [true, null];
45
45
 
46
46
  const initialize = useThemeStore((state) => state.initialize);
47
- const setThemeMode = useThemeStore((state) => state.setThemeMode);
48
- const setCustomColors = useDesignSystemTheme((state) => state.setCustomColors);
47
+ const setCustomColors = useThemeStore((state) => state.setCustomColors);
48
+ const setDefaultColors = useThemeStore((state) => state.setDefaultColors);
49
+ const setGlobalCustomColors = useDesignSystemTheme((state) => state.setCustomColors);
49
50
  const setGlobalThemeMode = useDesignSystemTheme((state) => state.setThemeMode);
50
51
 
51
52
  // Set icon config SYNCHRONOUSLY before first render
52
- // This ensures icons are available immediately
53
53
  if (iconRenderer && iconNames) {
54
54
  const store = useIconStore.getState();
55
55
  if (!store.isConfigured) {
@@ -58,22 +58,24 @@ export const DesignSystemProvider: React.FC<DesignSystemProviderProps> = ({
58
58
  }
59
59
 
60
60
  useEffect(() => {
61
+ // Register app's default colors for reset feature
61
62
  if (customColors) {
63
+ setDefaultColors(customColors);
62
64
  setCustomColors(customColors);
65
+ setGlobalCustomColors(customColors);
63
66
  }
64
67
 
65
68
  setGlobalThemeMode(initialThemeMode);
66
69
 
67
70
  initialize()
68
- .then(async () => {
69
- await setThemeMode(initialThemeMode);
71
+ .then(() => {
70
72
  setIsInitialized(true);
71
73
  })
72
74
  .catch((error) => {
73
75
  setIsInitialized(true);
74
76
  onError?.(error);
75
77
  });
76
- }, [initialize, customColors, initialThemeMode, setCustomColors, setGlobalThemeMode, setThemeMode, onError]);
78
+ }, []);
77
79
 
78
80
  useEffect(() => {
79
81
  if (isInitialized && fontsLoaded) {
@@ -16,6 +16,7 @@ interface ThemeState {
16
16
  theme: Theme;
17
17
  themeMode: ThemeMode;
18
18
  customColors?: CustomThemeColors;
19
+ defaultColors?: CustomThemeColors;
19
20
  isDark: boolean;
20
21
  isInitialized: boolean;
21
22
  }
@@ -23,6 +24,8 @@ interface ThemeState {
23
24
  interface ThemeActions {
24
25
  setThemeMode: (mode: ThemeMode) => Promise<void>;
25
26
  setCustomColors: (colors?: CustomThemeColors) => Promise<void>;
27
+ setDefaultColors: (colors: CustomThemeColors) => void;
28
+ resetToDefaults: () => Promise<void>;
26
29
  toggleTheme: () => Promise<void>;
27
30
  initialize: () => Promise<void>;
28
31
  }
@@ -36,13 +39,14 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
36
39
  theme: lightTheme,
37
40
  themeMode: 'light',
38
41
  customColors: undefined,
42
+ defaultColors: undefined,
39
43
  isDark: false,
40
44
  isInitialized: false,
41
45
  },
42
46
  persist: false,
43
47
  actions: (set, get) => ({
44
48
  initialize: async () => {
45
- const { isInitialized } = get();
49
+ const { isInitialized, customColors: currentColors } = get();
46
50
  if (isInitialized || themeInitInProgress) return;
47
51
 
48
52
  themeInitInProgress = true;
@@ -55,19 +59,20 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
55
59
 
56
60
  const mode = savedMode || 'light';
57
61
  const theme = mode === 'light' ? lightTheme : darkTheme;
62
+ // Only use savedColors if they exist, otherwise keep current (prop-based) colors
63
+ const colors = savedColors !== undefined ? savedColors : currentColors;
58
64
 
59
65
  set({
60
66
  themeMode: mode,
61
67
  theme,
62
- customColors: savedColors,
68
+ customColors: colors,
63
69
  isDark: mode === 'dark',
64
70
  isInitialized: true,
65
71
  });
66
72
 
67
- // Sync with design system global theme
68
73
  const dsTheme = useDesignSystemTheme.getState();
69
74
  dsTheme.setThemeMode(mode);
70
- dsTheme.setCustomColors(savedColors);
75
+ dsTheme.setCustomColors(colors);
71
76
  } catch {
72
77
  set({ isInitialized: true });
73
78
  useDesignSystemTheme.getState().setThemeMode('light');
@@ -98,6 +103,20 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
98
103
  useDesignSystemTheme.getState().setCustomColors(colors);
99
104
  },
100
105
 
106
+ setDefaultColors: (colors: CustomThemeColors) => {
107
+ set({ defaultColors: colors });
108
+ },
109
+
110
+ resetToDefaults: async () => {
111
+ const { defaultColors } = get();
112
+ set({ themeMode: 'light', theme: lightTheme, isDark: false, customColors: defaultColors });
113
+ await ThemeStorage.clearThemeMode();
114
+ await ThemeStorage.clearCustomColors();
115
+ const dsTheme = useDesignSystemTheme.getState();
116
+ dsTheme.setThemeMode('light');
117
+ dsTheme.setCustomColors(defaultColors);
118
+ },
119
+
101
120
  toggleTheme: async () => {
102
121
  const { themeMode, setThemeMode } = get();
103
122
  await setThemeMode(themeMode === 'light' ? 'dark' : 'light');