@@ -181,16 +181,22 @@ function OnMountExample() {
181
181
182
182
## A Portal Component inside a Presentation Modal screen
183
183
184
- 1 . Use the ` useModalPortalRoot ` hook in the screen with the presentation of ` modal ` .
185
- 2 . Adjust the bottom content insets to make sure the content is not hidden by the bottom safe area.
186
- 3 . Wrap the screen content with a View and pass the rootProps to it.
187
- 4 . Place the ` PortalHost ` inside the View with the rootProps as its last child.
188
- 5 . Pass the sideOffset from the ` useModalPortalRoot ` hook to the ` SelectContent ` component.
189
- 6 . Pass the ` portalHost ` name to the ` SelectContent ` component to render the content inside the ` PortalHost ` with the same name
184
+ 1 . Import the ` PortalHost ` component
185
+ 2 . Import the ` FullWindowOverlay ` component
186
+ 3 . Set a custom name for your portal and place it in a variable at the top of the file.
187
+ 4 . Create a window overlay component that adapts based on the platform (iOS or others)
188
+ 5 . In the component where you need a portal, pass the custom name
189
+ 6 . At the bottom of your content (the fragment wrapping everything), place the ` WindowOverlay ` component. Inside it, add ` PortalHost ` as a child.
190
+ 7 . Make sure the ` PortalHost ` also gets the custom portal name by passing it to the ` PortalHost ` component.
190
191
191
192
``` tsx
192
- import { PortalHost , useModalPortalRoot } from ' @rn-primitives/portal' ;
193
+ // #1
194
+ import { PortalHost } from ' @rn-primitives/portal' ;
195
+ import * as React from ' react' ;
196
+ import { Platform } from ' react-native' ;
193
197
import { useSafeAreaInsets } from ' react-native-safe-area-context' ;
198
+ // #2
199
+ import { FullWindowOverlay } from " react-native-screens"
194
200
195
201
import {
196
202
Select ,
@@ -202,25 +208,28 @@ import {
202
208
SelectValue ,
203
209
} from ' ~/components/ui/select' ;
204
210
211
+ // #3
212
+ const CUSTOM_PORTAL_HOST_NAME = ' modal-example' ;
213
+
214
+ // #4
215
+ const WindowOverlay = Platform .OS === " ios" ? FullWindowOverlay : React .Fragment
216
+
205
217
/**
206
218
* This screen is a Stack.Screen with a presentation of `modal`.
207
219
*/
208
220
export default function ModalScreen() {
209
221
const insets = useSafeAreaInsets ();
210
- const { sideOffset, ... rootProps } = useModalPortalRoot ();
211
222
const contentInsets = {
212
223
top: insets .top ,
213
- // Make sure the content is not hidden by the bottom safe area
214
- bottom: insets .bottom + Math .abs (sideOffset ),
224
+ bottom: insets .bottom ,
215
225
left: 16 ,
216
226
right: 16 ,
217
227
};
218
228
219
- // Wrap the screen content with a View and pass the rootProps to it
220
229
return (
221
- <View { ... rootProps } >
230
+ <>
222
231
<View className = ' flex-1 justify-center items-center' >
223
- <Select defaultValue = { { value: ' apple' , label: ' Apple' }} >
232
+ <Select defaultValue = { { value: ' apple' , label: ' Apple' }} >
224
233
<SelectTrigger >
225
234
<SelectValue
226
235
className = ' text-foreground text-sm native:text-lg'
@@ -229,11 +238,9 @@ export default function ModalScreen() {
229
238
</SelectTrigger >
230
239
<SelectContent
231
240
insets = { contentInsets }
232
- // Pass the sideOffset from the useModalPortalRoot hook
233
- sideOffset = { sideOffset }
234
241
className = ' w-full'
235
- // Pass the portalHost name from below to the SelectContent
236
- portalHost = ' modal-example '
242
+ // #5
243
+ portalHost = { CUSTOM_PORTAL_HOST_NAME }
237
244
>
238
245
<SelectGroup >
239
246
<SelectLabel >Fruits</SelectLabel >
@@ -256,9 +263,12 @@ export default function ModalScreen() {
256
263
</SelectContent >
257
264
</Select >
258
265
</View >
259
- { /* Place the Postal Host inside the View with the rootProps */ }
260
- <PortalHost name = ' modal-example' />
261
- </View >
266
+ { /* #6 */ }
267
+ <WindowOverlay >
268
+ { /* #7 */ }
269
+ <PortalHost name = { CUSTOM_PORTAL_HOST_NAME } />
270
+ </WindowOverlay >
271
+ </>
262
272
)
263
273
}
264
274
```
0 commit comments