rn-toastify 1.0.4 → 1.0.6
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/docs/Toast.gif +0 -0
- package/package.json +1 -1
- package/src/Toast.js +55 -66
- package/src/components/EmojiToast.js +5 -4
- package/src/components/ErrorToast.js +7 -6
- package/src/components/SuccessToast.js +7 -6
- package/src/context/ToastContainer.js +6 -2
- package/src/animations/customeAnimations.js +0 -31
- package/src/animations/fadeInDown.js +0 -16
- package/src/animations/fadeOutUp.js +0 -16
package/docs/Toast.gif
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-toastify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A customizable and performant toast notification library for React Native, featuring smooth animations, swipe gestures, and flexible styling options.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
package/src/Toast.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import React, { useEffect,
|
|
2
|
-
import { PanResponder, StyleSheet
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
|
2
|
+
import { PanResponder, StyleSheet } from 'react-native';
|
|
3
|
+
import Animated, {
|
|
4
|
+
useSharedValue,
|
|
5
|
+
useAnimatedStyle,
|
|
6
|
+
withTiming,
|
|
7
|
+
withSpring,
|
|
8
|
+
runOnJS,
|
|
9
|
+
} from 'react-native-reanimated';
|
|
8
10
|
|
|
9
11
|
const Toast = ({ visible, duration, position, children, onHide, style }) => {
|
|
10
12
|
const opacity = useSharedValue(0);
|
|
11
13
|
const translateY = useSharedValue(position === 'top' ? -50 : 50);
|
|
12
14
|
const translateX = useSharedValue(0);
|
|
13
|
-
const scale = useSharedValue(0.9);
|
|
15
|
+
const scale = useSharedValue(0.9);
|
|
14
16
|
|
|
15
|
-
const positionStyle = useMemo(() =>
|
|
16
|
-
return position === 'top' ? styles.top : styles.bottom;
|
|
17
|
-
}, [position]);
|
|
17
|
+
const positionStyle = useMemo(() => (position === 'top' ? styles.top : styles.bottom), [position]);
|
|
18
18
|
|
|
19
19
|
useEffect(() => {
|
|
20
20
|
if (visible) {
|
|
@@ -24,66 +24,64 @@ const Toast = ({ visible, duration, position, children, onHide, style }) => {
|
|
|
24
24
|
|
|
25
25
|
if (duration !== Infinity) {
|
|
26
26
|
const hideTimeout = setTimeout(() => {
|
|
27
|
-
|
|
28
|
-
translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 300 });
|
|
29
|
-
runOnJS(onHide)();
|
|
27
|
+
hideToast();
|
|
30
28
|
}, duration);
|
|
31
29
|
|
|
32
30
|
return () => clearTimeout(hideTimeout);
|
|
33
31
|
}
|
|
34
32
|
} else {
|
|
35
|
-
|
|
36
|
-
translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 300 });
|
|
37
|
-
runOnJS(onHide)();
|
|
33
|
+
hideToast();
|
|
38
34
|
}
|
|
39
|
-
}, [visible, duration
|
|
35
|
+
}, [visible, duration]);
|
|
40
36
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{ scale: scale.value },
|
|
48
|
-
],
|
|
49
|
-
};
|
|
50
|
-
});
|
|
37
|
+
const hideToast = () => {
|
|
38
|
+
opacity.value = withTiming(0, { duration: 300, easing: Easing.ease });
|
|
39
|
+
translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 300, easing: Easing.ease });
|
|
40
|
+
scale.value = withTiming(0.9, { duration: 300, easing: Easing.ease });
|
|
41
|
+
runOnJS(onHide)();
|
|
42
|
+
};
|
|
51
43
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
onPanResponderRelease: (evt, gestureState) => {
|
|
62
|
-
if (Math.abs(gestureState.dx) > 100) { // If the swipe distance is more than 100 pixels, remove the toast
|
|
63
|
-
opacity.value = withTiming(0, { duration: 200 });
|
|
64
|
-
runOnJS(onHide)();
|
|
65
|
-
} else {
|
|
66
|
-
// If the swipe is less than the threshold, reset the position
|
|
67
|
-
translateX.value = withSpring(0);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
}), [translateX, opacity, onHide]);
|
|
44
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
45
|
+
opacity: opacity.value,
|
|
46
|
+
transform: [
|
|
47
|
+
{ translateY: translateY.value },
|
|
48
|
+
{ translateX: translateX.value },
|
|
49
|
+
{ scale: scale.value },
|
|
50
|
+
],
|
|
51
|
+
}));
|
|
71
52
|
|
|
53
|
+
const panResponder = useMemo(
|
|
54
|
+
() =>
|
|
55
|
+
PanResponder.create({
|
|
56
|
+
onMoveShouldSetPanResponder: (evt, gestureState) => {
|
|
57
|
+
return Math.abs(gestureState.dx) > 20; // Swipe detection threshold
|
|
58
|
+
},
|
|
59
|
+
onPanResponderMove: (evt, gestureState) => {
|
|
60
|
+
translateX.value = gestureState.dx; // Update translateX as the user swipes
|
|
61
|
+
},
|
|
62
|
+
onPanResponderRelease: (evt, gestureState) => {
|
|
63
|
+
if (Math.abs(gestureState.dx) > 100) { // If the swipe distance is more than 100 pixels, remove the toast
|
|
64
|
+
opacity.value = withTiming(0, { duration: 200 });
|
|
65
|
+
translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 200 });
|
|
66
|
+
scale.value = withTiming(0.9, { duration: 200 });
|
|
67
|
+
runOnJS(onHide)();
|
|
68
|
+
} else {
|
|
69
|
+
// If the swipe is less than the threshold, reset the position
|
|
70
|
+
translateX.value = withSpring(0);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
[]
|
|
75
|
+
);
|
|
72
76
|
|
|
73
77
|
if (!visible) return null;
|
|
74
78
|
|
|
75
79
|
return (
|
|
76
80
|
<Animated.View
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
animatedStyle,
|
|
80
|
-
positionStyle,
|
|
81
|
-
style,
|
|
82
|
-
]}
|
|
81
|
+
{...panResponder.panHandlers}
|
|
82
|
+
style={[styles.container, animatedStyle, positionStyle, style]}
|
|
83
83
|
>
|
|
84
|
-
|
|
85
|
-
{typeof children === 'string' ? <Text>{children}</Text> : children}
|
|
86
|
-
</Animated.View>
|
|
84
|
+
{children}
|
|
87
85
|
</Animated.View>
|
|
88
86
|
);
|
|
89
87
|
};
|
|
@@ -100,16 +98,7 @@ const styles = StyleSheet.create({
|
|
|
100
98
|
top: 0,
|
|
101
99
|
},
|
|
102
100
|
bottom: {
|
|
103
|
-
bottom:
|
|
104
|
-
},
|
|
105
|
-
toast: {
|
|
106
|
-
marginTop: hp(1),
|
|
107
|
-
borderRadius: wp(3),
|
|
108
|
-
shadowColor: '#000',
|
|
109
|
-
shadowOffset: { width: 0, height: 1 },
|
|
110
|
-
shadowOpacity: 0.5,
|
|
111
|
-
shadowRadius: 10,
|
|
112
|
-
elevation: 20,
|
|
101
|
+
bottom: 20,
|
|
113
102
|
},
|
|
114
103
|
});
|
|
115
104
|
|
|
@@ -14,13 +14,14 @@ const EmojiToast = ({ message, emoji }) => {
|
|
|
14
14
|
}
|
|
15
15
|
const styles = StyleSheet.create({
|
|
16
16
|
emojiToast: {
|
|
17
|
-
width: wp(
|
|
18
|
-
height: hp(
|
|
17
|
+
width: wp(87),
|
|
18
|
+
height: hp(6.8),
|
|
19
19
|
paddingHorizontal: wp(4),
|
|
20
20
|
borderRadius: wp(4),
|
|
21
|
-
backgroundColor: '
|
|
22
|
-
|
|
21
|
+
// backgroundColor: '#d2f7d2',
|
|
22
|
+
backgroundColor: '#F7F7FC',
|
|
23
23
|
alignItems: 'center',
|
|
24
|
+
flexDirection: 'row',
|
|
24
25
|
|
|
25
26
|
},
|
|
26
27
|
text: {
|
|
@@ -24,19 +24,20 @@ const ErrorToast = ({ message }) => {
|
|
|
24
24
|
|
|
25
25
|
const styles = StyleSheet.create({
|
|
26
26
|
container: {
|
|
27
|
-
width: wp(
|
|
28
|
-
height: hp(6),
|
|
27
|
+
width: wp(87),
|
|
28
|
+
height: hp(6.8),
|
|
29
29
|
paddingHorizontal: wp(4),
|
|
30
|
-
borderRadius: wp(
|
|
31
|
-
backgroundColor: '#f8c4c4',
|
|
30
|
+
borderRadius: wp(4),
|
|
31
|
+
// backgroundColor: '#f8c4c4',
|
|
32
|
+
backgroundColor: '#F7F7FC',
|
|
32
33
|
alignItems: 'center',
|
|
33
34
|
flexDirection: 'row'
|
|
34
|
-
|
|
35
35
|
},
|
|
36
36
|
text: {
|
|
37
37
|
fontSize: hp(2.3),
|
|
38
38
|
color: 'black',
|
|
39
|
-
|
|
39
|
+
fontWeight: '500',
|
|
40
|
+
paddingHorizontal: wp(3)
|
|
40
41
|
},
|
|
41
42
|
lottie: {
|
|
42
43
|
width: wp(8.5),
|
|
@@ -23,19 +23,20 @@ const SuccessToast = ({ message }) => {
|
|
|
23
23
|
|
|
24
24
|
const styles = StyleSheet.create({
|
|
25
25
|
container: {
|
|
26
|
-
width: wp(
|
|
27
|
-
height: hp(6),
|
|
26
|
+
width: wp(87),
|
|
27
|
+
height: hp(6.8),
|
|
28
28
|
paddingHorizontal: wp(4),
|
|
29
|
-
borderRadius: wp(
|
|
30
|
-
backgroundColor: '#d2f7d2',
|
|
29
|
+
borderRadius: wp(4),
|
|
30
|
+
// backgroundColor: '#d2f7d2',
|
|
31
|
+
backgroundColor: '#F7F7FC',
|
|
31
32
|
alignItems: 'center',
|
|
32
33
|
flexDirection: 'row',
|
|
33
|
-
|
|
34
34
|
},
|
|
35
35
|
text: {
|
|
36
36
|
fontSize: hp(2.3),
|
|
37
37
|
color: 'black',
|
|
38
|
-
|
|
38
|
+
fontWeight: '500',
|
|
39
|
+
paddingHorizontal: wp(3)
|
|
39
40
|
},
|
|
40
41
|
lottie: {
|
|
41
42
|
width: wp(8),
|
|
@@ -2,6 +2,10 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import { View, StyleSheet } from 'react-native';
|
|
3
3
|
import Toast from '../Toast';
|
|
4
4
|
import toastManagerInstance from './ToastManager';
|
|
5
|
+
import {
|
|
6
|
+
heightPercentageToDP as hp,
|
|
7
|
+
widthPercentageToDP as wp,
|
|
8
|
+
} from '../utils/Pixel/Index';
|
|
5
9
|
|
|
6
10
|
const ToastContainer = () => {
|
|
7
11
|
const [toasts, setToasts] = useState([]);
|
|
@@ -39,7 +43,7 @@ const ToastContainer = () => {
|
|
|
39
43
|
visible={true}
|
|
40
44
|
duration={toast.options.duration}
|
|
41
45
|
position="top"
|
|
42
|
-
style={[toast.options.style, { top:
|
|
46
|
+
style={[toast.options.style, { top: hp(0.1) + index * 60 }]} // Adjust spacing between top toasts
|
|
43
47
|
onHide={() => toastManagerInstance.remove(toast.id)}
|
|
44
48
|
>
|
|
45
49
|
{toast.content}
|
|
@@ -71,7 +75,7 @@ const ToastContainer = () => {
|
|
|
71
75
|
visible={true}
|
|
72
76
|
duration={toast.options.duration}
|
|
73
77
|
position="bottom"
|
|
74
|
-
style={[toast.options.style, { bottom:
|
|
78
|
+
style={[toast.options.style, { bottom: hp(2) + index * 60 }]} // Adjust spacing between bottom toasts
|
|
75
79
|
onHide={() => toastManagerInstance.remove(toast.id)}
|
|
76
80
|
>
|
|
77
81
|
{toast.content}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Animated } from 'react-native';
|
|
2
|
-
|
|
3
|
-
export const customEnterAnimation = (opacity, translateY) => {
|
|
4
|
-
return Animated.parallel([
|
|
5
|
-
Animated.timing(opacity, {
|
|
6
|
-
toValue: 1,
|
|
7
|
-
duration: 1000,
|
|
8
|
-
useNativeDriver: true,
|
|
9
|
-
}),
|
|
10
|
-
Animated.spring(translateY, {
|
|
11
|
-
toValue: 0,
|
|
12
|
-
friction: 5,
|
|
13
|
-
useNativeDriver: true,
|
|
14
|
-
}),
|
|
15
|
-
]);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const customExitAnimation = (opacity, translateY) => {
|
|
19
|
-
return Animated.parallel([
|
|
20
|
-
Animated.timing(opacity, {
|
|
21
|
-
toValue: 0,
|
|
22
|
-
duration: 1000,
|
|
23
|
-
useNativeDriver: true,
|
|
24
|
-
}),
|
|
25
|
-
Animated.timing(translateY, {
|
|
26
|
-
toValue: -50,
|
|
27
|
-
duration: 1000,
|
|
28
|
-
useNativeDriver: true,
|
|
29
|
-
}),
|
|
30
|
-
]);
|
|
31
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Animated } from 'react-native';
|
|
2
|
-
|
|
3
|
-
export const fadeInDown = (opacity, translateY) => {
|
|
4
|
-
return Animated.parallel([
|
|
5
|
-
Animated.timing(opacity, {
|
|
6
|
-
toValue: 1,
|
|
7
|
-
duration: 500,
|
|
8
|
-
useNativeDriver: true,
|
|
9
|
-
}),
|
|
10
|
-
Animated.timing(translateY, {
|
|
11
|
-
toValue: 0,
|
|
12
|
-
duration: 500,
|
|
13
|
-
useNativeDriver: true,
|
|
14
|
-
}),
|
|
15
|
-
]);
|
|
16
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Animated } from 'react-native';
|
|
2
|
-
|
|
3
|
-
export const fadeOutUp = (opacity, translateY) => {
|
|
4
|
-
return Animated.parallel([
|
|
5
|
-
Animated.timing(opacity, {
|
|
6
|
-
toValue: 0,
|
|
7
|
-
duration: 500,
|
|
8
|
-
useNativeDriver: true,
|
|
9
|
-
}),
|
|
10
|
-
Animated.timing(translateY, {
|
|
11
|
-
toValue: -50,
|
|
12
|
-
duration: 500,
|
|
13
|
-
useNativeDriver: true,
|
|
14
|
-
}),
|
|
15
|
-
]);
|
|
16
|
-
};
|