Skip to content

Commit 6b43bd1

Browse files
authored
docs: update modal docs
1 parent 26ff0bf commit 6b43bd1

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

docs/modal-usage.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,7 @@ Under the hood, this `ref` is used when you imperatively call `Toast.show()` or
2525

2626
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.
2727

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).
5629

5730
```diff
5831
// App.jsx
@@ -75,3 +48,26 @@ export function App(props) {
7548
```
7649

7750
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. */}
69+
<Toast />
70+
</Modal>
71+
</NativeStackNavigator.Screen>
72+
</>
73+
```

0 commit comments

Comments
 (0)