react-native-modern-toast 0.1.0 → 0.1.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 (2) hide show
  1. package/README.md +221 -178
  2. package/package.json +9 -5
package/README.md CHANGED
@@ -1,296 +1,339 @@
1
- # react-native-flex-toast
1
+ # react-native-modern-toast
2
2
 
3
- A lightweight, flexible toast notification component for React Native with support for multiple variants, custom icons, and images. Easy to integrate and highly customizable.
3
+ A lightweight, customizable React Native toast library with support for:
4
4
 
5
- ## Features
6
-
7
- **Multiple Variants** - Success, Error, Warning, Info, and Modern toast styles
8
- 🖼️ **Icon Support** - Use custom React nodes or image sources (URI or require)
9
- ⏱️ **Customizable Duration** - Control how long toasts are displayed
10
- 📍 **Flexible Positioning** - Show toasts at top or bottom of screen
11
- 🎨 **Custom Styling** - Override colors, height, and container styles
12
- 📦 **Lightweight** - Minimal dependencies, TypeScript support
13
- 🪝 **Hook-based API** - Simple `useToast()` hook for showing notifications
5
+ * 🚀 Top, Center & Bottom Toast Positions
6
+ * 🎨 Custom Background Colors
7
+ * 📏 Custom Height
8
+ * 🖼 Custom Icons
9
+ * Auto Dismiss Duration
10
+ * 📱 Works Identically on Android & iOS
11
+ * No Native Dependencies
12
+ * 🔷 TypeScript Support
13
+ * 🎯 Multiple Toast Variants
14
14
 
15
15
  ## Installation
16
16
 
17
17
  ```bash
18
- npm install react-native-flex-toast
19
- # or
20
- yarn add react-native-flex-toast
18
+ npm install react-native-modern-toast
19
+ ```
20
+
21
+ or
22
+
23
+ ```bash
24
+ yarn add react-native-modern-toast
21
25
  ```
22
26
 
23
- ## Quick Start
27
+ ---
28
+
29
+ ## Setup
30
+
31
+ Wrap your app with `ToastProvider`.
24
32
 
25
- ### 1. Wrap Your App with ToastProvider
33
+ ### Expo Router
26
34
 
27
35
  ```tsx
28
- import React from 'react';
29
- import { View } from 'react-native';
30
- import { ToastProvider } from 'react-native-flex-toast';
36
+ import { ToastProvider } from "react-native-modern-toast";
31
37
 
32
- export default function App() {
38
+ export default function RootLayout() {
33
39
  return (
34
40
  <ToastProvider>
35
- <YourAppContent />
41
+ <Stack />
36
42
  </ToastProvider>
37
43
  );
38
44
  }
39
45
  ```
40
46
 
41
- ### 2. Use the Hook to Show Toasts
47
+ ### React Native
42
48
 
43
49
  ```tsx
44
- import { useToast } from 'react-native-flex-toast';
45
- import { View, Button } from 'react-native';
50
+ import { ToastProvider } from "react-native-modern-toast";
51
+
52
+ export default function App() {
53
+ return (
54
+ <ToastProvider>
55
+ <HomeScreen />
56
+ </ToastProvider>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ---
46
62
 
47
- export function MyComponent() {
48
- const { showToast } = useToast();
63
+ ## Usage
64
+
65
+ ```tsx
66
+ import { useToast } from "react-native-modern-toast";
49
67
 
50
- const handleSuccess = () => {
51
- showToast({
52
- message: 'Action completed successfully!',
53
- variant: 'success',
54
- });
55
- };
68
+ export default function HomeScreen() {
69
+ const toast = useToast();
56
70
 
57
71
  return (
58
- <View>
59
- <Button title="Show Toast" onPress={handleSuccess} />
60
- </View>
72
+ <Button
73
+ title="Show Toast"
74
+ onPress={() =>
75
+ toast?.showToast({
76
+ title: "Success",
77
+ message: "Profile updated successfully",
78
+ variant: "success",
79
+ })
80
+ }
81
+ />
61
82
  );
62
83
  }
63
84
  ```
64
85
 
65
- ## Usage Examples
86
+ ---
66
87
 
67
- ### Basic Toast
88
+ ## Top Toast
68
89
 
69
90
  ```tsx
70
- const { showToast } = useToast();
71
-
72
- showToast({
73
- message: 'Hello World!',
74
- variant: 'info',
91
+ toast?.showToast({
92
+ title: "Success",
93
+ message: "Top Toast",
94
+ variant: "success",
95
+ position: "top",
75
96
  });
76
97
  ```
77
98
 
78
- ### Toast with Image Icon (URI)
99
+ ---
100
+
101
+ ## Center Toast
79
102
 
80
103
  ```tsx
81
- showToast({
82
- message: 'Profile saved',
83
- variant: 'success',
84
- iconSource: { uri: 'https://example.com/check.png' },
104
+ toast?.showToast({
105
+ title: "Information",
106
+ message: "Center Toast",
107
+ variant: "info",
108
+ position: "center",
85
109
  });
86
110
  ```
87
111
 
88
- ### Toast with Local Image
112
+ ---
113
+
114
+ ## Bottom Toast
89
115
 
90
116
  ```tsx
91
- showToast({
92
- message: 'Download complete',
93
- variant: 'success',
94
- iconSource: require('./assets/download-icon.png'),
117
+ toast?.showToast({
118
+ title: "Warning",
119
+ message: "Bottom Toast",
120
+ variant: "warning",
121
+ position: "bottom",
95
122
  });
96
123
  ```
97
124
 
98
- ### Toast with Custom React Node Icon
125
+ ---
126
+
127
+ ## Variants
128
+
129
+ ### Success
99
130
 
100
131
  ```tsx
101
- import { Image, Text } from 'react-native';
102
-
103
- showToast({
104
- message: 'Custom icon toast',
105
- variant: 'info',
106
- icon: (
107
- <Image
108
- source={{ uri: 'https://example.com/avatar.png' }}
109
- style={{ width: 28, height: 28, borderRadius: 14 }}
110
- />
111
- ),
132
+ toast?.showToast({
133
+ message: "Success Toast",
134
+ variant: "success",
112
135
  });
113
136
  ```
114
137
 
115
- ### Toast with Custom Duration
138
+ ### Error
116
139
 
117
140
  ```tsx
118
- showToast({
119
- message: 'This will stay for 5 seconds',
120
- variant: 'warning',
121
- duration: 5000, // 5000ms
141
+ toast?.showToast({
142
+ message: "Error Toast",
143
+ variant: "error",
122
144
  });
123
145
  ```
124
146
 
125
- ### Toast with Custom Position
147
+ ### Warning
126
148
 
127
149
  ```tsx
128
- showToast({
129
- message: 'Bottom positioned toast',
130
- variant: 'error',
131
- position: 'bottom', // or 'top' (default)
150
+ toast?.showToast({
151
+ message: "Warning Toast",
152
+ variant: "warning",
132
153
  });
133
154
  ```
134
155
 
135
- ### Toast with Custom Colors & Styles
156
+ ### Info
136
157
 
137
158
  ```tsx
138
- showToast({
139
- message: 'Custom styled toast',
140
- backgroundColor: '#FF6B6B',
141
- height: 70,
142
- iconSource: { uri: 'https://example.com/icon.png' },
159
+ toast?.showToast({
160
+ message: "Info Toast",
161
+ variant: "info",
143
162
  });
144
163
  ```
145
164
 
146
- ### Complete Example with All Options
165
+ ### Modern
147
166
 
148
167
  ```tsx
149
- showToast({
150
- message: 'Profile updated successfully',
151
- variant: 'success',
152
- position: 'top',
153
- duration: 4000,
154
- icon: <Text style={{ fontSize: 20 }}>✓</Text>,
155
- height: 65,
156
- backgroundColor: '#10B981',
157
- iconStyle: { width: 24, height: 24 },
158
- containerStyle: { borderWidth: 1, borderColor: '#059669' },
168
+ toast?.showToast({
169
+ message: "Modern Toast",
170
+ variant: "modern",
159
171
  });
160
172
  ```
161
173
 
162
- ## API Reference
163
-
164
- ### ToastProvider
174
+ ---
165
175
 
166
- Wraps your app to provide toast functionality.
176
+ ## Custom Background Color
167
177
 
168
178
  ```tsx
169
- <ToastProvider>
170
- {children}
171
- </ToastProvider>
179
+ toast?.showToast({
180
+ title: "Custom",
181
+ message: "Custom Color Toast",
182
+ backgroundColor: "#3251A0",
183
+ });
172
184
  ```
173
185
 
174
- ### useToast Hook
186
+ ---
175
187
 
176
- Returns an object with the `showToast` function.
188
+ ## Custom Height
177
189
 
178
190
  ```tsx
179
- const { showToast } = useToast();
191
+ toast?.showToast({
192
+ message: "Large Toast",
193
+ height: 90,
194
+ });
180
195
  ```
181
196
 
182
- ### showToast(options: ToastOptions)
197
+ ---
183
198
 
184
- Displays a toast notification with the provided options.
199
+ ## Custom Icon
185
200
 
186
- **Parameters:**
201
+ ```tsx
202
+ toast?.showToast({
203
+ title: "Success",
204
+ message: "Uploaded Successfully",
205
+ icon: require("./assets/success.png"),
206
+ });
207
+ ```
187
208
 
188
- | Property | Type | Default | Description |
189
- |----------|------|---------|-------------|
190
- | `message` | `string` | **Required** | The text content of the toast |
191
- | `variant` | `'success' \| 'error' \| 'warning' \| 'info' \| 'modern'` | `'info'` | Visual style/color variant |
192
- | `position` | `'top' \| 'bottom'` | `'top'` | Vertical position on screen |
193
- | `duration` | `number` | `3000` | How long to display (milliseconds) |
194
- | `backgroundColor` | `string` | - | Override the variant color |
195
- | `height` | `number` | `60` | Toast container height |
196
- | `icon` | `React.ReactNode` | - | Custom React component for icon |
197
- | `iconSource` | `ImageSourcePropType` | - | Image source (URI or require) |
198
- | `iconStyle` | `ImageStyle` | - | Styling for the image icon |
199
- | `containerStyle` | `ViewStyle` | - | Custom styles for toast container |
209
+ ### Network Image
200
210
 
201
- ## Toast Variants
211
+ ```tsx
212
+ toast?.showToast({
213
+ title: "Profile",
214
+ message: "Image Loaded",
215
+ icon: "https://example.com/icon.png",
216
+ });
217
+ ```
202
218
 
203
- Each variant has a default color:
219
+ ### Use `type` alias for variant
204
220
 
205
- | Variant | Color | Hex Code |
206
- |---------|-------|----------|
207
- | `success` | Green | `#22C55E` |
208
- | `error` | Red | `#EF4444` |
209
- | `warning` | Amber | `#F59E0B` |
210
- | `info` | Blue | `#3B82F6` |
211
- | `modern` | Dark Gray | `#111827` |
221
+ ```tsx
222
+ toast?.showToast({
223
+ title: "Info",
224
+ message: "Type alias works",
225
+ type: "info",
226
+ position: "center",
227
+ time: 8,
228
+ icon: "https://example.com/info.png",
229
+ });
230
+ ```
212
231
 
213
- ## Variant Components
232
+ ---
214
233
 
215
- The package also exports pre-styled variant components:
234
+ ## Custom Duration
216
235
 
217
236
  ```tsx
218
- import { SuccessToast, ErrorToast, WarningToast, InfoToast, ModernToast } from 'react-native-flex-toast';
237
+ toast?.showToast({
238
+ message: "Will hide after 5 seconds",
239
+ duration: 5000,
240
+ });
241
+ ```
242
+
243
+ ---
244
+
245
+ ## Custom Time (seconds)
219
246
 
220
- // These are pre-configured with their respective colors
247
+ ```tsx
248
+ toast?.showToast({
249
+ message: "Will hide after 10 seconds",
250
+ time: 10,
251
+ });
221
252
  ```
222
253
 
223
- ## TypeScript Support
254
+ ---
224
255
 
225
- Full TypeScript support with exported types:
256
+ ## Custom Top Padding
226
257
 
227
258
  ```tsx
228
- import type { ToastOptions, ToastProps, ToastVariant } from 'react-native-flex-toast';
259
+ toast?.showToast({
260
+ message: "Top Padding",
261
+ position: "top",
262
+ topPadding: 100,
263
+ });
229
264
  ```
230
265
 
231
- ## Project Structure
266
+ ---
267
+
268
+ ## Custom Bottom Padding
232
269
 
270
+ ```tsx
271
+ toast?.showToast({
272
+ message: "Bottom Padding",
273
+ position: "bottom",
274
+ bottomPadding: 100,
275
+ });
233
276
  ```
234
- react-native-flex-toast/
235
- ├── src/
236
- │ ├── Toast.tsx # Core Toast component
237
- │ ├── ToastProvider.tsx # Provider and useToast hook
238
- │ ├── index.ts # Exports
239
- │ └── variants/
240
- │ ├── SuccessToast.tsx # Success variant wrapper
241
- │ ├── ErrorToast.tsx # Error variant wrapper
242
- │ ├── WarningToast.tsx # Warning variant wrapper
243
- │ ├── InfoToast.tsx # Info variant wrapper
244
- │ └── ModernToast.tsx # Modern variant wrapper
245
- ├── package.json
246
- └── README.md
277
+
278
+ ---
279
+
280
+ ## API Reference
281
+
282
+ | Prop | Type | Default |
283
+ | --------------- | ----------------------------------------- | ------------- |
284
+ | title | string | undefined |
285
+ | message | string | required |
286
+ | variant | success | error | warning | info | modern | info |
287
+ | type | success | error | warning | info | modern | info |
288
+ | position | top | center | bottom | top |
289
+ | duration | number | 3000 |
290
+ | time | number | undefined |
291
+ | backgroundColor | string | variant color |
292
+ | height | number | 70 |
293
+ | topPadding | number | 50 |
294
+ | bottomPadding | number | 40 |
295
+ | icon | ImageSourcePropType | string | undefined |
296
+
297
+ ---
298
+
299
+ ## TypeScript
300
+
301
+ Fully typed and TypeScript ready.
302
+
303
+ ```tsx
304
+ import { ToastOptions } from "react-native-modern-toast";
247
305
  ```
248
306
 
249
- ## Key Features Explained
307
+ ---
250
308
 
251
- ### Icon/Image Props
309
+ ## Features
252
310
 
253
- The component supports two ways to add icons:
311
+ Android Support
254
312
 
255
- 1. **`iconSource`** - For image assets (most common)
256
- ```tsx
257
- iconSource: { uri: 'https://...' } // Web image
258
- iconSource: require('./icon.png') // Local image
259
- ```
313
+ iOS Support
260
314
 
261
- 2. **`icon`** - For custom React nodes
262
- ```tsx
263
- icon: <Text style={{ fontSize: 20 }}>✓</Text>
264
- icon: <Image source={...} />
265
- ```
315
+ Expo Support
266
316
 
267
- **Priority:** If both `icon` and `iconSource` are provided, `icon` takes precedence.
317
+ React Native CLI Support
268
318
 
269
- ### Auto-dismiss
319
+ TypeScript Support
270
320
 
271
- Toasts automatically dismiss after the specified `duration` (default 3000ms). Showing a new toast while one is active will replace and reset the timer.
321
+ Custom Icons
272
322
 
273
- ### Context Error Handling
323
+ Custom Height
274
324
 
275
- If you call `useToast()` outside of `ToastProvider`, a helpful error is thrown:
276
- ```
277
- "useToast must be used within a ToastProvider"
278
- ```
325
+ Custom Colors
279
326
 
280
- ## Best Practices
327
+ Top / Center / Bottom Position
281
328
 
282
- Always wrap your app/root component with `ToastProvider`
283
- ✅ Use appropriate `variant` for different message types
284
- ✅ Keep messages concise for better readability
285
- ✅ Use `duration` based on message length (4-5 seconds for longer text)
286
- ✅ Prefer `iconSource` with URIs for remote images
287
- ✅ Use custom `icon` nodes for lightweight SVG or emoji icons
329
+ Lightweight
288
330
 
289
- ## Requirements
331
+ No Native Modules
290
332
 
291
- - React Native 0.72+
292
- - React 16.8+ (hooks)
333
+ ---
293
334
 
294
335
  ## License
295
336
 
296
- ISC
337
+ MIT
338
+
339
+ Neeraj Singh
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-modern-toast",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A lightweight React Native toast provider with icon support, multiple variants, and TypeScript definitions.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,10 +19,14 @@
19
19
  },
20
20
  "keywords": [
21
21
  "react-native",
22
- "toast",
23
- "notification",
24
- "toast-provider",
25
- "typescript"
22
+ "react-native-toast-provider",
23
+ "react-native-modern-toast",
24
+ "react-native-custom-toast",
25
+ "react-native-toast",
26
+ "react-native-toast-notification",
27
+ "react-native-toast-message",
28
+ "react-native-toastify",
29
+ "react-native-toast-component"
26
30
  ],
27
31
  "author": "",
28
32
  "license": "ISC",