react-native-modern-toast 0.1.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.
- package/README.md +296 -0
- package/lib/Toast.d.ts +6 -0
- package/lib/Toast.js +104 -0
- package/lib/ToastProvider.d.ts +6 -0
- package/lib/ToastProvider.js +131 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +10 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +7 -0
- package/lib/types.d.ts +16 -0
- package/lib/types.js +2 -0
- package/lib/variants/ErrorToast.d.ts +2 -0
- package/lib/variants/ErrorToast.js +7 -0
- package/lib/variants/InfoToast.d.ts +2 -0
- package/lib/variants/InfoToast.js +7 -0
- package/lib/variants/ModernToast.d.ts +2 -0
- package/lib/variants/ModernToast.js +7 -0
- package/lib/variants/SuccessToast.d.ts +2 -0
- package/lib/variants/SuccessToast.js +7 -0
- package/lib/variants/WarningToast.d.ts +2 -0
- package/lib/variants/WarningToast.js +7 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
# react-native-flex-toast
|
|
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.
|
|
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
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install react-native-flex-toast
|
|
19
|
+
# or
|
|
20
|
+
yarn add react-native-flex-toast
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### 1. Wrap Your App with ToastProvider
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import React from 'react';
|
|
29
|
+
import { View } from 'react-native';
|
|
30
|
+
import { ToastProvider } from 'react-native-flex-toast';
|
|
31
|
+
|
|
32
|
+
export default function App() {
|
|
33
|
+
return (
|
|
34
|
+
<ToastProvider>
|
|
35
|
+
<YourAppContent />
|
|
36
|
+
</ToastProvider>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Use the Hook to Show Toasts
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { useToast } from 'react-native-flex-toast';
|
|
45
|
+
import { View, Button } from 'react-native';
|
|
46
|
+
|
|
47
|
+
export function MyComponent() {
|
|
48
|
+
const { showToast } = useToast();
|
|
49
|
+
|
|
50
|
+
const handleSuccess = () => {
|
|
51
|
+
showToast({
|
|
52
|
+
message: 'Action completed successfully!',
|
|
53
|
+
variant: 'success',
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<View>
|
|
59
|
+
<Button title="Show Toast" onPress={handleSuccess} />
|
|
60
|
+
</View>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Usage Examples
|
|
66
|
+
|
|
67
|
+
### Basic Toast
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
const { showToast } = useToast();
|
|
71
|
+
|
|
72
|
+
showToast({
|
|
73
|
+
message: 'Hello World!',
|
|
74
|
+
variant: 'info',
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Toast with Image Icon (URI)
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
showToast({
|
|
82
|
+
message: 'Profile saved',
|
|
83
|
+
variant: 'success',
|
|
84
|
+
iconSource: { uri: 'https://example.com/check.png' },
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Toast with Local Image
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
showToast({
|
|
92
|
+
message: 'Download complete',
|
|
93
|
+
variant: 'success',
|
|
94
|
+
iconSource: require('./assets/download-icon.png'),
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Toast with Custom React Node Icon
|
|
99
|
+
|
|
100
|
+
```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
|
+
),
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Toast with Custom Duration
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
showToast({
|
|
119
|
+
message: 'This will stay for 5 seconds',
|
|
120
|
+
variant: 'warning',
|
|
121
|
+
duration: 5000, // 5000ms
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Toast with Custom Position
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
showToast({
|
|
129
|
+
message: 'Bottom positioned toast',
|
|
130
|
+
variant: 'error',
|
|
131
|
+
position: 'bottom', // or 'top' (default)
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Toast with Custom Colors & Styles
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
showToast({
|
|
139
|
+
message: 'Custom styled toast',
|
|
140
|
+
backgroundColor: '#FF6B6B',
|
|
141
|
+
height: 70,
|
|
142
|
+
iconSource: { uri: 'https://example.com/icon.png' },
|
|
143
|
+
});
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Complete Example with All Options
|
|
147
|
+
|
|
148
|
+
```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' },
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## API Reference
|
|
163
|
+
|
|
164
|
+
### ToastProvider
|
|
165
|
+
|
|
166
|
+
Wraps your app to provide toast functionality.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
<ToastProvider>
|
|
170
|
+
{children}
|
|
171
|
+
</ToastProvider>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### useToast Hook
|
|
175
|
+
|
|
176
|
+
Returns an object with the `showToast` function.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
const { showToast } = useToast();
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### showToast(options: ToastOptions)
|
|
183
|
+
|
|
184
|
+
Displays a toast notification with the provided options.
|
|
185
|
+
|
|
186
|
+
**Parameters:**
|
|
187
|
+
|
|
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 |
|
|
200
|
+
|
|
201
|
+
## Toast Variants
|
|
202
|
+
|
|
203
|
+
Each variant has a default color:
|
|
204
|
+
|
|
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` |
|
|
212
|
+
|
|
213
|
+
## Variant Components
|
|
214
|
+
|
|
215
|
+
The package also exports pre-styled variant components:
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
import { SuccessToast, ErrorToast, WarningToast, InfoToast, ModernToast } from 'react-native-flex-toast';
|
|
219
|
+
|
|
220
|
+
// These are pre-configured with their respective colors
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## TypeScript Support
|
|
224
|
+
|
|
225
|
+
Full TypeScript support with exported types:
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import type { ToastOptions, ToastProps, ToastVariant } from 'react-native-flex-toast';
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Project Structure
|
|
232
|
+
|
|
233
|
+
```
|
|
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
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Key Features Explained
|
|
250
|
+
|
|
251
|
+
### Icon/Image Props
|
|
252
|
+
|
|
253
|
+
The component supports two ways to add icons:
|
|
254
|
+
|
|
255
|
+
1. **`iconSource`** - For image assets (most common)
|
|
256
|
+
```tsx
|
|
257
|
+
iconSource: { uri: 'https://...' } // Web image
|
|
258
|
+
iconSource: require('./icon.png') // Local image
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
2. **`icon`** - For custom React nodes
|
|
262
|
+
```tsx
|
|
263
|
+
icon: <Text style={{ fontSize: 20 }}>✓</Text>
|
|
264
|
+
icon: <Image source={...} />
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Priority:** If both `icon` and `iconSource` are provided, `icon` takes precedence.
|
|
268
|
+
|
|
269
|
+
### Auto-dismiss
|
|
270
|
+
|
|
271
|
+
Toasts automatically dismiss after the specified `duration` (default 3000ms). Showing a new toast while one is active will replace and reset the timer.
|
|
272
|
+
|
|
273
|
+
### Context Error Handling
|
|
274
|
+
|
|
275
|
+
If you call `useToast()` outside of `ToastProvider`, a helpful error is thrown:
|
|
276
|
+
```
|
|
277
|
+
"useToast must be used within a ToastProvider"
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## Best Practices
|
|
281
|
+
|
|
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
|
|
288
|
+
|
|
289
|
+
## Requirements
|
|
290
|
+
|
|
291
|
+
- React Native 0.72+
|
|
292
|
+
- React 16.8+ (hooks)
|
|
293
|
+
|
|
294
|
+
## License
|
|
295
|
+
|
|
296
|
+
ISC
|
package/lib/Toast.d.ts
ADDED
package/lib/Toast.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const Toast = ({ title, message, variant = 'info', backgroundColor, height = 70, icon, }) => {
|
|
10
|
+
const iconSource = typeof icon === 'string'
|
|
11
|
+
? { uri: icon }
|
|
12
|
+
: icon;
|
|
13
|
+
return (react_1.default.createElement(react_native_1.View, { style: [
|
|
14
|
+
styles.container,
|
|
15
|
+
{
|
|
16
|
+
height,
|
|
17
|
+
backgroundColor: backgroundColor || constants_1.COLORS[variant],
|
|
18
|
+
},
|
|
19
|
+
] },
|
|
20
|
+
iconSource ? (react_1.default.createElement(react_native_1.Image, { source: iconSource, style: styles.icon })) : null,
|
|
21
|
+
react_1.default.createElement(react_native_1.View, { style: styles.content },
|
|
22
|
+
title ? (react_1.default.createElement(react_native_1.Text, { style: styles.title }, title)) : null,
|
|
23
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.message }, message))));
|
|
24
|
+
};
|
|
25
|
+
exports.default = Toast;
|
|
26
|
+
const styles = react_native_1.StyleSheet.create({
|
|
27
|
+
container: {
|
|
28
|
+
marginHorizontal: 15,
|
|
29
|
+
borderRadius: 14,
|
|
30
|
+
flexDirection: 'row',
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
paddingHorizontal: 15,
|
|
33
|
+
elevation: 5,
|
|
34
|
+
},
|
|
35
|
+
icon: {
|
|
36
|
+
width: 32,
|
|
37
|
+
height: 32,
|
|
38
|
+
marginRight: 12,
|
|
39
|
+
resizeMode: 'contain',
|
|
40
|
+
},
|
|
41
|
+
content: {
|
|
42
|
+
flex: 1,
|
|
43
|
+
},
|
|
44
|
+
title: {
|
|
45
|
+
color: '#fff',
|
|
46
|
+
fontSize: 16,
|
|
47
|
+
fontWeight: '700',
|
|
48
|
+
},
|
|
49
|
+
message: {
|
|
50
|
+
color: '#fff',
|
|
51
|
+
marginTop: 2,
|
|
52
|
+
fontSize: 14,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
// import React from 'react';
|
|
56
|
+
// import { View, Text, StyleSheet } from 'react-native';
|
|
57
|
+
// interface ToastProps {
|
|
58
|
+
// message: string;
|
|
59
|
+
// backgroundColor?: string;
|
|
60
|
+
// height?: number;
|
|
61
|
+
// variant?: 'success' | 'error' | 'warning' | 'info' | 'modern';
|
|
62
|
+
// }
|
|
63
|
+
// const defaultColors = {
|
|
64
|
+
// success: '#22C55E',
|
|
65
|
+
// error: '#EF4444',
|
|
66
|
+
// warning: '#F59E0B',
|
|
67
|
+
// info: '#3B82F6',
|
|
68
|
+
// modern: '#111827',
|
|
69
|
+
// };
|
|
70
|
+
// const Toast = ({
|
|
71
|
+
// message,
|
|
72
|
+
// backgroundColor,
|
|
73
|
+
// height = 60,
|
|
74
|
+
// variant = 'info',
|
|
75
|
+
// }: ToastProps) => {
|
|
76
|
+
// return (
|
|
77
|
+
// <View
|
|
78
|
+
// style={[
|
|
79
|
+
// styles.container,
|
|
80
|
+
// {
|
|
81
|
+
// height,
|
|
82
|
+
// backgroundColor:
|
|
83
|
+
// backgroundColor || defaultColors[variant],
|
|
84
|
+
// },
|
|
85
|
+
// ]}
|
|
86
|
+
// >
|
|
87
|
+
// <Text style={styles.text}>{message}</Text>
|
|
88
|
+
// </View>
|
|
89
|
+
// );
|
|
90
|
+
// };
|
|
91
|
+
// export default Toast;
|
|
92
|
+
// const styles = StyleSheet.create({
|
|
93
|
+
// container: {
|
|
94
|
+
// borderRadius: 12,
|
|
95
|
+
// paddingHorizontal: 16,
|
|
96
|
+
// justifyContent: 'center',
|
|
97
|
+
// marginHorizontal: 16,
|
|
98
|
+
// },
|
|
99
|
+
// text: {
|
|
100
|
+
// color: '#fff',
|
|
101
|
+
// fontSize: 15,
|
|
102
|
+
// fontWeight: '600',
|
|
103
|
+
// },
|
|
104
|
+
// });
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.useToast = exports.ToastProvider = void 0;
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const react_native_1 = require("react-native");
|
|
42
|
+
const Toast_1 = __importDefault(require("./Toast"));
|
|
43
|
+
const ToastContext = (0, react_1.createContext)(null);
|
|
44
|
+
const ToastProvider = ({ children, }) => {
|
|
45
|
+
const [toast, setToast] = (0, react_1.useState)(null);
|
|
46
|
+
const timeoutRef = (0, react_1.useRef)(null);
|
|
47
|
+
(0, react_1.useEffect)(() => {
|
|
48
|
+
return () => {
|
|
49
|
+
if (timeoutRef.current) {
|
|
50
|
+
clearTimeout(timeoutRef.current);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
const showToast = (options) => {
|
|
55
|
+
var _a;
|
|
56
|
+
if (timeoutRef.current) {
|
|
57
|
+
clearTimeout(timeoutRef.current);
|
|
58
|
+
}
|
|
59
|
+
setToast(Object.assign(Object.assign({}, options), { variant: options.variant || options.type || 'info' }));
|
|
60
|
+
const duration = (_a = options.duration) !== null && _a !== void 0 ? _a : (options.time ? options.time * 1000 : 3000);
|
|
61
|
+
timeoutRef.current =
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
setToast(null);
|
|
64
|
+
timeoutRef.current = null;
|
|
65
|
+
}, duration);
|
|
66
|
+
};
|
|
67
|
+
const wrapperStyle = {
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
left: 0,
|
|
70
|
+
right: 0,
|
|
71
|
+
alignItems: 'center',
|
|
72
|
+
};
|
|
73
|
+
if ((toast === null || toast === void 0 ? void 0 : toast.position) === 'bottom') {
|
|
74
|
+
wrapperStyle.bottom = toast.bottomPadding || 40;
|
|
75
|
+
}
|
|
76
|
+
else if ((toast === null || toast === void 0 ? void 0 : toast.position) === 'center') {
|
|
77
|
+
wrapperStyle.top = 0;
|
|
78
|
+
wrapperStyle.bottom = 0;
|
|
79
|
+
wrapperStyle.justifyContent = 'center';
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
wrapperStyle.top = (toast === null || toast === void 0 ? void 0 : toast.topPadding) || 50;
|
|
83
|
+
}
|
|
84
|
+
return (react_1.default.createElement(ToastContext.Provider, { value: { showToast } },
|
|
85
|
+
children,
|
|
86
|
+
toast && (react_1.default.createElement(react_native_1.View, { pointerEvents: "none", style: wrapperStyle },
|
|
87
|
+
react_1.default.createElement(Toast_1.default, Object.assign({}, toast))))));
|
|
88
|
+
};
|
|
89
|
+
exports.ToastProvider = ToastProvider;
|
|
90
|
+
const useToast = () => (0, react_1.useContext)(ToastContext);
|
|
91
|
+
exports.useToast = useToast;
|
|
92
|
+
// import React, { createContext, useContext, useState } from 'react';
|
|
93
|
+
// import { View } from 'react-native';
|
|
94
|
+
// import Toast from './Toast';
|
|
95
|
+
// interface ToastOptions {
|
|
96
|
+
// message: string;
|
|
97
|
+
// position?: 'top' | 'bottom';
|
|
98
|
+
// backgroundColor?: string;
|
|
99
|
+
// height?: number;
|
|
100
|
+
// variant?: 'success' | 'error' | 'warning' | 'info' | 'modern';
|
|
101
|
+
// }
|
|
102
|
+
// const ToastContext = createContext<any>(null);
|
|
103
|
+
// export const ToastProvider = ({ children }: any) => {
|
|
104
|
+
// const [toast, setToast] = useState<any>(null);
|
|
105
|
+
// const showToast = (options: ToastOptions) => {
|
|
106
|
+
// setToast(options);
|
|
107
|
+
// setTimeout(() => {
|
|
108
|
+
// setToast(null);
|
|
109
|
+
// }, 3000);
|
|
110
|
+
// };
|
|
111
|
+
// return (
|
|
112
|
+
// <ToastContext.Provider value={{ showToast }}>
|
|
113
|
+
// {children}
|
|
114
|
+
// {toast && (
|
|
115
|
+
// <View
|
|
116
|
+
// style={{
|
|
117
|
+
// position: 'absolute',
|
|
118
|
+
// left: 0,
|
|
119
|
+
// right: 0,
|
|
120
|
+
// ...(toast.position === 'bottom'
|
|
121
|
+
// ? { bottom: 40 }
|
|
122
|
+
// : { top: 50 }),
|
|
123
|
+
// }}
|
|
124
|
+
// >
|
|
125
|
+
// <Toast {...toast} />
|
|
126
|
+
// </View>
|
|
127
|
+
// )}
|
|
128
|
+
// </ToastContext.Provider>
|
|
129
|
+
// );
|
|
130
|
+
// };
|
|
131
|
+
// export const useToast = () => useContext(ToastContext);
|
package/lib/constants.js
ADDED
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useToast = exports.ToastProvider = void 0;
|
|
4
|
+
var ToastProvider_1 = require("./ToastProvider");
|
|
5
|
+
Object.defineProperty(exports, "ToastProvider", { enumerable: true, get: function () { return ToastProvider_1.ToastProvider; } });
|
|
6
|
+
var ToastProvider_2 = require("./ToastProvider");
|
|
7
|
+
Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return ToastProvider_2.useToast; } });
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ImageSourcePropType } from 'react-native';
|
|
2
|
+
export type ToastVariant = 'success' | 'error' | 'warning' | 'info' | 'modern';
|
|
3
|
+
export interface ToastOptions {
|
|
4
|
+
title?: string;
|
|
5
|
+
message: string;
|
|
6
|
+
variant?: ToastVariant;
|
|
7
|
+
position?: 'top' | 'bottom' | 'center';
|
|
8
|
+
duration?: number;
|
|
9
|
+
time?: number;
|
|
10
|
+
backgroundColor?: string;
|
|
11
|
+
height?: number;
|
|
12
|
+
topPadding?: number;
|
|
13
|
+
bottomPadding?: number;
|
|
14
|
+
icon?: ImageSourcePropType | string;
|
|
15
|
+
type?: ToastVariant;
|
|
16
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Toast_1 = __importDefault(require("../Toast"));
|
|
7
|
+
exports.default = Toast_1.default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Toast_1 = __importDefault(require("../Toast"));
|
|
7
|
+
exports.default = Toast_1.default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Toast_1 = __importDefault(require("../Toast"));
|
|
7
|
+
exports.default = Toast_1.default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Toast_1 = __importDefault(require("../Toast"));
|
|
7
|
+
exports.default = Toast_1.default;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Toast_1 = __importDefault(require("../Toast"));
|
|
7
|
+
exports.default = Toast_1.default;
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-modern-toast",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A lightweight React Native toast provider with icon support, multiple variants, and TypeScript definitions.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"README.md",
|
|
10
|
+
"package.json"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": "*",
|
|
18
|
+
"react-native": "*"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"react-native",
|
|
22
|
+
"toast",
|
|
23
|
+
"notification",
|
|
24
|
+
"toast-provider",
|
|
25
|
+
"typescript"
|
|
26
|
+
],
|
|
27
|
+
"author": "",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/react": "^19.2.17",
|
|
31
|
+
"@types/react-native": "^0.72.8",
|
|
32
|
+
"typescript": "^6.0.3"
|
|
33
|
+
}
|
|
34
|
+
}
|