react-native-earl-toastify 1.0.0

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/LICENSE +21 -0
  3. package/README.md +513 -0
  4. package/dist/Toast.d.ts +12 -0
  5. package/dist/Toast.d.ts.map +1 -0
  6. package/dist/Toast.js +143 -0
  7. package/dist/Toast.js.map +1 -0
  8. package/dist/ToastContainer.d.ts +12 -0
  9. package/dist/ToastContainer.d.ts.map +1 -0
  10. package/dist/ToastContainer.js +46 -0
  11. package/dist/ToastContainer.js.map +1 -0
  12. package/dist/ToastProvider.d.ts +22 -0
  13. package/dist/ToastProvider.d.ts.map +1 -0
  14. package/dist/ToastProvider.js +163 -0
  15. package/dist/ToastProvider.js.map +1 -0
  16. package/dist/animations.d.ts +54 -0
  17. package/dist/animations.d.ts.map +1 -0
  18. package/dist/animations.js +118 -0
  19. package/dist/animations.js.map +1 -0
  20. package/dist/icons.d.ts +12 -0
  21. package/dist/icons.d.ts.map +1 -0
  22. package/dist/icons.js +110 -0
  23. package/dist/icons.js.map +1 -0
  24. package/dist/index.d.ts +10 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +14 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/styles.d.ts +63 -0
  29. package/dist/styles.d.ts.map +1 -0
  30. package/dist/styles.js +182 -0
  31. package/dist/styles.js.map +1 -0
  32. package/dist/types.d.ts +100 -0
  33. package/dist/types.d.ts.map +1 -0
  34. package/dist/types.js +2 -0
  35. package/dist/types.js.map +1 -0
  36. package/dist/useToast.d.ts +40 -0
  37. package/dist/useToast.d.ts.map +1 -0
  38. package/dist/useToast.js +48 -0
  39. package/dist/useToast.js.map +1 -0
  40. package/dist/useToastAnimation.d.ts +24 -0
  41. package/dist/useToastAnimation.d.ts.map +1 -0
  42. package/dist/useToastAnimation.js +59 -0
  43. package/dist/useToastAnimation.js.map +1 -0
  44. package/package.json +58 -0
  45. package/src/Toast.tsx +250 -0
  46. package/src/ToastContainer.tsx +70 -0
  47. package/src/ToastProvider.tsx +271 -0
  48. package/src/animations.ts +161 -0
  49. package/src/icons.tsx +152 -0
  50. package/src/index.ts +41 -0
  51. package/src/styles.ts +208 -0
  52. package/src/types.ts +157 -0
  53. package/src/useToast.ts +53 -0
  54. package/src/useToastAnimation.ts +108 -0
@@ -0,0 +1,53 @@
1
+ import { useContext } from "react";
2
+ import { ToastContext } from "./ToastProvider";
3
+ import { ToastContextValue } from "./types";
4
+
5
+ /**
6
+ * Hook to access toast functions
7
+ *
8
+ * @returns Toast context with show, success, warning, error, info, hide, and hideAll methods
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const toast = useToast();
13
+ *
14
+ * // Show different toast types
15
+ * toast.success('Operation completed!');
16
+ * toast.error('Something went wrong');
17
+ * toast.warning('Please check your input');
18
+ * toast.info('New update available');
19
+ *
20
+ * // Show with custom configuration
21
+ * toast.show({
22
+ * message: 'Custom toast',
23
+ * type: 'custom',
24
+ * backgroundColor: '#8B5CF6',
25
+ * textColor: '#FFFFFF',
26
+ * position: 'bottom',
27
+ * duration: 5000,
28
+ * animationIn: 'up',
29
+ * animationOut: 'down',
30
+ * });
31
+ *
32
+ * // Hide specific toast
33
+ * const id = toast.success('Saving...');
34
+ * toast.hide(id);
35
+ *
36
+ * // Hide all toasts
37
+ * toast.hideAll();
38
+ * ```
39
+ *
40
+ * @throws Error if used outside of ToastProvider
41
+ */
42
+ export const useToast = (): ToastContextValue => {
43
+ const context = useContext(ToastContext);
44
+
45
+ if (!context) {
46
+ throw new Error(
47
+ "useToast must be used within a ToastProvider. " +
48
+ "Wrap your app with <ToastProvider> to use toast notifications.",
49
+ );
50
+ }
51
+
52
+ return context;
53
+ };
@@ -0,0 +1,108 @@
1
+ import { useRef, useEffect, useCallback } from "react";
2
+ import { Animated } from "react-native";
3
+ import { ToastAnimation, ToastPosition } from "./types";
4
+ import {
5
+ getInitialAnimatedValues,
6
+ createEnterAnimation,
7
+ createExitAnimation,
8
+ DEFAULT_ANIMATION_CONFIG,
9
+ } from "./animations";
10
+
11
+ type TransformStyle =
12
+ | { translateX: Animated.Value }
13
+ | { translateY: Animated.Value };
14
+
15
+ /**
16
+ * Hook return type
17
+ */
18
+ export interface UseToastAnimationReturn {
19
+ animatedStyle: {
20
+ opacity: Animated.Value;
21
+ transform: TransformStyle[];
22
+ };
23
+ startEnterAnimation: () => void;
24
+ startExitAnimation: (callback?: () => void) => void;
25
+ }
26
+
27
+ /**
28
+ * Custom hook for managing toast animations
29
+ */
30
+ export const useToastAnimation = (
31
+ animationIn: ToastAnimation,
32
+ animationOut: ToastAnimation,
33
+ position: ToastPosition,
34
+ animationDuration: number = DEFAULT_ANIMATION_CONFIG.duration,
35
+ ): UseToastAnimationReturn => {
36
+ // Get initial values based on enter animation
37
+ const initialValues = getInitialAnimatedValues(animationIn, position);
38
+
39
+ // Create animated values
40
+ const opacity = useRef(new Animated.Value(initialValues.opacity)).current;
41
+ const translateX = useRef(
42
+ new Animated.Value(initialValues.translateX),
43
+ ).current;
44
+ const translateY = useRef(
45
+ new Animated.Value(initialValues.translateY),
46
+ ).current;
47
+
48
+ // Animation config
49
+ const config = {
50
+ duration: animationDuration,
51
+ useNativeDriver: true,
52
+ };
53
+
54
+ /**
55
+ * Start enter animation
56
+ */
57
+ const startEnterAnimation = useCallback(() => {
58
+ const animation = createEnterAnimation(
59
+ { opacity, translateX, translateY },
60
+ config,
61
+ );
62
+ animation.start();
63
+ }, [opacity, translateX, translateY, config.duration]);
64
+
65
+ /**
66
+ * Start exit animation with optional callback
67
+ */
68
+ const startExitAnimation = useCallback(
69
+ (callback?: () => void) => {
70
+ const animation = createExitAnimation(
71
+ { opacity, translateX, translateY },
72
+ animationOut,
73
+ position,
74
+ config,
75
+ );
76
+ animation.start(({ finished }) => {
77
+ if (finished && callback) {
78
+ callback();
79
+ }
80
+ });
81
+ },
82
+ [
83
+ opacity,
84
+ translateX,
85
+ translateY,
86
+ animationOut,
87
+ position,
88
+ config.duration,
89
+ ],
90
+ );
91
+
92
+ // Start enter animation on mount
93
+ useEffect(() => {
94
+ startEnterAnimation();
95
+ }, []);
96
+
97
+ // Animated style object
98
+ const animatedStyle: UseToastAnimationReturn["animatedStyle"] = {
99
+ opacity,
100
+ transform: [{ translateX }, { translateY }] as TransformStyle[],
101
+ };
102
+
103
+ return {
104
+ animatedStyle,
105
+ startEnterAnimation,
106
+ startExitAnimation,
107
+ };
108
+ };