Skip to content

Commit 30e92c6

Browse files
committed
fix(docs): remove deprecated useModalPortalRoot from common patterns
1 parent 329dd99 commit 30e92c6

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

apps/docs/src/content/docs/getting-started/common-patterns.mdx

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,22 @@ function OnMountExample() {
181181

182182
## A Portal Component inside a Presentation Modal screen
183183

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.
190191

191192
```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';
193197
import { useSafeAreaInsets } from 'react-native-safe-area-context';
198+
// #2
199+
import { FullWindowOverlay } from "react-native-screens"
194200

195201
import {
196202
Select,
@@ -202,25 +208,28 @@ import {
202208
SelectValue,
203209
} from '~/components/ui/select';
204210

211+
// #3
212+
const CUSTOM_PORTAL_HOST_NAME = 'modal-example';
213+
214+
// #4
215+
const WindowOverlay = Platform.OS === "ios" ? FullWindowOverlay : React.Fragment
216+
205217
/**
206218
* This screen is a Stack.Screen with a presentation of `modal`.
207219
*/
208220
export default function ModalScreen() {
209221
const insets = useSafeAreaInsets();
210-
const { sideOffset, ...rootProps } = useModalPortalRoot();
211222
const contentInsets = {
212223
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,
215225
left: 16,
216226
right: 16,
217227
};
218228

219-
// Wrap the screen content with a View and pass the rootProps to it
220229
return (
221-
<View {...rootProps}>
230+
<>
222231
<View className='flex-1 justify-center items-center'>
223-
<Select defaultValue={{ value: 'apple', label: 'Apple' }}>
232+
<Select defaultValue={{ value: 'apple', label: 'Apple' }}>
224233
<SelectTrigger>
225234
<SelectValue
226235
className='text-foreground text-sm native:text-lg'
@@ -229,11 +238,9 @@ export default function ModalScreen() {
229238
</SelectTrigger>
230239
<SelectContent
231240
insets={contentInsets}
232-
// Pass the sideOffset from the useModalPortalRoot hook
233-
sideOffset={sideOffset}
234241
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}
237244
>
238245
<SelectGroup>
239246
<SelectLabel>Fruits</SelectLabel>
@@ -256,9 +263,12 @@ export default function ModalScreen() {
256263
</SelectContent>
257264
</Select>
258265
</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+
</>
262272
)
263273
}
264274
```

0 commit comments

Comments
 (0)