This repository was archived by the owner on Mar 17, 2025. It is now read-only.
File tree 5 files changed +39
-9
lines changed
5 files changed +39
-9
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
2
createDrawerNavigator ,
3
+ DrawerNavigationEventMap ,
3
4
DrawerNavigationOptions ,
4
5
} from "@react-navigation/drawer" ;
6
+ import { DrawerNavigationState , ParamListBase } from "@react-navigation/native" ;
5
7
6
8
import { withLayoutContext } from "./withLayoutContext" ;
7
9
8
10
const DrawerNavigator = createDrawerNavigator ( ) . Navigator ;
9
11
10
12
export const Drawer = withLayoutContext <
11
13
DrawerNavigationOptions ,
12
- typeof DrawerNavigator
14
+ typeof DrawerNavigator ,
15
+ DrawerNavigationState < ParamListBase > ,
16
+ DrawerNavigationEventMap
13
17
> ( DrawerNavigator ) ;
14
18
15
19
export default Drawer ;
Original file line number Diff line number Diff line change
1
+ import { ParamListBase , StackNavigationState } from "@react-navigation/native" ;
1
2
import {
2
3
createNativeStackNavigator ,
4
+ NativeStackNavigationEventMap ,
3
5
NativeStackNavigationOptions ,
4
6
} from "@react-navigation/native-stack" ;
5
7
@@ -9,7 +11,9 @@ const NativeStackNavigator = createNativeStackNavigator().Navigator;
9
11
10
12
export const Stack = withLayoutContext <
11
13
NativeStackNavigationOptions ,
12
- typeof NativeStackNavigator
14
+ typeof NativeStackNavigator ,
15
+ StackNavigationState < ParamListBase > ,
16
+ NativeStackNavigationEventMap
13
17
> ( NativeStackNavigator ) ;
14
18
15
19
export default Stack ;
Original file line number Diff line number Diff line change 1
1
import { Pressable } from "@bacons/react-views" ;
2
2
import {
3
3
BottomTabNavigationOptions ,
4
+ BottomTabNavigationEventMap ,
4
5
createBottomTabNavigator ,
5
6
} from "@react-navigation/bottom-tabs" ;
7
+ import { TabNavigationState , ParamListBase } from "@react-navigation/native" ;
6
8
import React from "react" ;
7
9
import { Platform } from "react-native" ;
8
10
@@ -15,7 +17,9 @@ const BottomTabNavigator = createBottomTabNavigator().Navigator;
15
17
16
18
export const Tabs = withLayoutContext <
17
19
BottomTabNavigationOptions & { href ?: Href | null } ,
18
- typeof BottomTabNavigator
20
+ typeof BottomTabNavigator ,
21
+ TabNavigationState < ParamListBase > ,
22
+ BottomTabNavigationEventMap
19
23
> ( BottomTabNavigator , ( screens ) => {
20
24
// Support the `href` shortcut prop.
21
25
return screens . map ( ( screen ) => {
Original file line number Diff line number Diff line change
1
+ import { EventMapBase , NavigationState } from "@react-navigation/native" ;
1
2
import React from "react" ;
2
3
3
4
import { useContextKey } from "../Route" ;
@@ -67,15 +68,19 @@ export function useFilterScreenChildren(
67
68
/** Return a navigator that automatically injects matched routes and renders nothing when there are no children. Return type with children prop optional */
68
69
export function withLayoutContext <
69
70
TOptions extends object ,
70
- T extends React . ComponentType < any >
71
+ T extends React . ComponentType < any > ,
72
+ State extends NavigationState ,
73
+ EventMap extends EventMapBase
71
74
> (
72
75
Nav : T ,
73
- processor ?: ( options : ScreenProps < TOptions > [ ] ) => ScreenProps < TOptions > [ ]
76
+ processor ?: (
77
+ options : ScreenProps < TOptions , State , EventMap > [ ]
78
+ ) => ScreenProps < TOptions , State , EventMap > [ ]
74
79
) : React . ForwardRefExoticComponent <
75
80
React . PropsWithoutRef < PickPartial < React . ComponentProps < T > , "children" > > &
76
81
React . RefAttributes < unknown >
77
82
> & {
78
- Screen : ( props : ScreenProps < TOptions > ) => null ;
83
+ Screen : ( props : ScreenProps < TOptions , State , EventMap > ) => null ;
79
84
} {
80
85
const Navigator = React . forwardRef (
81
86
(
Original file line number Diff line number Diff line change
1
+ import type {
2
+ EventMapBase ,
3
+ NavigationState ,
4
+ ParamListBase ,
5
+ RouteProp ,
6
+ ScreenListeners ,
7
+ } from "@react-navigation/native" ;
1
8
import React from "react" ;
2
9
3
10
import {
@@ -15,7 +22,9 @@ import { SuspenseFallback } from "./views/SuspenseFallback";
15
22
import { Try } from "./views/Try" ;
16
23
17
24
export type ScreenProps <
18
- TOptions extends Record < string , any > = Record < string , any >
25
+ TOptions extends Record < string , any > = Record < string , any > ,
26
+ State extends NavigationState = NavigationState ,
27
+ EventMap extends EventMapBase = EventMapBase
19
28
> = {
20
29
/** Name is required when used inside a Layout component. */
21
30
name ?: string ;
@@ -27,8 +36,12 @@ export type ScreenProps<
27
36
initialParams ?: { [ key : string ] : any } ;
28
37
options ?: TOptions ;
29
38
30
- // TODO: types
31
- listeners ?: any ;
39
+ listeners ?:
40
+ | ScreenListeners < State , EventMap >
41
+ | ( ( prop : {
42
+ route : RouteProp < ParamListBase , string > ;
43
+ navigation : any ;
44
+ } ) => ScreenListeners < State , EventMap > ) ;
32
45
33
46
getId ?: ( {
34
47
params,
You can’t perform that action at this time.
0 commit comments