react-native-toast-signal 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/LICENSE +20 -0
- package/README.md +353 -0
- package/lib/module/components/signal-item.js +482 -0
- package/lib/module/components/signal-item.js.map +1 -0
- package/lib/module/constants.js +62 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/core/store.js +158 -0
- package/lib/module/core/store.js.map +1 -0
- package/lib/module/hooks/useSignal.js +71 -0
- package/lib/module/hooks/useSignal.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/provider/signal-provider.js +72 -0
- package/lib/module/provider/signal-provider.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/signal-item.d.ts +7 -0
- package/lib/typescript/src/components/signal-item.d.ts.map +1 -0
- package/lib/typescript/src/constants.d.ts +12 -0
- package/lib/typescript/src/constants.d.ts.map +1 -0
- package/lib/typescript/src/core/store.d.ts +48 -0
- package/lib/typescript/src/core/store.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useSignal.d.ts +46 -0
- package/lib/typescript/src/hooks/useSignal.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/provider/signal-provider.d.ts +7 -0
- package/lib/typescript/src/provider/signal-provider.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +73 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/package.json +174 -0
- package/src/components/signal-item.tsx +548 -0
- package/src/constants.ts +62 -0
- package/src/core/store.ts +171 -0
- package/src/hooks/useSignal.ts +116 -0
- package/src/index.tsx +3 -0
- package/src/provider/signal-provider.tsx +89 -0
- package/src/types.ts +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yusfuu
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./assets/banner.svg" alt="react-native-toast-signal banner" width="100%"/>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/react-native-toast-signal?style=flat-square&color=22c55e&labelColor=0d0d1a&label=npm" alt="npm version"/>
|
|
7
|
+
<img src="https://img.shields.io/npm/dm/react-native-toast-signal?style=flat-square&color=3b82f6&labelColor=0d0d1a" alt="downloads"/>
|
|
8
|
+
<img src="https://img.shields.io/badge/Reanimated-v4-8b5cf6?style=flat-square&labelColor=0d0d1a" alt="reanimated v4"/>
|
|
9
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-3b82f6?style=flat-square&labelColor=0d0d1a" alt="typescript"/>
|
|
10
|
+
<img src="https://img.shields.io/badge/license-MIT-f59e0b?style=flat-square&labelColor=0d0d1a" alt="license"/>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
**react-native-toast-signal** is a smooth, stackable, fully typed toast notification library for React Native — built on [Reanimated v4](https://docs.swmansion.com/react-native-reanimated/) and [Gesture Handler v2](https://docs.swmansion.com/react-native-gesture-handler/).
|
|
16
|
+
|
|
17
|
+
- 🎞 **Fluid animations** — slide-in/out, stacked scale + opacity, progress bar
|
|
18
|
+
- 👆 **Swipe-to-dismiss** with flick velocity detection
|
|
19
|
+
- 📚 **Queue-aware stacking** — beyond `maxVisible` toasts are mounted but hidden, animating in seamlessly when a slot opens
|
|
20
|
+
- 🔔 **6 types** — `success` `error` `warning` `info` `loading` `custom`
|
|
21
|
+
- ⚡ **Loading toasts** — update in-place to success/error with a pulse animation
|
|
22
|
+
- 🎯 **Action buttons** — optional CTA rendered inside the toast
|
|
23
|
+
- ♿ **Accessible** — `accessibilityRole`, `accessibilityLiveRegion`, and `AccessibilityInfo` announcements
|
|
24
|
+
- 📍 **Position** — `top` or `bottom` per toast, with safe area clamping
|
|
25
|
+
- 🎨 **Fully themeable** per type
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npm install react-native-toast-signal
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Peer dependencies
|
|
36
|
+
|
|
37
|
+
Install if not already in your project:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npm install react-native-reanimated react-native-worklets react-native-gesture-handler react-native-safe-area-context
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
> **Reanimated v4 requires the New Architecture.** Make sure it's enabled in your project.
|
|
44
|
+
|
|
45
|
+
### babel.config.js
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
module.exports = {
|
|
49
|
+
presets: ['module:@react-native/babel-preset'],
|
|
50
|
+
plugins: [
|
|
51
|
+
'react-native-worklets/plugin', // required for Reanimated v4
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Setup
|
|
57
|
+
|
|
58
|
+
Wrap your app root with the required providers **in this exact order**:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
62
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
63
|
+
import { SignalProvider } from 'react-native-toast-signal';
|
|
64
|
+
|
|
65
|
+
export default function App() {
|
|
66
|
+
return (
|
|
67
|
+
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
68
|
+
<SafeAreaProvider>
|
|
69
|
+
<SignalProvider>
|
|
70
|
+
<YourApp />
|
|
71
|
+
</SignalProvider>
|
|
72
|
+
</SafeAreaProvider>
|
|
73
|
+
</GestureHandlerRootView>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## Usage
|
|
81
|
+
|
|
82
|
+
### Imperative API
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { Signal } from 'react-native-toast-signal';
|
|
86
|
+
|
|
87
|
+
// Simple
|
|
88
|
+
Signal.show({ description: 'Profile saved.' });
|
|
89
|
+
|
|
90
|
+
// With title and type
|
|
91
|
+
Signal.show({
|
|
92
|
+
type: 'success',
|
|
93
|
+
title: 'Changes saved',
|
|
94
|
+
description: 'Your profile has been updated successfully.',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Error
|
|
98
|
+
Signal.show({
|
|
99
|
+
type: 'error',
|
|
100
|
+
title: 'Upload failed',
|
|
101
|
+
description: 'Check your connection and try again.',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// Warning
|
|
105
|
+
Signal.show({
|
|
106
|
+
type: 'warning',
|
|
107
|
+
description: 'Your session expires in 5 minutes.',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Info — bottom position
|
|
111
|
+
Signal.show({
|
|
112
|
+
type: 'info',
|
|
113
|
+
description: 'New update available.',
|
|
114
|
+
position: 'bottom',
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Dismiss a specific toast
|
|
118
|
+
Signal.hide('my-toast-id');
|
|
119
|
+
|
|
120
|
+
// Dismiss all
|
|
121
|
+
Signal.clear();
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Hook API
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { useSignal } from 'react-native-toast-signal';
|
|
128
|
+
|
|
129
|
+
function MyComponent() {
|
|
130
|
+
const { show, hide, clear } = useSignal();
|
|
131
|
+
|
|
132
|
+
return (
|
|
133
|
+
<Button
|
|
134
|
+
title="Save"
|
|
135
|
+
onPress={() =>
|
|
136
|
+
show({
|
|
137
|
+
type: 'success',
|
|
138
|
+
title: 'Saved',
|
|
139
|
+
description: 'All changes have been saved.',
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
/>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Loading Toasts
|
|
150
|
+
|
|
151
|
+
Show a loading toast, then update it in-place to success or error — no flash, just a smooth pulse transition:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
Signal.show({
|
|
155
|
+
id: 'upload',
|
|
156
|
+
type: 'loading',
|
|
157
|
+
description: 'Uploading file…',
|
|
158
|
+
autoHide: false, // stays until you call update
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
await uploadFile();
|
|
163
|
+
Signal.update('upload', {
|
|
164
|
+
type: 'success',
|
|
165
|
+
description: 'File uploaded!',
|
|
166
|
+
autoHide: true,
|
|
167
|
+
});
|
|
168
|
+
} catch {
|
|
169
|
+
Signal.update('upload', {
|
|
170
|
+
type: 'error',
|
|
171
|
+
description: 'Upload failed. Try again.',
|
|
172
|
+
autoHide: true,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Action Buttons
|
|
180
|
+
|
|
181
|
+
Render a CTA inside the toast. The `onPress` callback receives a `dismiss` function so you control whether the toast closes:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
Signal.show({
|
|
185
|
+
type: 'warning',
|
|
186
|
+
title: 'Unsaved changes',
|
|
187
|
+
description: 'You have unsaved changes. Discard them?',
|
|
188
|
+
autoHide: false,
|
|
189
|
+
action: {
|
|
190
|
+
label: 'Discard',
|
|
191
|
+
onPress: (dismiss) => {
|
|
192
|
+
discardChanges();
|
|
193
|
+
dismiss();
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## onPress
|
|
202
|
+
|
|
203
|
+
The `onPress` callback also receives a `dismiss` function:
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
Signal.show({
|
|
207
|
+
type: 'info',
|
|
208
|
+
description: 'New message from Alex.',
|
|
209
|
+
onPress: (dismiss) => {
|
|
210
|
+
navigation.navigate('Chat');
|
|
211
|
+
dismiss();
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Callbacks
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
Signal.show({
|
|
222
|
+
description: 'Processing complete.',
|
|
223
|
+
onShow: () => console.log('Toast entered'),
|
|
224
|
+
onHide: () => console.log('Toast exited'),
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
| Callback | When it fires |
|
|
229
|
+
| --------- | ------------------------------------ |
|
|
230
|
+
| `onShow` | After entry animation fully settles |
|
|
231
|
+
| `onHide` | After exit animation fully completes |
|
|
232
|
+
| `onPress` | When the toast body is tapped |
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Custom Icon
|
|
237
|
+
|
|
238
|
+
Override the default type icon with any `ReactNode`:
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { MyIcon } from './icons';
|
|
242
|
+
|
|
243
|
+
Signal.show({
|
|
244
|
+
type: 'custom',
|
|
245
|
+
description: 'Custom icon toast.',
|
|
246
|
+
icon: <MyIcon size={16} color="#a78bfa" />,
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## API Reference
|
|
253
|
+
|
|
254
|
+
### `Signal`
|
|
255
|
+
|
|
256
|
+
| Method | Description |
|
|
257
|
+
| ---------------------------- | ------------------------------- |
|
|
258
|
+
| `Signal.show(options)` | Show a new toast |
|
|
259
|
+
| `Signal.hide(id)` | Dismiss a specific toast by ID |
|
|
260
|
+
| `Signal.update(id, options)` | Update a visible toast in-place |
|
|
261
|
+
| `Signal.clear()` | Dismiss all toasts |
|
|
262
|
+
|
|
263
|
+
### `SignalOptions`
|
|
264
|
+
|
|
265
|
+
| Prop | Type | Default | Description |
|
|
266
|
+
| ---------------- | ------------------------------- | -------- | ------------------------------------------------------------------------------ |
|
|
267
|
+
| `description` | `string` | — | **Required.** Body text |
|
|
268
|
+
| `title` | `string` | — | Optional bold heading |
|
|
269
|
+
| `id` | `string` | auto | Stable ID for deduplication / update / hide |
|
|
270
|
+
| `type` | `SignalType` | `'info'` | Visual style: `success` `error` `warning` `info` `loading` `custom` |
|
|
271
|
+
| `position` | `'top' \| 'bottom'` | `'top'` | Screen position |
|
|
272
|
+
| `duration` | `number` | `3000` | Auto-dismiss delay in ms |
|
|
273
|
+
| `autoHide` | `boolean` | `true` | Disable to keep toast until manually dismissed (`loading` defaults to `false`) |
|
|
274
|
+
| `swipeToDismiss` | `boolean` | `true` | Enable or disable swipe gesture |
|
|
275
|
+
| `action` | `SignalAction` | — | Optional CTA button with label and onPress |
|
|
276
|
+
| `icon` | `ReactNode` | — | Custom icon — replaces the default type icon |
|
|
277
|
+
| `onShow` | `() => void` | — | Called after entry animation settles |
|
|
278
|
+
| `onHide` | `() => void` | — | Called after exit animation completes |
|
|
279
|
+
| `onPress` | `(dismiss: () => void) => void` | — | Called when toast body is tapped |
|
|
280
|
+
|
|
281
|
+
### `SignalProvider` props
|
|
282
|
+
|
|
283
|
+
| Prop | Type | Default | Description |
|
|
284
|
+
| ----------------- | -------- | ------- | ------------------------------------- |
|
|
285
|
+
| `maxVisible` | `number` | `3` | Max toasts shown in the stack at once |
|
|
286
|
+
| `defaultDuration` | `number` | `3000` | Global default auto-dismiss duration |
|
|
287
|
+
|
|
288
|
+
```tsx
|
|
289
|
+
<SignalProvider maxVisible={5} defaultDuration={4000}>
|
|
290
|
+
<App />
|
|
291
|
+
</SignalProvider>
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### `SignalAction`
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
interface SignalAction {
|
|
298
|
+
label: string;
|
|
299
|
+
onPress: (dismiss: () => void) => void;
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## Theming
|
|
306
|
+
|
|
307
|
+
Pass a partial theme to `SignalProvider` to override colors per type:
|
|
308
|
+
|
|
309
|
+
```tsx
|
|
310
|
+
<SignalProvider
|
|
311
|
+
theme={{
|
|
312
|
+
success: {
|
|
313
|
+
background: '#052e16',
|
|
314
|
+
border: '#22c55e60',
|
|
315
|
+
titleColor: '#ffffff',
|
|
316
|
+
descriptionColor: '#bbf7d0',
|
|
317
|
+
iconColor: '#4ade80',
|
|
318
|
+
},
|
|
319
|
+
}}
|
|
320
|
+
>
|
|
321
|
+
<App />
|
|
322
|
+
</SignalProvider>
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Each type accepts a `SignalTypeTheme`:
|
|
326
|
+
|
|
327
|
+
```ts
|
|
328
|
+
interface SignalTypeTheme {
|
|
329
|
+
background: string;
|
|
330
|
+
border: string;
|
|
331
|
+
titleColor: string;
|
|
332
|
+
descriptionColor: string;
|
|
333
|
+
iconColor: string;
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Requirements
|
|
340
|
+
|
|
341
|
+
| Package | Version |
|
|
342
|
+
| -------------------------------- | ---------- |
|
|
343
|
+
| `react-native` | `>= 0.74` |
|
|
344
|
+
| `react-native-reanimated` | `>= 4.0.0` |
|
|
345
|
+
| `react-native-worklets` | `>= 0.4.0` |
|
|
346
|
+
| `react-native-gesture-handler` | `>= 2.0.0` |
|
|
347
|
+
| `react-native-safe-area-context` | `>= 4.0.0` |
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## License
|
|
352
|
+
|
|
353
|
+
MIT © 2025
|