react-native-earl-toastify 1.0.1 → 1.0.2

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 (3) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +56 -144
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.2] - 2026-01-17
9
+
10
+ ### Added
11
+
12
+ - ✨ **Example Images & Video**: Added example images and video for better documentation
13
+
14
+ ---
15
+
8
16
  ## [1.0.1] - 2026-01-17
9
17
 
10
18
  ### Added
package/README.md CHANGED
@@ -17,7 +17,46 @@ A beautiful, customizable toast notification library for React Native with smoot
17
17
  - 🔧 **Highly Configurable**: duration, dismissable, custom icons, custom styles
18
18
  - 📱 **Full-Width Edge Styling**: No rounded corners for top/bottom toasts
19
19
  - đŸĒļ **Zero Dependencies**: Uses only React Native's built-in Animated API
20
- - ✨ **Smooth Stack Transitions**: Remaining toasts slide smoothly when one is dismissed
20
+
21
+ ## 📸 Preview
22
+
23
+ <!-- Add your screenshots here -->
24
+ <!-- ![Toast Types](./assets/toast-types.png) -->
25
+ <!-- ![Animations Demo](./assets/animations.gif) -->
26
+
27
+ <table>
28
+ <tr>
29
+ <td align="center">
30
+ <b>Success</b><br/>
31
+ <img src="https://raw.githubusercontent.com/Swif7ify/react-native-earl-toastify/main/example/1.png" width="220"/>
32
+ </td>
33
+ <td align="center">
34
+ <b>Warning</b><br/>
35
+ <img src="https://raw.githubusercontent.com/Swif7ify/react-native-earl-toastify/main/example/2.png" width="220"/>
36
+ </td>
37
+ <td align="center">
38
+ <b>Error</b><br/>
39
+ <img src="https://raw.githubusercontent.com/Swif7ify/react-native-earl-toastify/main/example/3.png" width="220"/>
40
+ </td>
41
+ </tr>
42
+ <tr>
43
+ <td align="center">
44
+ <b>Info</b><br/>
45
+ <img src="https://raw.githubusercontent.com/Swif7ify/react-native-earl-toastify/main/example/4.png" width="220"/>
46
+ </td>
47
+ <td align="center">
48
+ <b>Show</b><br/>
49
+ <img src="https://raw.githubusercontent.com/Swif7ify/react-native-earl-toastify/main/example/5.png" width="220"/>
50
+ </td>
51
+ <td></td>
52
+ </tr>
53
+ </table>
54
+
55
+
56
+ ### đŸŽĨ Demo Video
57
+ https://github.com/user-attachments/assets/0c96e622-eb7e-4074-ac0a-97a0d04a5d31
58
+
59
+
21
60
 
22
61
  ## đŸ“Ļ Installation
23
62
 
@@ -70,184 +109,57 @@ function MyComponent() {
70
109
 
71
110
  ## đŸ› ī¸ Creating a Toast Utility (Recommended)
72
111
 
73
- For easier usage across your app, create a utility file that exposes toast functions globally with **your own custom defaults**:
112
+ For easier usage across your app, create a utility file that exposes toast functions globally:
74
113
 
75
114
  ### 1. Create `utils/Toast.tsx`
76
115
 
77
116
  ```tsx
78
117
  // utils/Toast.tsx
118
+ import React, { createRef } from "react";
79
119
  import { ToastContextValue, ToastConfig } from "react-native-earl-toastify";
80
- // Optional: import your icon library
81
- // import { CheckCircle, AlertTriangle, XCircle, Info } from "lucide-react-native";
82
-
83
- // ============================================
84
- // Store toast context reference (simple variable)
85
- // ============================================
86
- let toastContext: ToastContextValue | null = null;
87
-
88
- export const setToastContext = (context: ToastContextValue) => {
89
- toastContext = context;
90
- };
91
-
92
- // ============================================
93
- // 🎨 CUSTOMIZE YOUR TOAST DEFAULTS HERE
94
- // ============================================
95
-
96
- const CUSTOM_DEFAULTS: Record<string, Partial<ToastConfig>> = {
97
- // Custom success style - your own green, animation, etc.
98
- success: {
99
- backgroundColor: "#D1FAE5", // Light green
100
- textColor: "#065F46", // Dark green
101
- borderColor: "#10B981", // Green border
102
- animationIn: "up",
103
- animationOut: "down",
104
- position: "bottom",
105
- duration: 3000,
106
- // icon: <CheckCircle color="#10B981" size={20} />,
107
- },
108
-
109
- // Custom error style
110
- error: {
111
- backgroundColor: "#FEE2E2", // Light red
112
- textColor: "#991B1B", // Dark red
113
- borderColor: "#EF4444", // Red border
114
- animationIn: "fade",
115
- animationOut: "fade",
116
- position: "top",
117
- duration: 5000,
118
- // icon: <XCircle color="#EF4444" size={20} />,
119
- },
120
-
121
- // Custom warning style
122
- warning: {
123
- backgroundColor: "#FEF3C7", // Light amber
124
- textColor: "#92400E", // Dark amber
125
- borderColor: "#F59E0B", // Amber border
126
- animationIn: "right",
127
- animationOut: "left",
128
- position: "top",
129
- duration: 4000,
130
- // icon: <AlertTriangle color="#F59E0B" size={20} />,
131
- },
132
-
133
- // Custom info style
134
- info: {
135
- backgroundColor: "#DBEAFE", // Light blue
136
- textColor: "#1E40AF", // Dark blue
137
- borderColor: "#3B82F6", // Blue border
138
- animationIn: "left",
139
- animationOut: "right",
140
- position: "top",
141
- duration: 3000,
142
- // icon: <Info color="#3B82F6" size={20} />,
143
- },
144
- };
145
120
 
146
- // ============================================
147
- // Helper to parse flexible arguments
148
- // ============================================
149
- const parseArgs = (
150
- titleOrMessage: string,
151
- descriptionOrConfig?: string | Partial<ToastConfig>,
152
- config?: Partial<ToastConfig>,
153
- ): { title?: string; message: string; config?: Partial<ToastConfig> } => {
154
- if (typeof descriptionOrConfig === "string") {
155
- return { title: titleOrMessage, message: descriptionOrConfig, config };
156
- }
157
- return { message: titleOrMessage, config: descriptionOrConfig };
158
- };
121
+ // Create a ref to hold the toast context
122
+ export const toastRef = createRef<ToastContextValue>();
159
123
 
160
- // ============================================
161
- // Toast utility with custom defaults
162
- // ============================================
124
+ // Export convenience methods
163
125
  const Toast = {
126
+ // Supports: success("message") OR success("title", "description")
164
127
  success: (
165
128
  titleOrMessage: string,
166
129
  descriptionOrConfig?: string | Partial<ToastConfig>,
167
130
  config?: Partial<ToastConfig>,
168
131
  ) => {
169
- const {
170
- title,
171
- message,
172
- config: cfg,
173
- } = parseArgs(titleOrMessage, descriptionOrConfig, config);
174
- toastContext?.show({
175
- ...CUSTOM_DEFAULTS.success,
176
- ...cfg,
177
- title,
178
- message,
179
- type: "custom", // Use custom to apply our colors
180
- });
132
+ toastRef.current?.success(titleOrMessage, descriptionOrConfig, config);
181
133
  },
182
-
183
134
  error: (
184
135
  titleOrMessage: string,
185
136
  descriptionOrConfig?: string | Partial<ToastConfig>,
186
137
  config?: Partial<ToastConfig>,
187
138
  ) => {
188
- const {
189
- title,
190
- message,
191
- config: cfg,
192
- } = parseArgs(titleOrMessage, descriptionOrConfig, config);
193
- toastContext?.show({
194
- ...CUSTOM_DEFAULTS.error,
195
- ...cfg,
196
- title,
197
- message,
198
- type: "custom",
199
- });
139
+ toastRef.current?.error(titleOrMessage, descriptionOrConfig, config);
200
140
  },
201
-
202
141
  warning: (
203
142
  titleOrMessage: string,
204
143
  descriptionOrConfig?: string | Partial<ToastConfig>,
205
144
  config?: Partial<ToastConfig>,
206
145
  ) => {
207
- const {
208
- title,
209
- message,
210
- config: cfg,
211
- } = parseArgs(titleOrMessage, descriptionOrConfig, config);
212
- toastContext?.show({
213
- ...CUSTOM_DEFAULTS.warning,
214
- ...cfg,
215
- title,
216
- message,
217
- type: "custom",
218
- });
146
+ toastRef.current?.warning(titleOrMessage, descriptionOrConfig, config);
219
147
  },
220
-
221
148
  info: (
222
149
  titleOrMessage: string,
223
150
  descriptionOrConfig?: string | Partial<ToastConfig>,
224
151
  config?: Partial<ToastConfig>,
225
152
  ) => {
226
- const {
227
- title,
228
- message,
229
- config: cfg,
230
- } = parseArgs(titleOrMessage, descriptionOrConfig, config);
231
- toastContext?.show({
232
- ...CUSTOM_DEFAULTS.info,
233
- ...cfg,
234
- title,
235
- message,
236
- type: "custom",
237
- });
153
+ toastRef.current?.info(titleOrMessage, descriptionOrConfig, config);
238
154
  },
239
-
240
- // Generic show for full customization
241
155
  show: (config: ToastConfig) => {
242
- toastContext?.show(config);
156
+ toastRef.current?.show(config);
243
157
  },
244
-
245
158
  hide: (id: string) => {
246
- toastContext?.hide(id);
159
+ toastRef.current?.hide(id);
247
160
  },
248
-
249
161
  hideAll: () => {
250
- toastContext?.hideAll();
162
+ toastRef.current?.hideAll();
251
163
  },
252
164
  };
253
165
 
@@ -260,7 +172,7 @@ export default Toast;
260
172
  // components/ToastWrapper.tsx
261
173
  import React, { useEffect } from "react";
262
174
  import { useToast } from "react-native-earl-toastify";
263
- import { setToastContext } from "../utils/Toast";
175
+ import { toastRef } from "../utils/Toast";
264
176
 
265
177
  export const ToastWrapper: React.FC<{ children: React.ReactNode }> = ({
266
178
  children,
@@ -268,8 +180,8 @@ export const ToastWrapper: React.FC<{ children: React.ReactNode }> = ({
268
180
  const toast = useToast();
269
181
 
270
182
  useEffect(() => {
271
- // Set the toast context when component mounts
272
- setToastContext(toast);
183
+ // Assign the toast context to the ref
184
+ (toastRef as React.MutableRefObject<typeof toast>).current = toast;
273
185
  }, [toast]);
274
186
 
275
187
  return <>{children}</>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-earl-toastify",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A beautiful, customizable toast notification library for React Native with animations, multiple toast types, and accessibility support",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",