You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+45-1Lines changed: 45 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,8 @@ I know what you might be thinking (*jeez, another toast library?*). Trust me her
20
20
-**Customizable** (custom styles, dimensions, duration, and even create your own component to be used in the toast)
21
21
- Add support for **promises** <-- Really! Call `toast.promise(my_promise)` and watch react-native-toast work its magic, automatically updating the toast with a custom message on success -- or an error message on reject.
22
22
- Runs on **web**
23
+
- Support for native modals
24
+
- Callbacks for onPress, onShow, and onHide
23
25
24
26
# Getting Started
25
27
@@ -173,6 +175,49 @@ When a toast is pressed, this callback will fire, returning the toast object tha
Provide the Toasts component with a providerKey to conditionally render toasts in a component. Useful for rendering toasts in native modals.
180
+
```js
181
+
// Component in native modal
182
+
<Toasts providerKey="MODAL::1"/>
183
+
184
+
//...
185
+
// Root component
186
+
<Toasts />//has default providerKey of DEFAULT
187
+
188
+
//...
189
+
// Call toast in root modal
190
+
191
+
constid=toast("Hello from root modal") //default providerKey of DEFAULT
192
+
193
+
// Native modal becomes visible
194
+
constid=toast("Hello from native modal", {providerKey:"MODAL::1"})
195
+
//Now, toast is shown only in native modal
196
+
```
197
+
198
+
If you want to persist toasts across components (i.e. when you open/close a modal and want to keep the same toasts), your toasts should be assigned a providerKey of "PERSISTS".
199
+
200
+
```js
201
+
toast("Message...", {providerKey:"PERSISTS"})
202
+
```
203
+
204
+
Or, if you cannot do so, you can update each toast manually.
205
+
206
+
```js
207
+
const { toasts } =useToasterStore(); //Note, no provider key passed in
208
+
209
+
useEffect(() => {
210
+
toasts.forEach((t) => {
211
+
toast(t.message, {
212
+
...t,
213
+
providerKey: isModalVisible ?'MODAL::1':'DEFAULT', //Switch provider key here
214
+
});
215
+
});
216
+
}, [isModalVisible]);
217
+
```
218
+
219
+
220
+
176
221
### Example
177
222
```
178
223
<Toasts
@@ -449,4 +494,3 @@ Made with [create-react-native-library](https://github.com/callstack/react-nativ
0 commit comments