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: docs/modal-usage.md
+24-28Lines changed: 24 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,34 +25,7 @@ Under the hood, this `ref` is used when you imperatively call `Toast.show()` or
25
25
26
26
When you have a [Modal](https://reactnative.dev/docs/modal), things get different. This `Modal` component is [_above_ React's root `View`](https://stackoverflow.com/questions/39766350/bring-view-on-top-of-modal-using-zindex-style-with-react-native), so the only way to show something _on top of the modal_ is to render it inside the `Modal` itself.
27
27
28
-
This means **you need a new instance** of `<Toast />` rendered inside your `Modal`.
29
-
30
-
> Same behavior when using [react-native-modal](https://github.com/react-native-modal/react-native-modal) or a [NativeStackNavigator](https://reactnavigation.org/docs/native-stack-navigator#presentation) with `presentation: 'modal'`
31
-
32
-
The `ref` will still be tracked automatically. Whichever `<Toast />` instance last had its `ref` set will be used when showing/hiding.
33
-
34
-
```js
35
-
<>
36
-
37
-
{** This `Toast` will show when neither the native stack screen nor `Modal` are presented. *}
38
-
<Toast />
39
-
40
-
<NativeStackNavigator.Screen>
41
-
42
-
{** This `Toast` will show when the `NativeStackNavigator.Screen` is visible, but the `Modal` is NOT visible. *}
43
-
<Toast />
44
-
45
-
<Modal>
46
-
47
-
{** This `Toast` will show when both the `NativeStackNavigator.Screen` and the `Modal` are visible. *}
48
-
<Toast />
49
-
50
-
</Modal>
51
-
</NativeStackNavigator.Screen>
52
-
</>
53
-
```
54
-
55
-
So, when you have a `Modal`, the implementation looks like this:
28
+
This means **you need a new instance** of `<Toast />` rendered inside your `Modal` (as well as keeping the existing `<Toast />` instance outside, in your App's entry point).
56
29
57
30
```diff
58
31
// App.jsx
@@ -75,3 +48,26 @@ export function App(props) {
75
48
```
76
49
77
50
Everything else works as usual; you can show and hide Toasts using the imperative API: `Toast.show()` or `Toast.hide()`. When the `Modal` is visible, the `ref` from inside the `Modal` will be used, otherwise the one outside.
51
+
52
+
> The `ref` is tracked automatically; whichever `<Toast />` instance last had its `ref` set will be used when showing/hiding.
53
+
54
+
### Notes regarding `react-native-modal` or `NativeStackNavigator`
55
+
56
+
The same requirements as above apply when using [react-native-modal](https://github.com/react-native-modal/react-native-modal) or a [NativeStackNavigator](https://reactnavigation.org/docs/native-stack-navigator#presentation) with `presentation: 'modal'`:
57
+
58
+
```js
59
+
<>
60
+
{/* This `Toast` will show when neither the native stack screen nor `Modal` are presented */}
61
+
<Toast />
62
+
63
+
<NativeStackNavigator.Screen>
64
+
{/* This `Toast` will show when the `NativeStackNavigator.Screen` is visible, but the `Modal` is NOT visible. */}
65
+
<Toast />
66
+
67
+
<Modal>
68
+
{/* This `Toast` will show when both the `NativeStackNavigator.Screen` and the `Modal` are visible. */}
0 commit comments