@tcbs/react-native-mazic-ui 0.1.5 → 0.1.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
@@ -1,5 +1,12 @@
1
1
  # @tcbs/react-native-mazic-ui
2
2
 
3
+ ![npm](https://img.shields.io/npm/v/@tcbs/react-native-mazic-ui)
4
+ ![downloads](https://img.shields.io/npm/dw/@tcbs/react-native-mazic-ui)
5
+ ![license](https://img.shields.io/npm/l/@tcbs/react-native-mazic-ui)
6
+ [
7
+ ![Docs](https://img.shields.io/badge/docs-UI%20Docs-blue?logo=readthedocs&logoColor=white&style=flat-square)
8
+ ](https://tcbscli.subraatakumar.com/ui-home/)
9
+
3
10
  A customizable React Native UI component library.
4
11
 
5
12
  ## Installation
@@ -12,6 +19,36 @@ npm install @tcbs/react-native-mazic-ui @tcbs/react-native-exception-handler
12
19
  yarn add @tcbs/react-native-mazic-ui @tcbs/react-native-exception-handler
13
20
  ```
14
21
 
22
+
23
+ ## Error Handling: AppErrorBoundary
24
+
25
+ `AppErrorBoundary` is a React error boundary component for catching and displaying errors in your app. It supports custom fallback UIs for both development and production modes.
26
+
27
+ ### Quick Usage
28
+
29
+ ```tsx
30
+ import { AppErrorBoundary } from '@tcbs/react-native-mazic-ui';
31
+
32
+ <AppErrorBoundary>
33
+ <YourApp/>
34
+ </AppErrorBoundary>
35
+ ```
36
+
37
+ You can also provide custom fallback UIs for dev and prod:
38
+
39
+ ```tsx
40
+ <AppErrorBoundary
41
+ fallbackDev={<Text>DEV: Something went wrong.</Text>}
42
+ fallbackProd={<Text>PROD: Please try again later.</Text>}
43
+ >
44
+ <YourApp/>
45
+ </AppErrorBoundary>
46
+ ```
47
+
48
+ For full details and advanced usage, see [docs](https://tcbscli.subraatakumar.com/ui-home/apperrorboundary).
49
+
50
+ ---
51
+
15
52
  ## Theme Setup Example
16
53
 
17
54
  ```tsx
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "react-native-vector-icons"
14
14
  ],
15
15
  "author": "TechCraft By Subrata <subraatakumar@gmail.com>",
16
- "version": "0.1.5",
16
+ "version": "0.1.7",
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
@@ -33,11 +33,12 @@
33
33
  "peerDependencies": {
34
34
  "react": ">=17.0.0",
35
35
  "react-native": ">=0.68.0",
36
- "@tcbs/react-native-exception-handler": "1.0.0"
36
+ "@tcbs/react-native-exception-handler": "1.0.1"
37
37
  },
38
38
  "dependencies": {
39
39
  "react-native-vector-icons": ">=10.2.0",
40
- "react-error-boundary": ">=5.0.0"
40
+ "react-native-mmkv": "^3.2.0",
41
+ "zustand": "^5.0.3"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@types/react": "^17.0.0",
@@ -12,6 +12,8 @@ setupGlobalExceptionHandlers();
12
12
 
13
13
  export interface AppErrorBoundaryProps {
14
14
  children?: React.ReactNode;
15
+ fallbackDev?: React.ReactNode;
16
+ fallbackProd?: React.ReactNode;
15
17
  }
16
18
 
17
19
  export interface AppErrorBoundaryState {
@@ -35,6 +37,15 @@ export class AppErrorBoundary extends React.Component<AppErrorBoundaryProps, App
35
37
  errorInfo: null,
36
38
  };
37
39
 
40
+ handleReset = () => {
41
+ this.setState({
42
+ hasError: false,
43
+ error: null,
44
+ reactError: null,
45
+ errorInfo: null,
46
+ });
47
+ };
48
+
38
49
  static getDerivedStateFromError(error: any) {
39
50
  return { hasError: true, error };
40
51
  }
@@ -57,11 +68,19 @@ export class AppErrorBoundary extends React.Component<AppErrorBoundaryProps, App
57
68
 
58
69
  renderDevError() {
59
70
  const { error, reactError, errorInfo } = this.state;
71
+ const { fallbackDev } = this.props;
72
+
73
+ if (fallbackDev) {
74
+ // Custom fallback for DEV
75
+ return typeof fallbackDev === 'function'
76
+ ? fallbackDev({ error, errorInfo, reset: this.handleReset })
77
+ : fallbackDev;
78
+ }
60
79
 
61
80
  if (!error) return null;
62
81
 
63
82
  return (
64
- <SafeAreaView style={{ flex: 1 }}>
83
+ <SafeAreaView style={{ flex: 1, marginBottom: 40 }}>
65
84
  <ScrollView style={styles.container}>
66
85
  <Text style={styles.title}>🚨 Application Error (DEV)</Text>
67
86
 
@@ -85,18 +104,39 @@ export class AppErrorBoundary extends React.Component<AppErrorBoundaryProps, App
85
104
  {errorInfo?.componentStack}
86
105
  </Text>
87
106
  </Section>
107
+ {/* Try Again Button */}
108
+ <View style={styles.buttonContainer}>
109
+ <Text style={styles.tryAgainButton} onPress={this.handleReset}>
110
+ 🔄 Try Again
111
+ </Text>
112
+ </View>
88
113
  </ScrollView>
89
114
  </SafeAreaView>
90
115
  );
91
116
  }
92
117
 
93
118
  renderProdError() {
119
+ const { fallbackProd } = this.props;
120
+ const { error, errorInfo } = this.state;
121
+
122
+ if (fallbackProd) {
123
+ // Custom fallback for PROD
124
+ return typeof fallbackProd === 'function'
125
+ ? fallbackProd({ error, errorInfo, reset: this.handleReset })
126
+ : fallbackProd;
127
+ }
128
+
94
129
  return (
95
130
  <View style={styles.prodContainer}>
96
131
  <Text style={styles.prodTitle}>Something went wrong</Text>
97
132
  <Text style={styles.prodSubtitle}>
98
133
  Please restart the application.
99
134
  </Text>
135
+ <View style={styles.buttonContainer}>
136
+ <Text style={styles.tryAgainButton} onPress={this.handleReset}>
137
+ 🔄 Try Again
138
+ </Text>
139
+ </View>
100
140
  </View>
101
141
  );
102
142
  }
@@ -129,7 +169,7 @@ const styles = StyleSheet.create({
129
169
  container: {
130
170
  flex: 1,
131
171
  backgroundColor: '#0f172a',
132
- padding: 16,
172
+ // padding: 36,
133
173
  },
134
174
  title: {
135
175
  fontSize: 18,
@@ -176,4 +216,18 @@ const styles = StyleSheet.create({
176
216
  color: '#666',
177
217
  textAlign: 'center',
178
218
  },
219
+ buttonContainer: {
220
+ marginTop: 24,
221
+ alignItems: 'center',
222
+ },
223
+ tryAgainButton: {
224
+ backgroundColor: '#38bdf8',
225
+ color: '#fff',
226
+ paddingVertical: 10,
227
+ paddingHorizontal: 24,
228
+ borderRadius: 8,
229
+ fontWeight: '700',
230
+ fontSize: 16,
231
+ overflow: 'hidden',
232
+ },
179
233
  });
@@ -0,0 +1,13 @@
1
+ import {create} from 'zustand';
2
+
3
+ export interface GlobalErrorState {
4
+ fatalError: null | { error: any };
5
+ setFatalError: (error: any) => void;
6
+ clearFatalError: () => void;
7
+ }
8
+
9
+ export const useGlobalErrorStore = create<GlobalErrorState>((set) => ({
10
+ fatalError: null,
11
+ setFatalError: (error) => set({ fatalError: { error } }),
12
+ clearFatalError: () => set({ fatalError: null }),
13
+ }));