rn-toastify 1.0.5 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-toastify",
3
- "version": "1.0.5",
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, useState, useMemo } from 'react';
2
- import { PanResponder, StyleSheet, Text } from 'react-native';
3
- import {
4
- heightPercentageToDP as hp,
5
- widthPercentageToDP as wp,
6
- } from './utils/Pixel/Index';
7
- import Animated, { useSharedValue, useAnimatedStyle, withTiming, withSpring, Easing, runOnJS } from 'react-native-reanimated';
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); // Start with a slightly smaller scale
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
- opacity.value = withTiming(0, { duration: 300 });
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
- opacity.value = withTiming(0, { duration: 300 });
36
- translateY.value = withTiming(position === 'top' ? -50 : 50, { duration: 300 });
37
- runOnJS(onHide)();
33
+ hideToast();
38
34
  }
39
- }, [visible, duration, onHide]);
35
+ }, [visible, duration]);
40
36
 
41
- const animatedStyle = useAnimatedStyle(() => {
42
- return {
43
- opacity: opacity.value,
44
- transform: [
45
- { translateY: translateY.value },
46
- { translateX: translateX.value },
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
- // Set up PanResponder for swipe gestures
53
- const panResponder = useMemo(() =>
54
- PanResponder.create({
55
- onMoveShouldSetPanResponder: (evt, gestureState) => {
56
- return Math.abs(gestureState.dx) > 20; // Swipe detection threshold
57
- },
58
- onPanResponderMove: (evt, gestureState) => {
59
- translateX.value = gestureState.dx; // Update translateX as the user swipes
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
- style={[
78
- styles.container,
79
- animatedStyle,
80
- positionStyle,
81
- style,
82
- ]}
81
+ {...panResponder.panHandlers}
82
+ style={[styles.container, animatedStyle, positionStyle, style]}
83
83
  >
84
- <Animated.View style={[styles.toast, { opacity }]}>
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: 50,
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(72),
18
- height: hp(5.5),
17
+ width: wp(87),
18
+ height: hp(6.8),
19
19
  paddingHorizontal: wp(4),
20
20
  borderRadius: wp(4),
21
- backgroundColor: 'white',
22
- flexDirection: 'row',
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(74),
28
- height: hp(6),
27
+ width: wp(87),
28
+ height: hp(6.8),
29
29
  paddingHorizontal: wp(4),
30
- borderRadius: wp(3),
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
- paddingHorizontal: wp(1.5)
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(74),
27
- height: hp(6),
26
+ width: wp(87),
27
+ height: hp(6.8),
28
28
  paddingHorizontal: wp(4),
29
- borderRadius: wp(3),
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
- paddingHorizontal: wp(1.5)
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: 20 + index * 60 }]} // Adjust spacing between top toasts
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: 20 + index * 60 }]} // Adjust spacing between bottom toasts
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}