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: versioned_docs/version-7.x/upgrading-from-6.x.md
+40-2
Original file line number
Diff line number
Diff line change
@@ -336,7 +336,7 @@ The `popToTopOnBlur` option provides an alternative approach - it pops the scree
336
336
337
337
See [Bottom Tab Navigator](bottom-tab-navigator.md#poptotoponblur) and [Drawer Navigator](drawer-navigator.md#poptotoponblur) docs for usage.
338
338
339
-
It's still possible to achieve the old behavior of `unmountOnBlur` by using the useIsFocused hook in the screen:
339
+
It's still possible to achieve the old behavior of `unmountOnBlur` by using the [`useIsFocused`](use-is-focused.md) hook in the screen:
340
340
341
341
```js
342
342
constisFocused=useIsFocused();
@@ -346,7 +346,45 @@ if (!isFocused) {
346
346
}
347
347
```
348
348
349
-
This could also be combined with the new [layout props](#new-layout-props) to specify it at the screen configuration level.
349
+
This could also be combined with the new [layout props](#new-layout-props) to specify it at the screen configuration level to make the migration easier.
350
+
351
+
To achieve this, define a component that uses the `useIsFocused` hook to conditionally render its children:
352
+
353
+
```js
354
+
functionUnmountOnBlur({ children }) {
355
+
constisFocused=useIsFocused();
356
+
357
+
if (!isFocused) {
358
+
returnnull;
359
+
}
360
+
361
+
return children;
362
+
}
363
+
```
364
+
365
+
Then use the component in `layout` prop of the screen:
366
+
367
+
```diff lang=js
368
+
<Tab.Screen
369
+
name="MyScreen"
370
+
component={MyScreen}
371
+
+ layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
372
+
options={{
373
+
- unmountOnBlur: true,
374
+
}}
375
+
/>
376
+
```
377
+
378
+
Or `screenLayout` prop of the navigator:
379
+
380
+
```diff lang=js
381
+
<Tab.Navigator
382
+
+ screenLayout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
383
+
screenOptions={{
384
+
- unmountOnBlur: true,
385
+
}}
386
+
>
387
+
```
350
388
351
389
#### The `tabBarTestID` option is renamed to `tabBarButtonTestID` in Bottom Tab Navigator and Material Top Tab Navigator
0 commit comments