rn-toastify 1.0.3 → 1.0.5
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 +10 -13
- package/src/components/ErrorToast.js +6 -6
- package/src/components/LoadingToast.js +1 -0
- package/src/components/SuccessToast.js +5 -6
- package/src/context/ToastContainer.js +75 -18
- 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.5",
|
|
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,14 +1,14 @@
|
|
|
1
|
-
import React, { useEffect, useMemo } from 'react';
|
|
1
|
+
import React, { useEffect, useState, useMemo } from 'react';
|
|
2
2
|
import { PanResponder, StyleSheet, Text } from 'react-native';
|
|
3
3
|
import {
|
|
4
4
|
heightPercentageToDP as hp,
|
|
5
5
|
widthPercentageToDP as wp,
|
|
6
6
|
} from './utils/Pixel/Index';
|
|
7
|
-
import Animated, { useSharedValue, useAnimatedStyle, withTiming, withSpring, runOnJS } from 'react-native-reanimated';
|
|
7
|
+
import Animated, { useSharedValue, useAnimatedStyle, withTiming, withSpring, Easing, runOnJS } from 'react-native-reanimated';
|
|
8
8
|
|
|
9
9
|
const Toast = ({ visible, duration, position, children, onHide, style }) => {
|
|
10
10
|
const opacity = useSharedValue(0);
|
|
11
|
-
const translateY = useSharedValue(-50);
|
|
11
|
+
const translateY = useSharedValue(position === 'top' ? -50 : 50);
|
|
12
12
|
const translateX = useSharedValue(0);
|
|
13
13
|
const scale = useSharedValue(0.9); // Start with a slightly smaller scale
|
|
14
14
|
|
|
@@ -25,7 +25,7 @@ const Toast = ({ visible, duration, position, children, onHide, style }) => {
|
|
|
25
25
|
if (duration !== Infinity) {
|
|
26
26
|
const hideTimeout = setTimeout(() => {
|
|
27
27
|
opacity.value = withTiming(0, { duration: 300 });
|
|
28
|
-
translateY.value = withTiming(-50, { duration: 300 });
|
|
28
|
+
translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 300 });
|
|
29
29
|
runOnJS(onHide)();
|
|
30
30
|
}, duration);
|
|
31
31
|
|
|
@@ -33,7 +33,7 @@ const Toast = ({ visible, duration, position, children, onHide, style }) => {
|
|
|
33
33
|
}
|
|
34
34
|
} else {
|
|
35
35
|
opacity.value = withTiming(0, { duration: 300 });
|
|
36
|
-
translateY.value = withTiming(-50, { duration: 300 });
|
|
36
|
+
translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 300 });
|
|
37
37
|
runOnJS(onHide)();
|
|
38
38
|
}
|
|
39
39
|
}, [visible, duration, onHide]);
|
|
@@ -74,7 +74,6 @@ const Toast = ({ visible, duration, position, children, onHide, style }) => {
|
|
|
74
74
|
|
|
75
75
|
return (
|
|
76
76
|
<Animated.View
|
|
77
|
-
// {...panResponder.panHandlers}
|
|
78
77
|
style={[
|
|
79
78
|
styles.container,
|
|
80
79
|
animatedStyle,
|
|
@@ -105,14 +104,12 @@ const styles = StyleSheet.create({
|
|
|
105
104
|
},
|
|
106
105
|
toast: {
|
|
107
106
|
marginTop: hp(1),
|
|
108
|
-
|
|
109
|
-
backgroundColor: 'white',
|
|
110
|
-
borderRadius: wp(4),
|
|
107
|
+
borderRadius: wp(3),
|
|
111
108
|
shadowColor: '#000',
|
|
112
|
-
shadowOffset: { width: 0, height: 1 },
|
|
113
|
-
shadowOpacity: 0.5,
|
|
114
|
-
shadowRadius: 10,
|
|
115
|
-
elevation: 20,
|
|
109
|
+
shadowOffset: { width: 0, height: 1 },
|
|
110
|
+
shadowOpacity: 0.5,
|
|
111
|
+
shadowRadius: 10,
|
|
112
|
+
elevation: 20,
|
|
116
113
|
},
|
|
117
114
|
});
|
|
118
115
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// src/components/ToastHelpers/ErrorToast.js
|
|
1
2
|
import LottieView from 'lottie-react-native';
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { View, Text, StyleSheet } from 'react-native';
|
|
@@ -23,18 +24,17 @@ const ErrorToast = ({ message }) => {
|
|
|
23
24
|
|
|
24
25
|
const styles = StyleSheet.create({
|
|
25
26
|
container: {
|
|
26
|
-
width: wp(
|
|
27
|
-
height: hp(
|
|
27
|
+
width: wp(74),
|
|
28
|
+
height: hp(6),
|
|
28
29
|
paddingHorizontal: wp(4),
|
|
29
|
-
borderRadius: wp(
|
|
30
|
-
|
|
31
|
-
backgroundColor: 'white',
|
|
30
|
+
borderRadius: wp(3),
|
|
31
|
+
backgroundColor: '#f8c4c4',
|
|
32
32
|
alignItems: 'center',
|
|
33
33
|
flexDirection: 'row'
|
|
34
34
|
|
|
35
35
|
},
|
|
36
36
|
text: {
|
|
37
|
-
fontSize: hp(2.
|
|
37
|
+
fontSize: hp(2.3),
|
|
38
38
|
color: 'black',
|
|
39
39
|
paddingHorizontal: wp(1.5)
|
|
40
40
|
},
|
|
@@ -23,18 +23,17 @@ const SuccessToast = ({ message }) => {
|
|
|
23
23
|
|
|
24
24
|
const styles = StyleSheet.create({
|
|
25
25
|
container: {
|
|
26
|
-
width: wp(
|
|
27
|
-
height: hp(
|
|
26
|
+
width: wp(74),
|
|
27
|
+
height: hp(6),
|
|
28
28
|
paddingHorizontal: wp(4),
|
|
29
|
-
borderRadius: wp(
|
|
30
|
-
backgroundColor: '#d2f7d2',
|
|
31
|
-
// backgroundColor: 'white', // Success color (green)
|
|
29
|
+
borderRadius: wp(3),
|
|
30
|
+
backgroundColor: '#d2f7d2',
|
|
32
31
|
alignItems: 'center',
|
|
33
32
|
flexDirection: 'row',
|
|
34
33
|
|
|
35
34
|
},
|
|
36
35
|
text: {
|
|
37
|
-
fontSize: hp(2.
|
|
36
|
+
fontSize: hp(2.3),
|
|
38
37
|
color: 'black',
|
|
39
38
|
paddingHorizontal: wp(1.5)
|
|
40
39
|
},
|
|
@@ -3,7 +3,6 @@ import { View, StyleSheet } from 'react-native';
|
|
|
3
3
|
import Toast from '../Toast';
|
|
4
4
|
import toastManagerInstance from './ToastManager';
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
const ToastContainer = () => {
|
|
8
7
|
const [toasts, setToasts] = useState([]);
|
|
9
8
|
|
|
@@ -25,35 +24,93 @@ const ToastContainer = () => {
|
|
|
25
24
|
};
|
|
26
25
|
}, []);
|
|
27
26
|
|
|
27
|
+
// Separate toasts by position
|
|
28
|
+
const topToasts = toasts.filter(toast => toast.options.position === 'top');
|
|
29
|
+
const centerToasts = toasts.filter(toast => toast.options.position === 'center');
|
|
30
|
+
const bottomToasts = toasts.filter(toast => toast.options.position === 'bottom');
|
|
31
|
+
|
|
28
32
|
return (
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
<>
|
|
34
|
+
{/* Top positioned toasts */}
|
|
35
|
+
<View style={styles.topContainer}>
|
|
36
|
+
{topToasts.map((toast, index) => (
|
|
37
|
+
<Toast
|
|
38
|
+
key={toast.id}
|
|
39
|
+
visible={true}
|
|
40
|
+
duration={toast.options.duration}
|
|
41
|
+
position="top"
|
|
42
|
+
style={[toast.options.style, { top: 20 + index * 60 }]} // Adjust spacing between top toasts
|
|
43
|
+
onHide={() => toastManagerInstance.remove(toast.id)}
|
|
44
|
+
>
|
|
45
|
+
{toast.content}
|
|
46
|
+
</Toast>
|
|
47
|
+
))}
|
|
48
|
+
</View>
|
|
49
|
+
|
|
50
|
+
{/* Center positioned toasts */}
|
|
51
|
+
<View style={styles.centerContainer}>
|
|
52
|
+
{centerToasts.map((toast, index) => (
|
|
53
|
+
<Toast
|
|
54
|
+
key={toast.id}
|
|
55
|
+
visible={true}
|
|
56
|
+
duration={toast.options.duration}
|
|
57
|
+
position="center"
|
|
58
|
+
style={[toast.options.style, { marginTop: index * 60 }]} // Adjust spacing between center toasts
|
|
59
|
+
onHide={() => toastManagerInstance.remove(toast.id)}
|
|
60
|
+
>
|
|
61
|
+
{toast.content}
|
|
62
|
+
</Toast>
|
|
63
|
+
))}
|
|
64
|
+
</View>
|
|
65
|
+
|
|
66
|
+
{/* Bottom positioned toasts */}
|
|
67
|
+
<View style={styles.bottomContainer}>
|
|
68
|
+
{bottomToasts.map((toast, index) => (
|
|
69
|
+
<Toast
|
|
70
|
+
key={toast.id}
|
|
71
|
+
visible={true}
|
|
72
|
+
duration={toast.options.duration}
|
|
73
|
+
position="bottom"
|
|
74
|
+
style={[toast.options.style, { bottom: 20 + index * 60 }]} // Adjust spacing between bottom toasts
|
|
75
|
+
onHide={() => toastManagerInstance.remove(toast.id)}
|
|
76
|
+
>
|
|
77
|
+
{toast.content}
|
|
78
|
+
</Toast>
|
|
79
|
+
))}
|
|
80
|
+
</View>
|
|
81
|
+
</>
|
|
43
82
|
);
|
|
44
83
|
};
|
|
45
84
|
|
|
46
85
|
const styles = StyleSheet.create({
|
|
47
|
-
|
|
86
|
+
topContainer: {
|
|
48
87
|
position: 'absolute',
|
|
49
88
|
top: 0,
|
|
50
89
|
left: 0,
|
|
51
90
|
right: 0,
|
|
52
|
-
|
|
53
|
-
|
|
91
|
+
zIndex: 9999,
|
|
92
|
+
pointerEvents: 'box-none',
|
|
93
|
+
alignItems: 'center',
|
|
94
|
+
},
|
|
95
|
+
centerContainer: {
|
|
96
|
+
position: 'absolute',
|
|
97
|
+
top: '50%',
|
|
98
|
+
bottom: '50%',
|
|
99
|
+
left: 0,
|
|
100
|
+
right: 0,
|
|
101
|
+
zIndex: 9999,
|
|
102
|
+
pointerEvents: 'box-none',
|
|
54
103
|
alignItems: 'center',
|
|
104
|
+
transform: [{ translateY: -30 }] // Center the first toast vertically
|
|
105
|
+
},
|
|
106
|
+
bottomContainer: {
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
bottom: 0,
|
|
109
|
+
left: 0,
|
|
110
|
+
right: 0,
|
|
55
111
|
zIndex: 9999,
|
|
56
112
|
pointerEvents: 'box-none',
|
|
113
|
+
alignItems: 'center',
|
|
57
114
|
},
|
|
58
115
|
});
|
|
59
116
|
|
|
@@ -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
|
-
};
|