@dropi/react-native-design-system 0.3.8 → 0.3.9

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.
@@ -18,8 +18,9 @@ const ToastProvider = ({
18
18
  const [currentToast, setCurrentToast] = (0, _react.useState)(null);
19
19
  const [queue, setQueue] = (0, _react.useState)([]);
20
20
  const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
21
- const slideAnim = (0, _react.useRef)(new _reactNative.Animated.Value(-100)).current;
21
+ const slideAnim = (0, _react.useRef)(new _reactNative.Animated.Value(-200)).current;
22
22
  const timeoutRef = (0, _react.useRef)(null);
23
+ const animationRef = (0, _react.useRef)(null);
23
24
  const toastIdCounter = (0, _react.useRef)(0);
24
25
 
25
26
  // Cleanup timers on unmount
@@ -28,13 +29,19 @@ const ToastProvider = ({
28
29
  if (timeoutRef.current) {
29
30
  clearTimeout(timeoutRef.current);
30
31
  }
32
+ if (animationRef.current) {
33
+ animationRef.current.stop();
34
+ }
31
35
  };
32
36
  }, []);
33
37
 
34
38
  // Animate in the toast
35
39
  const animateIn = (0, _react.useCallback)(() => {
40
+ if (isAnimating) return;
36
41
  setIsAnimating(true);
37
- _reactNative.Animated.sequence([_reactNative.Animated.timing(slideAnim, {
42
+ slideAnim.setValue(-200); // Reset to initial position
43
+
44
+ animationRef.current = _reactNative.Animated.sequence([_reactNative.Animated.timing(slideAnim, {
38
45
  toValue: _reactNative.Platform.OS === 'ios' ? 100 : 50 + _utils.statusBarHeight,
39
46
  duration: 300,
40
47
  useNativeDriver: true
@@ -42,34 +49,54 @@ const ToastProvider = ({
42
49
  toValue: _reactNative.Platform.OS === 'ios' ? 80 : 30 + _utils.statusBarHeight,
43
50
  duration: 120,
44
51
  useNativeDriver: true
45
- })]).start(() => {
46
- setIsAnimating(false);
52
+ })]);
53
+ animationRef.current.start(({
54
+ finished
55
+ }) => {
56
+ if (finished) {
57
+ setIsAnimating(false);
58
+ }
47
59
  });
48
- }, [slideAnim]);
60
+ }, [slideAnim, isAnimating]);
49
61
 
50
62
  // Animate out the toast
51
63
  const animateOut = (0, _react.useCallback)(callback => {
52
- if (isAnimating) return;
64
+ if (isAnimating && animationRef.current) {
65
+ animationRef.current.stop();
66
+ }
53
67
  setIsAnimating(true);
54
- _reactNative.Animated.timing(slideAnim, {
55
- toValue: -100,
68
+ animationRef.current = _reactNative.Animated.timing(slideAnim, {
69
+ toValue: -200,
56
70
  duration: 400,
57
71
  useNativeDriver: true
58
- }).start(() => {
59
- setIsAnimating(false);
60
- setCurrentToast(null);
61
- callback?.();
72
+ });
73
+ animationRef.current.start(({
74
+ finished
75
+ }) => {
76
+ if (finished) {
77
+ setIsAnimating(false);
78
+ // Defer state updates to avoid useInsertionEffect error
79
+ requestAnimationFrame(() => {
80
+ setCurrentToast(null);
81
+ if (callback) {
82
+ callback();
83
+ }
84
+ });
85
+ }
62
86
  });
63
87
  }, [slideAnim, isAnimating]);
64
88
 
65
89
  // Process the next toast in the queue
66
90
  const processQueue = (0, _react.useCallback)(() => {
67
- setQueue(prevQueue => {
68
- if (prevQueue.length === 0) return prevQueue;
69
- const [nextToast, ...remainingQueue] = prevQueue;
70
- setCurrentToast(nextToast);
71
- return remainingQueue;
72
- });
91
+ // Use setTimeout to defer state update
92
+ setTimeout(() => {
93
+ setQueue(prevQueue => {
94
+ if (prevQueue.length === 0) return prevQueue;
95
+ const [nextToast, ...remainingQueue] = prevQueue;
96
+ setCurrentToast(nextToast);
97
+ return remainingQueue;
98
+ });
99
+ }, 0);
73
100
  }, []);
74
101
 
75
102
  // Handle auto-dismiss
@@ -79,6 +106,7 @@ const ToastProvider = ({
79
106
  // Clear any existing timeout
80
107
  if (timeoutRef.current) {
81
108
  clearTimeout(timeoutRef.current);
109
+ timeoutRef.current = null;
82
110
  }
83
111
 
84
112
  // Animate in
@@ -95,6 +123,7 @@ const ToastProvider = ({
95
123
  return () => {
96
124
  if (timeoutRef.current) {
97
125
  clearTimeout(timeoutRef.current);
126
+ timeoutRef.current = null;
98
127
  }
99
128
  };
100
129
  }, [currentToast, animateIn, animateOut, processQueue]);
@@ -103,6 +132,7 @@ const ToastProvider = ({
103
132
  const handleClose = (0, _react.useCallback)(() => {
104
133
  if (timeoutRef.current) {
105
134
  clearTimeout(timeoutRef.current);
135
+ timeoutRef.current = null;
106
136
  }
107
137
  animateOut(() => {
108
138
  processQueue();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dropi/react-native-design-system",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "description": "A React Native package built from scratch",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",