Skip to content

Commit

Permalink
docs: provide proper typings for withLayoutContext (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski authored Jan 30, 2025
1 parent 4fa80c2 commit 7a79a7f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-pugs-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bottom-tabs/expo-template': patch
---

fix: provide proper typings for withLayoutContext
26 changes: 19 additions & 7 deletions docs/docs/docs/guides/usage-with-expo-router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@ First install `@bottom-tabs/react-navigation` which provides a native bottom tab

<PackageManagerTabs command="install @bottom-tabs/react-navigation" />

First, create a custom layout adapter for the native bottom tabs:
Next, create a custom layout adapter for the native bottom tabs using `withLayoutContext` from Expo Router:

```tsx
import { withLayoutContext } from "expo-router";
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';

export const Tabs = withLayoutContext(
createNativeBottomTabNavigator().Navigator
);
import { withLayoutContext } from 'expo-router';
import {
createNativeBottomTabNavigator,
NativeBottomTabNavigationOptions,
NativeBottomTabNavigationEventMap,
} from '@bottom-tabs/react-navigation';
import { ParamListBase, TabNavigationState } from '@react-navigation/native';

const BottomTabNavigator = createNativeBottomTabNavigator().Navigator;

const Tabs = withLayoutContext<
NativeBottomTabNavigationOptions,
typeof BottomTabNavigator,
TabNavigationState<ParamListBase>,
NativeBottomTabNavigationEventMap
>(BottomTabNavigator);
```

> [!NOTE] Make sure to provide the correct types for the `withLayoutContext` function. Without it screen options won't have proper types.
Then, use the `Tabs` navigator in your app:

```tsx
Expand Down
16 changes: 14 additions & 2 deletions packages/expo-template/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import React from 'react';
import { withLayoutContext } from 'expo-router';
import { createNativeBottomTabNavigator } from '@bottom-tabs/react-navigation';
import {
createNativeBottomTabNavigator,
NativeBottomTabNavigationOptions,
NativeBottomTabNavigationEventMap,
} from '@bottom-tabs/react-navigation';
import { ParamListBase, TabNavigationState } from '@react-navigation/native';

const Tabs = withLayoutContext(createNativeBottomTabNavigator().Navigator);
const BottomTabNavigator = createNativeBottomTabNavigator().Navigator;

const Tabs = withLayoutContext<
NativeBottomTabNavigationOptions,
typeof BottomTabNavigator,
TabNavigationState<ParamListBase>,
NativeBottomTabNavigationEventMap
>(BottomTabNavigator);

export default function TabLayout() {
return (
Expand Down

0 comments on commit 7a79a7f

Please sign in to comment.