rn-toastify 1.0.0 → 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.
- package/README.MD +249 -5
- package/index.js +3 -1
- package/package.json +12 -2
package/README.MD
CHANGED
|
@@ -19,11 +19,255 @@ Animated toast message component for React Native.
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Installation
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
```bash
|
|
25
|
+
npm install rn-toastify
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
- [API](https://github.com/muku534/react-native-toast)
|
|
28
|
-
- [Create custom layouts](https://github.com/muku534/react-native-toast)
|
|
30
|
+
To integrate the toast notifications into your application, follow these steps:
|
|
29
31
|
|
|
32
|
+
- Import and Setup
|
|
33
|
+
|
|
34
|
+
Start by importing the necessary components and hooks from the library:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import useToast from 'rn-toastify';
|
|
38
|
+
import ToastContainer from 'rn-toastify';
|
|
39
|
+
|
|
40
|
+
const AppContent = () => {
|
|
41
|
+
// Toast functions here
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<View style={styles.container}>
|
|
45
|
+
{/* Buttons to trigger toasts */}
|
|
46
|
+
<ToastContainer />
|
|
47
|
+
</View>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default AppContent;
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- Implementing Toasts
|
|
56
|
+
|
|
57
|
+
The useToast hook provides access to different types of toasts. Below are examples of how to implement each toast type:
|
|
58
|
+
|
|
59
|
+
- Success Toast
|
|
60
|
+
```javascript
|
|
61
|
+
import useToast from 'rn-toastify';
|
|
62
|
+
|
|
63
|
+
const { success } = useToast();
|
|
64
|
+
|
|
65
|
+
const handleSuccessToast = () => {
|
|
66
|
+
success('Operation was successful!', { duration: 1500, position: 'top' });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
- Error Toast
|
|
72
|
+
```javascript
|
|
73
|
+
import useToast from 'rn-toastify';
|
|
74
|
+
|
|
75
|
+
const { error } = useToast();
|
|
76
|
+
|
|
77
|
+
const handleErrorToast = () => {
|
|
78
|
+
error('Something went wrong!', { duration: 1500, position: 'top' });
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- Promise Toast
|
|
85
|
+
```javascript
|
|
86
|
+
import useToast from 'rn-toastify';
|
|
87
|
+
|
|
88
|
+
const { promise } = useToast();
|
|
89
|
+
|
|
90
|
+
const handlePromiseToast = () => {
|
|
91
|
+
const myPromise = new Promise((resolve, reject) => {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
resolve();
|
|
94
|
+
// reject();
|
|
95
|
+
}, 1500);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
promise(myPromise, {
|
|
99
|
+
loading: 'Loading...',
|
|
100
|
+
success: 'Promise resolved!',
|
|
101
|
+
error: 'Promise rejected!',
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- Custom Toast
|
|
109
|
+
```javascript
|
|
110
|
+
import React from 'react';
|
|
111
|
+
import { View, Text, Image, StyleSheet } from 'react-native';
|
|
112
|
+
import useToast from 'rn-toastify';
|
|
113
|
+
|
|
114
|
+
const { custom } = useToast();
|
|
115
|
+
|
|
116
|
+
const handleCustomToast = () => {
|
|
117
|
+
custom(
|
|
118
|
+
<View style={styles.customContent}>
|
|
119
|
+
<Image
|
|
120
|
+
style={styles.image}
|
|
121
|
+
source={{
|
|
122
|
+
uri: 'https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixqx=6GHAjsWpt9&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2.2&w=160&h=160&q=80',
|
|
123
|
+
}}
|
|
124
|
+
/>
|
|
125
|
+
<View style={styles.textContainer}>
|
|
126
|
+
<Text style={styles.customText}>Emilia Gates</Text>
|
|
127
|
+
<Text style={styles.customSubText}>Sure! 8:30pm works great!</Text>
|
|
128
|
+
</View>
|
|
129
|
+
</View>,
|
|
130
|
+
{ duration: 1500, position: 'top' }
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const styles = StyleSheet.create({
|
|
135
|
+
customContent: {
|
|
136
|
+
flexDirection: 'row',
|
|
137
|
+
alignItems: 'center',
|
|
138
|
+
},
|
|
139
|
+
image: {
|
|
140
|
+
width: 50,
|
|
141
|
+
height: 50,
|
|
142
|
+
borderRadius: 25,
|
|
143
|
+
},
|
|
144
|
+
textContainer: {
|
|
145
|
+
marginLeft: 10,
|
|
146
|
+
},
|
|
147
|
+
customText: {
|
|
148
|
+
fontWeight: 'bold',
|
|
149
|
+
},
|
|
150
|
+
customSubText: {
|
|
151
|
+
color: 'gray',
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
- Emoji Toast
|
|
158
|
+
```javascript
|
|
159
|
+
import useToast from 'rn-toastify';
|
|
160
|
+
|
|
161
|
+
const { emoji } = useToast();
|
|
162
|
+
|
|
163
|
+
const handleEmojiToast = () => {
|
|
164
|
+
emoji('Great job!', '👍', { duration: 1500, position: 'top' });
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- Full Example
|
|
170
|
+
|
|
171
|
+
Here's a complete example to demonstrate how all the toast types can be implemented within a single component:
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
import React from 'react';
|
|
175
|
+
import { StyleSheet, View, Button } from 'react-native';
|
|
176
|
+
import useToast from 'rn-toastify';
|
|
177
|
+
import ToastContainer from 'rn-toastify';
|
|
178
|
+
|
|
179
|
+
const AppContent = () => {
|
|
180
|
+
const { success, error, promise, custom, emoji } = useToast();
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<View style={styles.container}>
|
|
184
|
+
<Button title="Show Success Toast" onPress={() => success('Operation was successful!', { duration: 1500, position: 'top' })} />
|
|
185
|
+
<Button title="Show Error Toast" onPress={() => error('Something went wrong!', { duration: 1500, position: 'top' })} />
|
|
186
|
+
<Button title="Show Promise Toast" onPress={() => {
|
|
187
|
+
const myPromise = new Promise((resolve) => setTimeout(resolve, 1500));
|
|
188
|
+
promise(myPromise, { loading: 'Loading...', success: 'Promise resolved!', error: 'Promise rejected!' });
|
|
189
|
+
}} />
|
|
190
|
+
<Button title="Show Custom Toast" onPress={() => custom(
|
|
191
|
+
<View style={styles.customContent}>
|
|
192
|
+
<Text>Custom Toast Content</Text>
|
|
193
|
+
</View>,
|
|
194
|
+
{ duration: 1500, position: 'top' }
|
|
195
|
+
)} />
|
|
196
|
+
<Button title="Show Emoji Toast" onPress={() => emoji('Great job!', '👍', { duration: 1500, position: 'top' })} />
|
|
197
|
+
<ToastContainer />
|
|
198
|
+
</View>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const styles = StyleSheet.create({
|
|
203
|
+
container: {
|
|
204
|
+
flex: 1,
|
|
205
|
+
justifyContent: 'center',
|
|
206
|
+
alignItems: 'center',
|
|
207
|
+
},
|
|
208
|
+
customContent: {
|
|
209
|
+
padding: 10,
|
|
210
|
+
backgroundColor: '#fff',
|
|
211
|
+
borderRadius: 5,
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
export default AppContent;
|
|
216
|
+
```
|
|
217
|
+
This example integrates multiple toast types and demonstrates how to trigger each one. It also includes the necessary ToastContainer to display the toasts.
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## API Reference
|
|
221
|
+
|
|
222
|
+
#### useToast Hook Methods
|
|
223
|
+
All toast methods accept the following parameters:
|
|
224
|
+
|
|
225
|
+
| Parameter | Type | Description |
|
|
226
|
+
| :-------- | :------- | :------------------------- |
|
|
227
|
+
| `message` | `string` | **Required**. The message to display in the toast. |
|
|
228
|
+
| `options` | `object` | **Optional**. Configuration options for the toast (e.g., duration, position). |
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
- Methods
|
|
232
|
+
|
|
233
|
+
- success : Displays a success toast.
|
|
234
|
+
|
|
235
|
+
- error : Displays an error toast.
|
|
236
|
+
|
|
237
|
+
- promise : Handles a promise and displays loading, success, and error toasts based on the promise's state.
|
|
238
|
+
|
|
239
|
+
Additional options for promise method:
|
|
240
|
+
| Option | Type | Description |
|
|
241
|
+
| :-------- | :------- | :------------------------- |
|
|
242
|
+
| `loading` | `string` | The message to display in the toast. |
|
|
243
|
+
| `success` | `string` | Message to display if the promise resolves. |
|
|
244
|
+
| `error` | `string` | Message to display if the promise is rejected. |
|
|
245
|
+
|
|
246
|
+
- custom
|
|
247
|
+
|
|
248
|
+
Displays a custom toast with your own content.
|
|
249
|
+
|
|
250
|
+
| Parameter | Type | Description |
|
|
251
|
+
| :-------- | :------- | :------------------------- |
|
|
252
|
+
| `content` | `element` | **Required**. React element to render in the toast. |
|
|
253
|
+
|
|
254
|
+
- emoji
|
|
255
|
+
|
|
256
|
+
Displays a custom toast with your own content.
|
|
257
|
+
|
|
258
|
+
| Parameter | Type | Description |
|
|
259
|
+
| :-------- | :------- | :------------------------- |
|
|
260
|
+
| `emoji` | `string` | **Required**. The emoji to display alongside the message. |
|
|
261
|
+
|
|
262
|
+
- options
|
|
263
|
+
|
|
264
|
+
All toast methods accept an options object for configuration:
|
|
265
|
+
|
|
266
|
+
| Option | Type | Description |
|
|
267
|
+
| :-------- | :------- | :------------------------- |
|
|
268
|
+
| `duration` | `number` |**Optional**. Duration in milliseconds for which the toast is visible. |
|
|
269
|
+
| `position` | `string` | **Optional**. Position of the toast on the screen (top, bottom, center). |
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
package/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { default as toast } from './src/Toast';
|
|
2
|
+
export { default as useToast } from './src/hooks/useToast';
|
|
3
|
+
export { default as ToastContainer } from './src/context/ToastContainer';
|
|
2
4
|
export { SuccessToast } from './src/components/SuccessToast';
|
|
3
5
|
export { CustomeToast } from './src/components/CustomeToast';
|
|
4
6
|
export { EmojiToast } from './src/components/EmojiToast';
|
package/package.json
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-toastify",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "1.0.2",
|
|
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
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/muku534/react-native-toast"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/muku534/react-native-toast#readme",
|
|
6
11
|
"scripts": {
|
|
7
12
|
"test": "jest"
|
|
8
13
|
},
|
|
9
14
|
"keywords": [
|
|
10
15
|
"react-native",
|
|
11
16
|
"toast",
|
|
17
|
+
"react-native-toastify",
|
|
18
|
+
"react-native-toast",
|
|
19
|
+
"react-native-toast-message",
|
|
20
|
+
"rn-toastify",
|
|
21
|
+
"alert",
|
|
12
22
|
"notification",
|
|
13
23
|
"library"
|
|
14
24
|
],
|