@momo-kits/foundation 0.157.1-beta.1 → 0.157.1-beta.2-viewboundary-test

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.
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { ViewStyle, StyleProp } from 'react-native';
3
+
4
+ export interface ViewBoundaryProps {
5
+ children: React.ReactNode;
6
+ /** Custom fallback UI when error occurs. Defaults to hiding the crashed view. */
7
+ fallback?: React.ReactNode;
8
+ /** Style for the fallback container */
9
+ fallbackStyle?: StyleProp<ViewStyle>;
10
+ /** Called when an error is caught. Use for logging/reporting. */
11
+ onError?: (error: Error, errorInfo: React.ErrorInfo) => void;
12
+ }
13
+
14
+ interface ViewBoundaryState {
15
+ hasError: boolean;
16
+ error: Error | null;
17
+ }
18
+
19
+ class ViewBoundary extends React.Component<ViewBoundaryProps, ViewBoundaryState> {
20
+ constructor(props: ViewBoundaryProps) {
21
+ super(props);
22
+ this.state = { hasError: false, error: null };
23
+ }
24
+
25
+ static getDerivedStateFromError(error: Error): ViewBoundaryState {
26
+ return { hasError: true, error };
27
+ }
28
+
29
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
30
+ this.props.onError?.(error, errorInfo);
31
+ }
32
+
33
+ render() {
34
+ if (this.state.hasError) {
35
+ if (this.props.fallback !== undefined) {
36
+ return this.props.fallback;
37
+ }
38
+ return null;
39
+ }
40
+ return this.props.children;
41
+ }
42
+ }
43
+
44
+ export default ViewBoundary;
45
+ export { ViewBoundary };
package/index.ts CHANGED
@@ -47,4 +47,5 @@ export * from './Badge';
47
47
  export * from './Badge/types';
48
48
  export * from './FoundationList';
49
49
  export * from './FoundationList/types';
50
+ export * from './ViewBoundary';
50
51
  export { TouchableOpacity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.157.1-beta.1",
3
+ "version": "0.157.1-beta.2-viewboundary-test",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},