@umituz/react-native-design-system 4.23.110 → 4.23.112
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.
|
|
3
|
+
"version": "4.23.112",
|
|
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",
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ErrorBoundary Component
|
|
3
|
+
* React 19 compatible error boundary for catching rendering errors
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { Component, ReactNode } from "react";
|
|
7
|
+
import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
|
|
8
|
+
|
|
9
|
+
export interface ErrorBoundaryProps {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
fallback?: ReactNode;
|
|
12
|
+
onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ErrorBoundaryState {
|
|
16
|
+
hasError: boolean;
|
|
17
|
+
error: Error | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ErrorBoundary extends Component<
|
|
21
|
+
ErrorBoundaryProps,
|
|
22
|
+
ErrorBoundaryState
|
|
23
|
+
> {
|
|
24
|
+
constructor(props: ErrorBoundaryProps) {
|
|
25
|
+
super(props);
|
|
26
|
+
this.state = { hasError: false, error: null };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState {
|
|
30
|
+
return { hasError: true, error };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
|
|
34
|
+
this.props.onError?.(error, errorInfo);
|
|
35
|
+
|
|
36
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
37
|
+
console.error("[ErrorBoundary] Error caught:", error);
|
|
38
|
+
console.error("[ErrorBoundary] Error info:", errorInfo);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
handleReset = () => {
|
|
43
|
+
this.setState({ hasError: false, error: null });
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
render() {
|
|
47
|
+
if (this.state.hasError) {
|
|
48
|
+
if (this.props.fallback) {
|
|
49
|
+
return this.props.fallback;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<View style={styles.container}>
|
|
54
|
+
<Text style={styles.title}>Something went wrong</Text>
|
|
55
|
+
<Text style={styles.message}>
|
|
56
|
+
{this.state.error?.message || "An unexpected error occurred"}
|
|
57
|
+
</Text>
|
|
58
|
+
<TouchableOpacity style={styles.button} onPress={this.handleReset}>
|
|
59
|
+
<Text style={styles.buttonText}>Try Again</Text>
|
|
60
|
+
</TouchableOpacity>
|
|
61
|
+
</View>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return this.props.children;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const styles = StyleSheet.create({
|
|
70
|
+
container: {
|
|
71
|
+
flex: 1,
|
|
72
|
+
justifyContent: "center",
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
padding: 20,
|
|
75
|
+
backgroundColor: "#FFFFFF",
|
|
76
|
+
},
|
|
77
|
+
title: {
|
|
78
|
+
fontSize: 24,
|
|
79
|
+
fontWeight: "bold",
|
|
80
|
+
marginBottom: 12,
|
|
81
|
+
color: "#000000",
|
|
82
|
+
},
|
|
83
|
+
message: {
|
|
84
|
+
fontSize: 16,
|
|
85
|
+
textAlign: "center",
|
|
86
|
+
marginBottom: 24,
|
|
87
|
+
color: "#666666",
|
|
88
|
+
paddingHorizontal: 20,
|
|
89
|
+
},
|
|
90
|
+
button: {
|
|
91
|
+
backgroundColor: "#007AFF",
|
|
92
|
+
paddingHorizontal: 24,
|
|
93
|
+
paddingVertical: 12,
|
|
94
|
+
borderRadius: 8,
|
|
95
|
+
},
|
|
96
|
+
buttonText: {
|
|
97
|
+
color: "#FFFFFF",
|
|
98
|
+
fontSize: 16,
|
|
99
|
+
fontWeight: "600",
|
|
100
|
+
},
|
|
101
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -58,9 +58,9 @@ export * from "./organisms";
|
|
|
58
58
|
export * from "./safe-area";
|
|
59
59
|
|
|
60
60
|
// =============================================================================
|
|
61
|
-
// EXCEPTION EXPORTS
|
|
61
|
+
// EXCEPTION EXPORTS
|
|
62
62
|
// =============================================================================
|
|
63
|
-
|
|
63
|
+
export * from "./exception";
|
|
64
64
|
|
|
65
65
|
// =============================================================================
|
|
66
66
|
// INFINITE SCROLL EXPORTS
|
|
@@ -49,6 +49,7 @@ export const DesignSystemProvider: React.FC<DesignSystemProviderProps> = ({
|
|
|
49
49
|
const initialize = useTheme((state) => state.initialize);
|
|
50
50
|
const setCustomColors = useTheme((state) => state.setCustomColors);
|
|
51
51
|
const setDefaultColors = useTheme((state) => state.setDefaultColors);
|
|
52
|
+
const setDefaultThemeMode = useTheme((state) => state.setDefaultThemeMode);
|
|
52
53
|
const setGlobalCustomColors = useDesignSystemTheme((state) => state.setCustomColors);
|
|
53
54
|
const setGlobalThemeMode = useDesignSystemTheme((state) => state.setThemeMode);
|
|
54
55
|
|
|
@@ -68,6 +69,8 @@ export const DesignSystemProvider: React.FC<DesignSystemProviderProps> = ({
|
|
|
68
69
|
setGlobalCustomColors(customColors);
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// Set default theme mode BEFORE initialize
|
|
73
|
+
setDefaultThemeMode(initialThemeMode);
|
|
71
74
|
setGlobalThemeMode(initialThemeMode);
|
|
72
75
|
|
|
73
76
|
initialize()
|
|
@@ -17,6 +17,7 @@ interface ThemeState {
|
|
|
17
17
|
themeMode: ThemeMode;
|
|
18
18
|
customColors?: CustomThemeColors;
|
|
19
19
|
defaultColors?: CustomThemeColors;
|
|
20
|
+
defaultThemeMode: ThemeMode;
|
|
20
21
|
isDark: boolean;
|
|
21
22
|
isInitialized: boolean;
|
|
22
23
|
}
|
|
@@ -25,6 +26,7 @@ interface ThemeActions {
|
|
|
25
26
|
setThemeMode: (mode: ThemeMode) => Promise<void>;
|
|
26
27
|
setCustomColors: (colors?: CustomThemeColors) => Promise<void>;
|
|
27
28
|
setDefaultColors: (colors: CustomThemeColors) => void;
|
|
29
|
+
setDefaultThemeMode: (mode: ThemeMode) => void;
|
|
28
30
|
resetToDefaults: () => Promise<void>;
|
|
29
31
|
toggleTheme: () => Promise<void>;
|
|
30
32
|
initialize: () => Promise<void>;
|
|
@@ -36,17 +38,18 @@ let themeInitInProgress = false;
|
|
|
36
38
|
export const useTheme = createStore<ThemeState, ThemeActions>({
|
|
37
39
|
name: 'theme-store',
|
|
38
40
|
initialState: {
|
|
39
|
-
theme:
|
|
40
|
-
themeMode: '
|
|
41
|
+
theme: darkTheme,
|
|
42
|
+
themeMode: 'dark',
|
|
41
43
|
customColors: undefined,
|
|
42
44
|
defaultColors: undefined,
|
|
43
|
-
|
|
45
|
+
defaultThemeMode: 'dark',
|
|
46
|
+
isDark: true,
|
|
44
47
|
isInitialized: false,
|
|
45
48
|
},
|
|
46
49
|
persist: false,
|
|
47
50
|
actions: (set, get) => ({
|
|
48
51
|
initialize: async () => {
|
|
49
|
-
const { isInitialized, customColors: currentColors } = get();
|
|
52
|
+
const { isInitialized, customColors: currentColors, defaultThemeMode } = get();
|
|
50
53
|
if (isInitialized || themeInitInProgress) return;
|
|
51
54
|
|
|
52
55
|
themeInitInProgress = true;
|
|
@@ -57,7 +60,7 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
|
|
|
57
60
|
ThemeStorage.getCustomColors(),
|
|
58
61
|
]);
|
|
59
62
|
|
|
60
|
-
const mode = savedMode ||
|
|
63
|
+
const mode = savedMode || defaultThemeMode;
|
|
61
64
|
const theme = mode === 'light' ? lightTheme : darkTheme;
|
|
62
65
|
// Only use savedColors if they exist, otherwise keep current (prop-based) colors
|
|
63
66
|
const colors = savedColors !== undefined ? savedColors : currentColors;
|
|
@@ -75,7 +78,7 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
|
|
|
75
78
|
dsTheme.setCustomColors(colors);
|
|
76
79
|
} catch {
|
|
77
80
|
set({ isInitialized: true });
|
|
78
|
-
useDesignSystemTheme.getState().setThemeMode(
|
|
81
|
+
useDesignSystemTheme.getState().setThemeMode(defaultThemeMode);
|
|
79
82
|
} finally {
|
|
80
83
|
themeInitInProgress = false;
|
|
81
84
|
}
|
|
@@ -107,13 +110,18 @@ export const useTheme = createStore<ThemeState, ThemeActions>({
|
|
|
107
110
|
set({ defaultColors: colors });
|
|
108
111
|
},
|
|
109
112
|
|
|
113
|
+
setDefaultThemeMode: (mode: ThemeMode) => {
|
|
114
|
+
set({ defaultThemeMode: mode });
|
|
115
|
+
},
|
|
116
|
+
|
|
110
117
|
resetToDefaults: async () => {
|
|
111
|
-
const { defaultColors } = get();
|
|
112
|
-
|
|
118
|
+
const { defaultColors, defaultThemeMode } = get();
|
|
119
|
+
const theme = defaultThemeMode === 'light' ? lightTheme : darkTheme;
|
|
120
|
+
set({ themeMode: defaultThemeMode, theme, isDark: defaultThemeMode === 'dark', customColors: defaultColors });
|
|
113
121
|
await ThemeStorage.clearThemeMode();
|
|
114
122
|
await ThemeStorage.clearCustomColors();
|
|
115
123
|
const dsTheme = useDesignSystemTheme.getState();
|
|
116
|
-
dsTheme.setThemeMode(
|
|
124
|
+
dsTheme.setThemeMode(defaultThemeMode);
|
|
117
125
|
dsTheme.setCustomColors(defaultColors);
|
|
118
126
|
},
|
|
119
127
|
|