@react-navigation/core 7.0.0-alpha.13 → 7.0.0-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/Group.js.map +1 -1
- package/lib/commonjs/Screen.js.map +1 -1
- package/lib/commonjs/StaticNavigation.js.map +1 -1
- package/lib/commonjs/createNavigatorFactory.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/module/Group.js.map +1 -1
- package/lib/module/Screen.js.map +1 -1
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/createNavigatorFactory.js +1 -0
- package/lib/module/createNavigatorFactory.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/typescript/src/Group.d.ts +1 -1
- package/lib/typescript/src/Group.d.ts.map +1 -1
- package/lib/typescript/src/Screen.d.ts +1 -1
- package/lib/typescript/src/Screen.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +17 -15
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/createNavigatorFactory.d.ts +1 -9
- package/lib/typescript/src/createNavigatorFactory.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +59 -22
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +1 -1
- package/lib/typescript/src/useDescriptors.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Group.tsx +2 -1
- package/src/Screen.tsx +11 -1
- package/src/StaticNavigation.tsx +107 -26
- package/src/createNavigatorFactory.tsx +1 -36
- package/src/index.tsx +1 -0
- package/src/types.tsx +128 -21
- package/src/useDescriptors.tsx +8 -1
- package/src/useNavigationBuilder.tsx +5 -2
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { NavigationState, ParamListBase } from '@react-navigation/routers';
|
|
2
1
|
import type * as React from 'react';
|
|
3
2
|
|
|
4
3
|
import { Group } from './Group';
|
|
5
4
|
import { Screen } from './Screen';
|
|
6
|
-
import type { StaticConfig } from './StaticNavigation';
|
|
7
|
-
import type { EventMapBase, TypedNavigator } from './types';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
* Higher order component to create a `Navigator` and `Screen` pair.
|
|
@@ -13,39 +10,7 @@ import type { EventMapBase, TypedNavigator } from './types';
|
|
|
13
10
|
* @param Navigator The navigator component to wrap.
|
|
14
11
|
* @returns Factory method to create a `Navigator` and `Screen` pair.
|
|
15
12
|
*/
|
|
16
|
-
export function createNavigatorFactory<
|
|
17
|
-
State extends NavigationState,
|
|
18
|
-
ScreenOptions extends {},
|
|
19
|
-
EventMap extends EventMapBase,
|
|
20
|
-
NavigatorComponent extends React.ComponentType<any>,
|
|
21
|
-
>(Navigator: NavigatorComponent) {
|
|
22
|
-
function createNavigator<ParamList extends ParamListBase>(): TypedNavigator<
|
|
23
|
-
ParamList,
|
|
24
|
-
State,
|
|
25
|
-
ScreenOptions,
|
|
26
|
-
EventMap,
|
|
27
|
-
typeof Navigator
|
|
28
|
-
>;
|
|
29
|
-
|
|
30
|
-
function createNavigator<
|
|
31
|
-
ParamList extends ParamListBase,
|
|
32
|
-
Config extends StaticConfig<
|
|
33
|
-
ParamList,
|
|
34
|
-
State,
|
|
35
|
-
ScreenOptions,
|
|
36
|
-
EventMap,
|
|
37
|
-
typeof Navigator
|
|
38
|
-
>,
|
|
39
|
-
>(
|
|
40
|
-
config: Config
|
|
41
|
-
): TypedNavigator<
|
|
42
|
-
ParamList,
|
|
43
|
-
State,
|
|
44
|
-
ScreenOptions,
|
|
45
|
-
EventMap,
|
|
46
|
-
typeof Navigator
|
|
47
|
-
> & { config: Config };
|
|
48
|
-
|
|
13
|
+
export function createNavigatorFactory(Navigator: React.ComponentType<any>) {
|
|
49
14
|
function createNavigator(config?: any): any {
|
|
50
15
|
if (config != null) {
|
|
51
16
|
return {
|
package/src/index.tsx
CHANGED
package/src/types.tsx
CHANGED
|
@@ -24,15 +24,12 @@ type Keyof<T extends {}> = Extract<keyof T, string>;
|
|
|
24
24
|
|
|
25
25
|
export type DefaultNavigatorOptions<
|
|
26
26
|
ParamList extends ParamListBase,
|
|
27
|
+
NavigatorID extends string | undefined,
|
|
27
28
|
State extends NavigationState,
|
|
28
29
|
ScreenOptions extends {},
|
|
29
30
|
EventMap extends EventMapBase,
|
|
31
|
+
Navigation,
|
|
30
32
|
> = DefaultRouterOptions<Keyof<ParamList>> & {
|
|
31
|
-
/**
|
|
32
|
-
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
33
|
-
*/
|
|
34
|
-
id?: string;
|
|
35
|
-
|
|
36
33
|
/**
|
|
37
34
|
* Children React Elements to extract the route configuration from.
|
|
38
35
|
* Only `Screen`, `Group` and `React.Fragment` are supported as children.
|
|
@@ -71,7 +68,7 @@ export type DefaultNavigatorOptions<
|
|
|
71
68
|
| ScreenListeners<State, EventMap>
|
|
72
69
|
| ((props: {
|
|
73
70
|
route: RouteProp<ParamList>;
|
|
74
|
-
navigation:
|
|
71
|
+
navigation: Navigation;
|
|
75
72
|
}) => ScreenListeners<State, EventMap>);
|
|
76
73
|
|
|
77
74
|
/**
|
|
@@ -81,7 +78,7 @@ export type DefaultNavigatorOptions<
|
|
|
81
78
|
| ScreenOptions
|
|
82
79
|
| ((props: {
|
|
83
80
|
route: RouteProp<ParamList>;
|
|
84
|
-
navigation:
|
|
81
|
+
navigation: Navigation;
|
|
85
82
|
theme: ReactNavigation.Theme;
|
|
86
83
|
}) => ScreenOptions);
|
|
87
84
|
|
|
@@ -90,7 +87,7 @@ export type DefaultNavigatorOptions<
|
|
|
90
87
|
*/
|
|
91
88
|
screenLayout?: (props: {
|
|
92
89
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
93
|
-
navigation:
|
|
90
|
+
navigation: Navigation;
|
|
94
91
|
theme: ReactNavigation.Theme;
|
|
95
92
|
children: React.ReactElement;
|
|
96
93
|
}) => React.ReactElement;
|
|
@@ -101,7 +98,16 @@ export type DefaultNavigatorOptions<
|
|
|
101
98
|
getStateForRouteNamesChange?: (
|
|
102
99
|
state: NavigationState
|
|
103
100
|
) => PartialState<NavigationState> | undefined;
|
|
104
|
-
}
|
|
101
|
+
} & (NavigatorID extends string
|
|
102
|
+
? {
|
|
103
|
+
/**
|
|
104
|
+
* Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.
|
|
105
|
+
*/
|
|
106
|
+
id: NavigatorID;
|
|
107
|
+
}
|
|
108
|
+
: {
|
|
109
|
+
id?: undefined;
|
|
110
|
+
});
|
|
105
111
|
|
|
106
112
|
export type EventMapBase = Record<
|
|
107
113
|
string,
|
|
@@ -602,12 +608,13 @@ export type RouteConfigComponent<
|
|
|
602
608
|
getComponent?: never;
|
|
603
609
|
};
|
|
604
610
|
|
|
605
|
-
export type
|
|
611
|
+
export type RouteConfigProps<
|
|
606
612
|
ParamList extends ParamListBase,
|
|
607
613
|
RouteName extends keyof ParamList,
|
|
608
614
|
State extends NavigationState,
|
|
609
615
|
ScreenOptions extends {},
|
|
610
616
|
EventMap extends EventMapBase,
|
|
617
|
+
Navigation,
|
|
611
618
|
> = {
|
|
612
619
|
/**
|
|
613
620
|
* Optional key for this screen. This doesn't need to be unique.
|
|
@@ -628,7 +635,7 @@ export type RouteConfig<
|
|
|
628
635
|
| ScreenOptions
|
|
629
636
|
| ((props: {
|
|
630
637
|
route: RouteProp<ParamList, RouteName>;
|
|
631
|
-
navigation:
|
|
638
|
+
navigation: Navigation;
|
|
632
639
|
theme: ReactNavigation.Theme;
|
|
633
640
|
}) => ScreenOptions);
|
|
634
641
|
|
|
@@ -639,7 +646,7 @@ export type RouteConfig<
|
|
|
639
646
|
| ScreenListeners<State, EventMap>
|
|
640
647
|
| ((props: {
|
|
641
648
|
route: RouteProp<ParamList, RouteName>;
|
|
642
|
-
navigation:
|
|
649
|
+
navigation: Navigation;
|
|
643
650
|
}) => ScreenListeners<State, EventMap>);
|
|
644
651
|
|
|
645
652
|
/**
|
|
@@ -648,8 +655,8 @@ export type RouteConfig<
|
|
|
648
655
|
* e.g. for styling, error boundaries, suspense, etc.
|
|
649
656
|
*/
|
|
650
657
|
layout?: (props: {
|
|
651
|
-
route: RouteProp<ParamList,
|
|
652
|
-
navigation:
|
|
658
|
+
route: RouteProp<ParamList, RouteName>;
|
|
659
|
+
navigation: Navigation;
|
|
653
660
|
theme: ReactNavigation.Theme;
|
|
654
661
|
children: React.ReactElement;
|
|
655
662
|
}) => React.ReactElement;
|
|
@@ -670,11 +677,29 @@ export type RouteConfig<
|
|
|
670
677
|
* Initial params object for the route.
|
|
671
678
|
*/
|
|
672
679
|
initialParams?: Partial<ParamList[RouteName]>;
|
|
673
|
-
}
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
export type RouteConfig<
|
|
683
|
+
ParamList extends ParamListBase,
|
|
684
|
+
RouteName extends keyof ParamList,
|
|
685
|
+
State extends NavigationState,
|
|
686
|
+
ScreenOptions extends {},
|
|
687
|
+
EventMap extends EventMapBase,
|
|
688
|
+
Navigation,
|
|
689
|
+
> = RouteConfigProps<
|
|
690
|
+
ParamList,
|
|
691
|
+
RouteName,
|
|
692
|
+
State,
|
|
693
|
+
ScreenOptions,
|
|
694
|
+
EventMap,
|
|
695
|
+
Navigation
|
|
696
|
+
> &
|
|
697
|
+
RouteConfigComponent<ParamList, RouteName>;
|
|
674
698
|
|
|
675
699
|
export type RouteGroupConfig<
|
|
676
700
|
ParamList extends ParamListBase,
|
|
677
701
|
ScreenOptions extends {},
|
|
702
|
+
Navigation,
|
|
678
703
|
> = {
|
|
679
704
|
/**
|
|
680
705
|
* Optional key for the screens in this group.
|
|
@@ -689,7 +714,7 @@ export type RouteGroupConfig<
|
|
|
689
714
|
| ScreenOptions
|
|
690
715
|
| ((props: {
|
|
691
716
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
692
|
-
navigation:
|
|
717
|
+
navigation: Navigation;
|
|
693
718
|
theme: ReactNavigation.Theme;
|
|
694
719
|
}) => ScreenOptions);
|
|
695
720
|
|
|
@@ -699,7 +724,7 @@ export type RouteGroupConfig<
|
|
|
699
724
|
*/
|
|
700
725
|
screenLayout?: (props: {
|
|
701
726
|
route: RouteProp<ParamList, keyof ParamList>;
|
|
702
|
-
navigation:
|
|
727
|
+
navigation: Navigation;
|
|
703
728
|
theme: ReactNavigation.Theme;
|
|
704
729
|
children: React.ReactElement;
|
|
705
730
|
}) => React.ReactElement;
|
|
@@ -790,11 +815,77 @@ export type NavigationContainerRefWithCurrent<ParamList extends {}> =
|
|
|
790
815
|
current: NavigationContainerRef<ParamList> | null;
|
|
791
816
|
};
|
|
792
817
|
|
|
818
|
+
export type NavigationListBase<ParamList extends ParamListBase> = {
|
|
819
|
+
[RouteName in keyof ParamList]: unknown;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
export type TypeBag<
|
|
823
|
+
ParamList extends ParamListBase,
|
|
824
|
+
NavigatorID extends string | undefined,
|
|
825
|
+
State extends NavigationState,
|
|
826
|
+
ScreenOptions extends {},
|
|
827
|
+
EventMap extends EventMapBase,
|
|
828
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
829
|
+
Navigator extends React.ComponentType<any>,
|
|
830
|
+
> = {
|
|
831
|
+
ParamList: ParamList;
|
|
832
|
+
NavigatorID: NavigatorID;
|
|
833
|
+
State: State;
|
|
834
|
+
ScreenOptions: ScreenOptions;
|
|
835
|
+
EventMap: EventMap;
|
|
836
|
+
NavigationList: NavigationList;
|
|
837
|
+
Navigator: Navigator;
|
|
838
|
+
};
|
|
839
|
+
|
|
840
|
+
export type NavigatorTypeBagBase = {
|
|
841
|
+
ParamList: ParamListBase;
|
|
842
|
+
NavigatorID: string | undefined;
|
|
843
|
+
State: NavigationState;
|
|
844
|
+
ScreenOptions: {};
|
|
845
|
+
EventMap: EventMapBase;
|
|
846
|
+
NavigationList: NavigationListBase<ParamListBase>;
|
|
847
|
+
Navigator: React.ComponentType<any>;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
export type NavigatorTypeBag<
|
|
851
|
+
ParamList extends ParamListBase,
|
|
852
|
+
NavigatorID extends string | undefined,
|
|
853
|
+
State extends NavigationState,
|
|
854
|
+
ScreenOptions extends {},
|
|
855
|
+
EventMap extends EventMapBase,
|
|
856
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
857
|
+
Navigator extends React.ComponentType<any>,
|
|
858
|
+
> = {
|
|
859
|
+
ParamList: ParamList;
|
|
860
|
+
NavigatorID: NavigatorID;
|
|
861
|
+
State: State;
|
|
862
|
+
ScreenOptions: ScreenOptions;
|
|
863
|
+
EventMap: EventMap;
|
|
864
|
+
NavigationList: NavigationList;
|
|
865
|
+
Navigator: Navigator;
|
|
866
|
+
};
|
|
867
|
+
|
|
793
868
|
export type TypedNavigator<
|
|
869
|
+
Bag extends NavigatorTypeBagBase,
|
|
870
|
+
Config = unknown,
|
|
871
|
+
> = TypedNavigatorInternal<
|
|
872
|
+
Bag['ParamList'],
|
|
873
|
+
Bag['NavigatorID'],
|
|
874
|
+
Bag['State'],
|
|
875
|
+
Bag['ScreenOptions'],
|
|
876
|
+
Bag['EventMap'],
|
|
877
|
+
Bag['NavigationList'],
|
|
878
|
+
Bag['Navigator']
|
|
879
|
+
> &
|
|
880
|
+
(undefined extends Config ? {} : { config: Config });
|
|
881
|
+
|
|
882
|
+
type TypedNavigatorInternal<
|
|
794
883
|
ParamList extends ParamListBase,
|
|
884
|
+
NavigatorID extends string | undefined,
|
|
795
885
|
State extends NavigationState,
|
|
796
886
|
ScreenOptions extends {},
|
|
797
887
|
EventMap extends EventMapBase,
|
|
888
|
+
NavigationList extends NavigationListBase<ParamList>,
|
|
798
889
|
Navigator extends React.ComponentType<any>,
|
|
799
890
|
> = {
|
|
800
891
|
/**
|
|
@@ -803,19 +894,35 @@ export type TypedNavigator<
|
|
|
803
894
|
Navigator: React.ComponentType<
|
|
804
895
|
Omit<
|
|
805
896
|
React.ComponentProps<Navigator>,
|
|
806
|
-
keyof DefaultNavigatorOptions<any, any, any, any>
|
|
897
|
+
keyof DefaultNavigatorOptions<any, any, any, any, any, any>
|
|
807
898
|
> &
|
|
808
|
-
DefaultNavigatorOptions<
|
|
899
|
+
DefaultNavigatorOptions<
|
|
900
|
+
ParamList,
|
|
901
|
+
NavigatorID,
|
|
902
|
+
State,
|
|
903
|
+
ScreenOptions,
|
|
904
|
+
EventMap,
|
|
905
|
+
NavigationList[keyof ParamList]
|
|
906
|
+
>
|
|
809
907
|
>;
|
|
810
908
|
/**
|
|
811
909
|
* Component used for grouping multiple route configuration.
|
|
812
910
|
*/
|
|
813
|
-
Group: React.ComponentType<
|
|
911
|
+
Group: React.ComponentType<
|
|
912
|
+
RouteGroupConfig<ParamList, ScreenOptions, NavigationList[keyof ParamList]>
|
|
913
|
+
>;
|
|
814
914
|
/**
|
|
815
915
|
* Component used for specifying route configuration.
|
|
816
916
|
*/
|
|
817
917
|
Screen: <RouteName extends keyof ParamList>(
|
|
818
|
-
_: RouteConfig<
|
|
918
|
+
_: RouteConfig<
|
|
919
|
+
ParamList,
|
|
920
|
+
RouteName,
|
|
921
|
+
State,
|
|
922
|
+
ScreenOptions,
|
|
923
|
+
EventMap,
|
|
924
|
+
NavigationList[RouteName]
|
|
925
|
+
>
|
|
819
926
|
) => null;
|
|
820
927
|
};
|
|
821
928
|
|
package/src/useDescriptors.tsx
CHANGED
|
@@ -36,7 +36,14 @@ export type ScreenConfigWithParent<
|
|
|
36
36
|
keys: (string | undefined)[];
|
|
37
37
|
options: (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined;
|
|
38
38
|
layout: ScreenLayout | undefined;
|
|
39
|
-
props: RouteConfig<
|
|
39
|
+
props: RouteConfig<
|
|
40
|
+
ParamListBase,
|
|
41
|
+
string,
|
|
42
|
+
State,
|
|
43
|
+
ScreenOptions,
|
|
44
|
+
EventMap,
|
|
45
|
+
unknown
|
|
46
|
+
>;
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
type ScreenLayout = (props: {
|
|
@@ -103,7 +103,8 @@ const getRouteConfigsFromChildren = <
|
|
|
103
103
|
string,
|
|
104
104
|
State,
|
|
105
105
|
ScreenOptions,
|
|
106
|
-
EventMap
|
|
106
|
+
EventMap,
|
|
107
|
+
unknown
|
|
107
108
|
>,
|
|
108
109
|
});
|
|
109
110
|
|
|
@@ -252,9 +253,11 @@ export function useNavigationBuilder<
|
|
|
252
253
|
createRouter: RouterFactory<State, any, RouterOptions>,
|
|
253
254
|
options: DefaultNavigatorOptions<
|
|
254
255
|
ParamListBase,
|
|
256
|
+
string | undefined,
|
|
255
257
|
State,
|
|
256
258
|
ScreenOptions,
|
|
257
|
-
EventMap
|
|
259
|
+
EventMap,
|
|
260
|
+
any
|
|
258
261
|
> &
|
|
259
262
|
RouterOptions
|
|
260
263
|
) {
|