react-native-modern-toast 0.1.0 → 0.1.1
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/README.md +221 -178
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,296 +1,339 @@
|
|
|
1
|
-
# react-native-
|
|
1
|
+
# react-native-modern-toast
|
|
2
2
|
|
|
3
|
-
A lightweight,
|
|
3
|
+
A lightweight, customizable React Native toast library with support for:
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
Wrap your app with `ToastProvider`.
|
|
24
32
|
|
|
25
|
-
###
|
|
33
|
+
### Expo Router
|
|
26
34
|
|
|
27
35
|
```tsx
|
|
28
|
-
import
|
|
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
|
|
38
|
+
export default function RootLayout() {
|
|
33
39
|
return (
|
|
34
40
|
<ToastProvider>
|
|
35
|
-
<
|
|
41
|
+
<Stack />
|
|
36
42
|
</ToastProvider>
|
|
37
43
|
);
|
|
38
44
|
}
|
|
39
45
|
```
|
|
40
46
|
|
|
41
|
-
###
|
|
47
|
+
### React Native
|
|
42
48
|
|
|
43
49
|
```tsx
|
|
44
|
-
import {
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import { useToast } from "react-native-modern-toast";
|
|
49
67
|
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
86
|
+
---
|
|
66
87
|
|
|
67
|
-
|
|
88
|
+
## Top Toast
|
|
68
89
|
|
|
69
90
|
```tsx
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
toast?.showToast({
|
|
92
|
+
title: "Success",
|
|
93
|
+
message: "Top Toast",
|
|
94
|
+
variant: "success",
|
|
95
|
+
position: "top",
|
|
75
96
|
});
|
|
76
97
|
```
|
|
77
98
|
|
|
78
|
-
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Center Toast
|
|
79
102
|
|
|
80
103
|
```tsx
|
|
81
|
-
showToast({
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
104
|
+
toast?.showToast({
|
|
105
|
+
title: "Information",
|
|
106
|
+
message: "Center Toast",
|
|
107
|
+
variant: "info",
|
|
108
|
+
position: "center",
|
|
85
109
|
});
|
|
86
110
|
```
|
|
87
111
|
|
|
88
|
-
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Bottom Toast
|
|
89
115
|
|
|
90
116
|
```tsx
|
|
91
|
-
showToast({
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
117
|
+
toast?.showToast({
|
|
118
|
+
title: "Warning",
|
|
119
|
+
message: "Bottom Toast",
|
|
120
|
+
variant: "warning",
|
|
121
|
+
position: "bottom",
|
|
95
122
|
});
|
|
96
123
|
```
|
|
97
124
|
|
|
98
|
-
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Variants
|
|
128
|
+
|
|
129
|
+
### Success
|
|
99
130
|
|
|
100
131
|
```tsx
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
###
|
|
138
|
+
### Error
|
|
116
139
|
|
|
117
140
|
```tsx
|
|
118
|
-
showToast({
|
|
119
|
-
message:
|
|
120
|
-
variant:
|
|
121
|
-
duration: 5000, // 5000ms
|
|
141
|
+
toast?.showToast({
|
|
142
|
+
message: "Error Toast",
|
|
143
|
+
variant: "error",
|
|
122
144
|
});
|
|
123
145
|
```
|
|
124
146
|
|
|
125
|
-
###
|
|
147
|
+
### Warning
|
|
126
148
|
|
|
127
149
|
```tsx
|
|
128
|
-
showToast({
|
|
129
|
-
message:
|
|
130
|
-
variant:
|
|
131
|
-
position: 'bottom', // or 'top' (default)
|
|
150
|
+
toast?.showToast({
|
|
151
|
+
message: "Warning Toast",
|
|
152
|
+
variant: "warning",
|
|
132
153
|
});
|
|
133
154
|
```
|
|
134
155
|
|
|
135
|
-
###
|
|
156
|
+
### Info
|
|
136
157
|
|
|
137
158
|
```tsx
|
|
138
|
-
showToast({
|
|
139
|
-
message:
|
|
140
|
-
|
|
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
|
-
###
|
|
165
|
+
### Modern
|
|
147
166
|
|
|
148
167
|
```tsx
|
|
149
|
-
showToast({
|
|
150
|
-
message:
|
|
151
|
-
variant:
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
### ToastProvider
|
|
174
|
+
---
|
|
165
175
|
|
|
166
|
-
|
|
176
|
+
## Custom Background Color
|
|
167
177
|
|
|
168
178
|
```tsx
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
179
|
+
toast?.showToast({
|
|
180
|
+
title: "Custom",
|
|
181
|
+
message: "Custom Color Toast",
|
|
182
|
+
backgroundColor: "#3251A0",
|
|
183
|
+
});
|
|
172
184
|
```
|
|
173
185
|
|
|
174
|
-
|
|
186
|
+
---
|
|
175
187
|
|
|
176
|
-
|
|
188
|
+
## Custom Height
|
|
177
189
|
|
|
178
190
|
```tsx
|
|
179
|
-
|
|
191
|
+
toast?.showToast({
|
|
192
|
+
message: "Large Toast",
|
|
193
|
+
height: 90,
|
|
194
|
+
});
|
|
180
195
|
```
|
|
181
196
|
|
|
182
|
-
|
|
197
|
+
---
|
|
183
198
|
|
|
184
|
-
|
|
199
|
+
## Custom Icon
|
|
185
200
|
|
|
186
|
-
|
|
201
|
+
```tsx
|
|
202
|
+
toast?.showToast({
|
|
203
|
+
title: "Success",
|
|
204
|
+
message: "Uploaded Successfully",
|
|
205
|
+
icon: require("./assets/success.png"),
|
|
206
|
+
});
|
|
207
|
+
```
|
|
187
208
|
|
|
188
|
-
|
|
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
|
-
|
|
211
|
+
```tsx
|
|
212
|
+
toast?.showToast({
|
|
213
|
+
title: "Profile",
|
|
214
|
+
message: "Image Loaded",
|
|
215
|
+
icon: "https://example.com/icon.png",
|
|
216
|
+
});
|
|
217
|
+
```
|
|
202
218
|
|
|
203
|
-
|
|
219
|
+
### Use `type` alias for variant
|
|
204
220
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
232
|
+
---
|
|
214
233
|
|
|
215
|
-
|
|
234
|
+
## Custom Duration
|
|
216
235
|
|
|
217
236
|
```tsx
|
|
218
|
-
|
|
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
|
-
|
|
247
|
+
```tsx
|
|
248
|
+
toast?.showToast({
|
|
249
|
+
message: "Will hide after 10 seconds",
|
|
250
|
+
time: 10,
|
|
251
|
+
});
|
|
221
252
|
```
|
|
222
253
|
|
|
223
|
-
|
|
254
|
+
---
|
|
224
255
|
|
|
225
|
-
|
|
256
|
+
## Custom Top Padding
|
|
226
257
|
|
|
227
258
|
```tsx
|
|
228
|
-
|
|
259
|
+
toast?.showToast({
|
|
260
|
+
message: "Top Padding",
|
|
261
|
+
position: "top",
|
|
262
|
+
topPadding: 100,
|
|
263
|
+
});
|
|
229
264
|
```
|
|
230
265
|
|
|
231
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
307
|
+
---
|
|
250
308
|
|
|
251
|
-
|
|
309
|
+
## Features
|
|
252
310
|
|
|
253
|
-
|
|
311
|
+
✅ Android Support
|
|
254
312
|
|
|
255
|
-
|
|
256
|
-
```tsx
|
|
257
|
-
iconSource: { uri: 'https://...' } // Web image
|
|
258
|
-
iconSource: require('./icon.png') // Local image
|
|
259
|
-
```
|
|
313
|
+
✅ iOS Support
|
|
260
314
|
|
|
261
|
-
|
|
262
|
-
```tsx
|
|
263
|
-
icon: <Text style={{ fontSize: 20 }}>✓</Text>
|
|
264
|
-
icon: <Image source={...} />
|
|
265
|
-
```
|
|
315
|
+
✅ Expo Support
|
|
266
316
|
|
|
267
|
-
|
|
317
|
+
✅ React Native CLI Support
|
|
268
318
|
|
|
269
|
-
|
|
319
|
+
✅ TypeScript Support
|
|
270
320
|
|
|
271
|
-
|
|
321
|
+
✅ Custom Icons
|
|
272
322
|
|
|
273
|
-
|
|
323
|
+
✅ Custom Height
|
|
274
324
|
|
|
275
|
-
|
|
276
|
-
```
|
|
277
|
-
"useToast must be used within a ToastProvider"
|
|
278
|
-
```
|
|
325
|
+
✅ Custom Colors
|
|
279
326
|
|
|
280
|
-
|
|
327
|
+
✅ Top / Center / Bottom Position
|
|
281
328
|
|
|
282
|
-
✅
|
|
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
|
-
|
|
331
|
+
✅ No Native Modules
|
|
290
332
|
|
|
291
|
-
|
|
292
|
-
- React 16.8+ (hooks)
|
|
333
|
+
---
|
|
293
334
|
|
|
294
335
|
## License
|
|
295
336
|
|
|
296
|
-
|
|
337
|
+
MIT
|
|
338
|
+
|
|
339
|
+
Neeraj Singh
|
package/package.json
CHANGED