@react-navigation/core 8.0.0-alpha.3 → 8.0.0-alpha.5
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/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/NavigationBuilderContext.js.map +1 -1
- package/lib/module/NavigationIndependentTree.js +8 -4
- package/lib/module/NavigationIndependentTree.js.map +1 -1
- package/lib/module/NavigationProvider.js +14 -3
- package/lib/module/NavigationProvider.js.map +1 -1
- package/lib/module/NavigationStateContext.js.map +1 -1
- package/lib/module/SceneView.js +6 -39
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/StaticNavigation.js +13 -1
- package/lib/module/StaticNavigation.js.map +1 -1
- package/lib/module/getPathFromState.js +24 -2
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +157 -72
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/getStateFromRouteParams.js +24 -0
- package/lib/module/getStateFromRouteParams.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useIsFocused.js +7 -12
- package/lib/module/useIsFocused.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +71 -28
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +5 -5
- package/lib/typescript/src/NavigationBuilderContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts +4 -4
- package/lib/typescript/src/NavigationFocusedRouteStateContext.d.ts.map +1 -1
- package/lib/typescript/src/NavigationIndependentTree.d.ts.map +1 -1
- package/lib/typescript/src/NavigationProvider.d.ts +4 -4
- package/lib/typescript/src/NavigationProvider.d.ts.map +1 -1
- package/lib/typescript/src/NavigationStateContext.d.ts +3 -3
- package/lib/typescript/src/NavigationStateContext.d.ts.map +1 -1
- package/lib/typescript/src/SceneView.d.ts.map +1 -1
- package/lib/typescript/src/StaticNavigation.d.ts +13 -11
- package/lib/typescript/src/StaticNavigation.d.ts.map +1 -1
- package/lib/typescript/src/findFocusedRoute.d.ts +3 -3
- package/lib/typescript/src/findFocusedRoute.d.ts.map +1 -1
- package/lib/typescript/src/getActionFromState.d.ts +3 -3
- package/lib/typescript/src/getActionFromState.d.ts.map +1 -1
- package/lib/typescript/src/getPathFromState.d.ts +2 -2
- package/lib/typescript/src/getPathFromState.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromPath.d.ts +3 -3
- package/lib/typescript/src/getStateFromPath.d.ts.map +1 -1
- package/lib/typescript/src/getStateFromRouteParams.d.ts +3 -0
- package/lib/typescript/src/getStateFromRouteParams.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +64 -64
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/useDescriptors.d.ts +2 -2
- package/lib/typescript/src/useIsFocused.d.ts +3 -0
- package/lib/typescript/src/useIsFocused.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationBuilder.d.ts +17 -17
- package/lib/typescript/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +15 -15
- package/lib/typescript/src/useOnAction.d.ts +6 -6
- package/lib/typescript/src/useOnAction.d.ts.map +1 -1
- package/lib/typescript/src/useOnRouteFocus.d.ts +6 -6
- package/lib/typescript/src/useOnRouteFocus.d.ts.map +1 -1
- package/lib/typescript/src/useRouteCache.d.ts +2 -2
- package/lib/typescript/src/utilities.d.ts +35 -3
- package/lib/typescript/src/utilities.d.ts.map +1 -1
- package/package.json +10 -8
- package/src/BaseNavigationContainer.tsx +1 -1
- package/src/NavigationBuilderContext.tsx +7 -8
- package/src/NavigationFocusedRouteStateContext.tsx +4 -4
- package/src/NavigationIndependentTree.tsx +8 -5
- package/src/NavigationProvider.tsx +17 -3
- package/src/NavigationStateContext.tsx +5 -6
- package/src/SceneView.tsx +6 -36
- package/src/StaticNavigation.tsx +48 -17
- package/src/findFocusedRoute.tsx +3 -3
- package/src/getActionFromState.tsx +7 -7
- package/src/getPathFromState.tsx +52 -8
- package/src/getStateFromPath.tsx +254 -96
- package/src/getStateFromRouteParams.tsx +60 -0
- package/src/index.tsx +1 -0
- package/src/types.tsx +164 -120
- package/src/useIsFocused.tsx +14 -21
- package/src/useNavigationBuilder.tsx +116 -41
- package/src/useOnAction.tsx +7 -7
- package/src/useOnRouteFocus.tsx +9 -11
- package/src/utilities.tsx +72 -4
package/src/types.tsx
CHANGED
|
@@ -14,6 +14,7 @@ import type {
|
|
|
14
14
|
FlatType,
|
|
15
15
|
KeyOf,
|
|
16
16
|
NotUndefined,
|
|
17
|
+
StandardSchemaV1,
|
|
17
18
|
UnionToIntersection,
|
|
18
19
|
} from './utilities';
|
|
19
20
|
|
|
@@ -82,58 +83,68 @@ export type DefaultNavigatorOptions<
|
|
|
82
83
|
* Layout for the navigator.
|
|
83
84
|
* Useful for wrapping with a component with access to navigator's state and options.
|
|
84
85
|
*/
|
|
85
|
-
layout?:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
86
|
+
layout?:
|
|
87
|
+
| ((props: {
|
|
88
|
+
state: State;
|
|
89
|
+
navigation: NavigationHelpers<ParamList>;
|
|
90
|
+
descriptors: Record<
|
|
91
|
+
string,
|
|
92
|
+
Descriptor<
|
|
93
|
+
ScreenOptions,
|
|
94
|
+
NavigationProp<
|
|
95
|
+
ParamList,
|
|
96
|
+
keyof ParamList,
|
|
97
|
+
State,
|
|
98
|
+
ScreenOptions,
|
|
99
|
+
EventMap
|
|
100
|
+
>,
|
|
101
|
+
RouteProp<ParamList>
|
|
102
|
+
>
|
|
103
|
+
>;
|
|
104
|
+
children: React.ReactNode;
|
|
105
|
+
}) => React.ReactElement)
|
|
106
|
+
| undefined;
|
|
104
107
|
|
|
105
108
|
/**
|
|
106
109
|
* Event listeners for all the screens in the navigator.
|
|
107
110
|
*/
|
|
108
111
|
screenListeners?:
|
|
109
|
-
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
| (
|
|
113
|
+
| ScreenListeners<State, EventMap>
|
|
114
|
+
| ((props: {
|
|
115
|
+
route: RouteProp<ParamList>;
|
|
116
|
+
navigation: Navigation;
|
|
117
|
+
}) => ScreenListeners<State, EventMap>)
|
|
118
|
+
)
|
|
119
|
+
| undefined;
|
|
114
120
|
|
|
115
121
|
/**
|
|
116
122
|
* Default options for all screens under this navigator.
|
|
117
123
|
*/
|
|
118
124
|
screenOptions?:
|
|
119
|
-
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
| (
|
|
126
|
+
| ScreenOptions
|
|
127
|
+
| ((props: {
|
|
128
|
+
route: RouteProp<ParamList>;
|
|
129
|
+
navigation: Navigation;
|
|
130
|
+
theme: Theme;
|
|
131
|
+
}) => ScreenOptions)
|
|
132
|
+
)
|
|
133
|
+
| undefined;
|
|
125
134
|
|
|
126
135
|
/**
|
|
127
136
|
* Layout for all screens under this navigator.
|
|
128
137
|
*/
|
|
129
|
-
screenLayout?:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
screenLayout?:
|
|
139
|
+
| ((
|
|
140
|
+
props: ScreenLayoutArgs<
|
|
141
|
+
ParamList,
|
|
142
|
+
keyof ParamList,
|
|
143
|
+
ScreenOptions,
|
|
144
|
+
Navigation
|
|
145
|
+
>
|
|
146
|
+
) => React.ReactElement)
|
|
147
|
+
| undefined;
|
|
137
148
|
|
|
138
149
|
/**
|
|
139
150
|
* A function returning overrides for the underlying router used by the navigator.
|
|
@@ -142,9 +153,11 @@ export type DefaultNavigatorOptions<
|
|
|
142
153
|
*
|
|
143
154
|
* This must be a pure function and cannot reference outside dynamic variables.
|
|
144
155
|
*/
|
|
145
|
-
router?:
|
|
146
|
-
|
|
147
|
-
|
|
156
|
+
router?:
|
|
157
|
+
| (<Action extends NavigationAction>(
|
|
158
|
+
original: Router<State, Action>
|
|
159
|
+
) => Partial<Router<State, Action>>)
|
|
160
|
+
| undefined;
|
|
148
161
|
|
|
149
162
|
/**
|
|
150
163
|
* What should happen when the available route names change.
|
|
@@ -165,12 +178,12 @@ export type DefaultNavigatorOptions<
|
|
|
165
178
|
* - Direct navigation is only handled for `NAVIGATE` actions.
|
|
166
179
|
* - Unhandled state is restored only if the current state becomes invalid, i.e. it doesn't contain any currently defined screens.
|
|
167
180
|
*/
|
|
168
|
-
routeNamesChangeBehavior?: 'firstMatch' | 'lastUnhandled';
|
|
181
|
+
routeNamesChangeBehavior?: ('firstMatch' | 'lastUnhandled') | undefined;
|
|
169
182
|
};
|
|
170
183
|
|
|
171
184
|
export type EventMapBase = Record<
|
|
172
185
|
string,
|
|
173
|
-
{ data?: any; canPreventDefault?: boolean }
|
|
186
|
+
{ data?: any; canPreventDefault?: boolean | undefined }
|
|
174
187
|
>;
|
|
175
188
|
|
|
176
189
|
export type EventMapCore<State extends NavigationState> = {
|
|
@@ -192,7 +205,7 @@ export type EventArg<
|
|
|
192
205
|
/**
|
|
193
206
|
* Key of the route which received the event.
|
|
194
207
|
*/
|
|
195
|
-
readonly target?: string;
|
|
208
|
+
readonly target?: string | undefined;
|
|
196
209
|
} & (CanPreventDefault extends true
|
|
197
210
|
? {
|
|
198
211
|
/**
|
|
@@ -206,7 +219,7 @@ export type EventArg<
|
|
|
206
219
|
}
|
|
207
220
|
: {}) &
|
|
208
221
|
(undefined extends Data
|
|
209
|
-
? { readonly data?: Readonly<Data> }
|
|
222
|
+
? { readonly data?: Readonly<Data> | undefined }
|
|
210
223
|
: { readonly data: Readonly<Data> });
|
|
211
224
|
|
|
212
225
|
export type EventListenerCallback<
|
|
@@ -314,12 +327,18 @@ type NavigationHelpersCommon<
|
|
|
314
327
|
? [
|
|
315
328
|
screen: RouteName,
|
|
316
329
|
params?: ParamList[RouteName],
|
|
317
|
-
options?: {
|
|
330
|
+
options?: {
|
|
331
|
+
merge?: boolean | undefined;
|
|
332
|
+
pop?: boolean | undefined;
|
|
333
|
+
},
|
|
318
334
|
]
|
|
319
335
|
: [
|
|
320
336
|
screen: RouteName,
|
|
321
337
|
params: ParamList[RouteName],
|
|
322
|
-
options?: {
|
|
338
|
+
options?: {
|
|
339
|
+
merge?: boolean | undefined;
|
|
340
|
+
pop?: boolean | undefined;
|
|
341
|
+
},
|
|
323
342
|
]
|
|
324
343
|
: never
|
|
325
344
|
): void;
|
|
@@ -338,9 +357,9 @@ type NavigationHelpersCommon<
|
|
|
338
357
|
? {
|
|
339
358
|
name: RouteName;
|
|
340
359
|
params: ParamList[RouteName];
|
|
341
|
-
path?: string;
|
|
342
|
-
merge?: boolean;
|
|
343
|
-
pop?: boolean;
|
|
360
|
+
path?: string | undefined;
|
|
361
|
+
merge?: boolean | undefined;
|
|
362
|
+
pop?: boolean | undefined;
|
|
344
363
|
}
|
|
345
364
|
: never
|
|
346
365
|
): void;
|
|
@@ -449,23 +468,27 @@ export type NavigationContainerProps = {
|
|
|
449
468
|
/**
|
|
450
469
|
* Initial state object for the navigation tree.
|
|
451
470
|
*/
|
|
452
|
-
initialState?: InitialState;
|
|
471
|
+
initialState?: InitialState | undefined;
|
|
453
472
|
/**
|
|
454
473
|
* Callback which is called with the latest navigation state when it changes.
|
|
455
474
|
*/
|
|
456
|
-
onStateChange?:
|
|
475
|
+
onStateChange?:
|
|
476
|
+
| ((state: Readonly<NavigationState> | undefined) => void)
|
|
477
|
+
| undefined;
|
|
457
478
|
/**
|
|
458
479
|
* Callback which is called after the navigation tree mounts.
|
|
459
480
|
*/
|
|
460
|
-
onReady?: () => void;
|
|
481
|
+
onReady?: (() => void) | undefined;
|
|
461
482
|
/**
|
|
462
483
|
* Callback which is called when an action is not handled.
|
|
463
484
|
*/
|
|
464
|
-
onUnhandledAction?:
|
|
485
|
+
onUnhandledAction?:
|
|
486
|
+
| ((action: Readonly<NavigationAction>) => void)
|
|
487
|
+
| undefined;
|
|
465
488
|
/**
|
|
466
489
|
* Theme object for the UI elements.
|
|
467
490
|
*/
|
|
468
|
-
theme?: Theme;
|
|
491
|
+
theme?: Theme | undefined;
|
|
469
492
|
/**
|
|
470
493
|
* Children elements to render.
|
|
471
494
|
*/
|
|
@@ -579,7 +602,7 @@ export type ScreenLayoutArgs<
|
|
|
579
602
|
|
|
580
603
|
export type Descriptor<
|
|
581
604
|
ScreenOptions extends {},
|
|
582
|
-
Navigation extends NavigationProp<
|
|
605
|
+
Navigation extends NavigationProp<ParamListBase, any, any, any, any>,
|
|
583
606
|
Route extends RouteProp<any, any>,
|
|
584
607
|
> = {
|
|
585
608
|
/**
|
|
@@ -632,16 +655,16 @@ export type RouteConfigComponent<
|
|
|
632
655
|
* React component to render for this screen.
|
|
633
656
|
*/
|
|
634
657
|
component: ScreenComponentType<ParamList, RouteName>;
|
|
635
|
-
getComponent?: never;
|
|
636
|
-
children?: never;
|
|
658
|
+
getComponent?: never | undefined;
|
|
659
|
+
children?: never | undefined;
|
|
637
660
|
}
|
|
638
661
|
| {
|
|
639
662
|
/**
|
|
640
663
|
* Lazily get a React component to render for this screen.
|
|
641
664
|
*/
|
|
642
665
|
getComponent: () => ScreenComponentType<ParamList, RouteName>;
|
|
643
|
-
component?: never;
|
|
644
|
-
children?: never;
|
|
666
|
+
component?: never | undefined;
|
|
667
|
+
children?: never | undefined;
|
|
645
668
|
}
|
|
646
669
|
| {
|
|
647
670
|
/**
|
|
@@ -651,8 +674,8 @@ export type RouteConfigComponent<
|
|
|
651
674
|
route: RouteProp<ParamList, RouteName>;
|
|
652
675
|
navigation: any;
|
|
653
676
|
}) => React.ReactNode;
|
|
654
|
-
component?: never;
|
|
655
|
-
getComponent?: never;
|
|
677
|
+
component?: never | undefined;
|
|
678
|
+
getComponent?: never | undefined;
|
|
656
679
|
};
|
|
657
680
|
|
|
658
681
|
export type RouteConfigProps<
|
|
@@ -668,7 +691,7 @@ export type RouteConfigProps<
|
|
|
668
691
|
* If the key changes, existing screens with this name will be removed or reset.
|
|
669
692
|
* Useful when we have some common screens and have conditional rendering.
|
|
670
693
|
*/
|
|
671
|
-
navigationKey?: string;
|
|
694
|
+
navigationKey?: string | undefined;
|
|
672
695
|
|
|
673
696
|
/**
|
|
674
697
|
* Route name of this screen.
|
|
@@ -679,31 +702,39 @@ export type RouteConfigProps<
|
|
|
679
702
|
* Navigator options for this screen.
|
|
680
703
|
*/
|
|
681
704
|
options?:
|
|
682
|
-
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
705
|
+
| (
|
|
706
|
+
| ScreenOptions
|
|
707
|
+
| ((props: {
|
|
708
|
+
route: RouteProp<ParamList, RouteName>;
|
|
709
|
+
navigation: Navigation;
|
|
710
|
+
theme: Theme;
|
|
711
|
+
}) => ScreenOptions)
|
|
712
|
+
)
|
|
713
|
+
| undefined;
|
|
688
714
|
|
|
689
715
|
/**
|
|
690
716
|
* Event listeners for this screen.
|
|
691
717
|
*/
|
|
692
718
|
listeners?:
|
|
693
|
-
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
719
|
+
| (
|
|
720
|
+
| ScreenListeners<State, EventMap>
|
|
721
|
+
| ((props: {
|
|
722
|
+
route: RouteProp<ParamList, RouteName>;
|
|
723
|
+
navigation: Navigation;
|
|
724
|
+
}) => ScreenListeners<State, EventMap>)
|
|
725
|
+
)
|
|
726
|
+
| undefined;
|
|
698
727
|
|
|
699
728
|
/**
|
|
700
729
|
* Layout for this screen.
|
|
701
730
|
* Useful for wrapping the screen with custom containers.
|
|
702
731
|
* e.g. for styling, error boundaries, suspense, etc.
|
|
703
732
|
*/
|
|
704
|
-
layout?:
|
|
705
|
-
|
|
706
|
-
|
|
733
|
+
layout?:
|
|
734
|
+
| ((
|
|
735
|
+
props: ScreenLayoutArgs<ParamList, RouteName, ScreenOptions, Navigation>
|
|
736
|
+
) => React.ReactElement)
|
|
737
|
+
| undefined;
|
|
707
738
|
|
|
708
739
|
/**
|
|
709
740
|
* Function to return an unique ID for this screen.
|
|
@@ -711,16 +742,18 @@ export type RouteConfigProps<
|
|
|
711
742
|
* For a given screen name, there will always be only one screen corresponding to an ID.
|
|
712
743
|
* If `undefined` is returned, it acts same as no `getId` being specified.
|
|
713
744
|
*/
|
|
714
|
-
getId?:
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
745
|
+
getId?:
|
|
746
|
+
| (({
|
|
747
|
+
params,
|
|
748
|
+
}: {
|
|
749
|
+
params: Readonly<ParamList[RouteName]>;
|
|
750
|
+
}) => string | undefined)
|
|
751
|
+
| undefined;
|
|
719
752
|
|
|
720
753
|
/**
|
|
721
754
|
* Initial params object for the route.
|
|
722
755
|
*/
|
|
723
|
-
initialParams?: Partial<ParamList[RouteName]
|
|
756
|
+
initialParams?: Partial<ParamList[RouteName]> | undefined;
|
|
724
757
|
};
|
|
725
758
|
|
|
726
759
|
export type RouteConfig<
|
|
@@ -749,35 +782,41 @@ export type RouteGroupConfig<
|
|
|
749
782
|
* Optional key for the screens in this group.
|
|
750
783
|
* If the key changes, all existing screens in this group will be removed or reset.
|
|
751
784
|
*/
|
|
752
|
-
navigationKey?: string;
|
|
785
|
+
navigationKey?: string | undefined;
|
|
753
786
|
|
|
754
787
|
/**
|
|
755
788
|
* Navigator options for this screen.
|
|
756
789
|
*/
|
|
757
790
|
screenOptions?:
|
|
758
|
-
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
791
|
+
| (
|
|
792
|
+
| ScreenOptions
|
|
793
|
+
| ((props: {
|
|
794
|
+
route: RouteProp<ParamList, keyof ParamList>;
|
|
795
|
+
navigation: Navigation;
|
|
796
|
+
theme: Theme;
|
|
797
|
+
}) => ScreenOptions)
|
|
798
|
+
)
|
|
799
|
+
| undefined;
|
|
764
800
|
|
|
765
801
|
/**
|
|
766
802
|
* Layout for the screens inside the group.
|
|
767
803
|
* This will override the `screenLayout` of parent group or navigator.
|
|
768
804
|
*/
|
|
769
805
|
screenLayout?:
|
|
770
|
-
| (
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
806
|
+
| (
|
|
807
|
+
| ((
|
|
808
|
+
props: ScreenLayoutArgs<
|
|
809
|
+
ParamList,
|
|
810
|
+
keyof ParamList,
|
|
811
|
+
ScreenOptions,
|
|
812
|
+
Navigation
|
|
813
|
+
>
|
|
814
|
+
) => React.ReactElement)
|
|
815
|
+
| {
|
|
816
|
+
// FIXME: TypeScript doesn't seem to infer `navigation` correctly without this
|
|
817
|
+
}
|
|
818
|
+
)
|
|
819
|
+
| undefined;
|
|
781
820
|
|
|
782
821
|
/**
|
|
783
822
|
* Children React Elements to extract the route configuration from.
|
|
@@ -1173,33 +1212,35 @@ export type NavigatorScreenParams<ParamList extends {}> =
|
|
|
1173
1212
|
merge?: never;
|
|
1174
1213
|
initial?: never;
|
|
1175
1214
|
pop?: never;
|
|
1176
|
-
path?: string;
|
|
1215
|
+
path?: string | undefined;
|
|
1177
1216
|
state: PartialState<NavigationState> | NavigationState | undefined;
|
|
1178
1217
|
}
|
|
1179
1218
|
| {
|
|
1180
1219
|
[RouteName in keyof ParamList]: undefined extends ParamList[RouteName]
|
|
1181
1220
|
? {
|
|
1182
1221
|
screen: RouteName;
|
|
1183
|
-
params?: ParamList[RouteName];
|
|
1184
|
-
merge?: boolean;
|
|
1185
|
-
initial?: boolean;
|
|
1186
|
-
path?: string;
|
|
1187
|
-
pop?: boolean;
|
|
1222
|
+
params?: ParamList[RouteName] | undefined;
|
|
1223
|
+
merge?: boolean | undefined;
|
|
1224
|
+
initial?: boolean | undefined;
|
|
1225
|
+
path?: string | undefined;
|
|
1226
|
+
pop?: boolean | undefined;
|
|
1188
1227
|
state?: never;
|
|
1189
1228
|
}
|
|
1190
1229
|
: {
|
|
1191
1230
|
screen: RouteName;
|
|
1192
1231
|
params: ParamList[RouteName];
|
|
1193
|
-
merge?: boolean;
|
|
1194
|
-
initial?: boolean;
|
|
1195
|
-
path?: string;
|
|
1196
|
-
pop?: boolean;
|
|
1232
|
+
merge?: boolean | undefined;
|
|
1233
|
+
initial?: boolean | undefined;
|
|
1234
|
+
path?: string | undefined;
|
|
1235
|
+
pop?: boolean | undefined;
|
|
1197
1236
|
state?: never;
|
|
1198
1237
|
};
|
|
1199
1238
|
}[keyof ParamList];
|
|
1200
1239
|
|
|
1201
1240
|
type ParseConfig<Params> = {
|
|
1202
|
-
[K in keyof Params]?:
|
|
1241
|
+
[K in keyof Params]?:
|
|
1242
|
+
| ((value: string) => Params[K])
|
|
1243
|
+
| StandardSchemaV1<string | string[] | null | undefined, Params[K]>;
|
|
1203
1244
|
};
|
|
1204
1245
|
|
|
1205
1246
|
type StringifyConfig<Params> = {
|
|
@@ -1217,9 +1258,9 @@ type PathConfigAlias<Params> = {
|
|
|
1217
1258
|
* By default, paths are relating to the path config on the parent screen.
|
|
1218
1259
|
* If `exact` is set to `true`, the parent path configuration is not used.
|
|
1219
1260
|
*/
|
|
1220
|
-
exact?: boolean;
|
|
1261
|
+
exact?: boolean | undefined;
|
|
1221
1262
|
/**
|
|
1222
|
-
* An object mapping the param name to a function
|
|
1263
|
+
* An object mapping the param name to a parser function or a Standard Schema.
|
|
1223
1264
|
*
|
|
1224
1265
|
* @example
|
|
1225
1266
|
* ```js
|
|
@@ -1229,7 +1270,7 @@ type PathConfigAlias<Params> = {
|
|
|
1229
1270
|
* }
|
|
1230
1271
|
* ```
|
|
1231
1272
|
*/
|
|
1232
|
-
parse?: ParseConfig<Params
|
|
1273
|
+
parse?: ParseConfig<Params> | undefined;
|
|
1233
1274
|
};
|
|
1234
1275
|
|
|
1235
1276
|
export type PathConfig<Params> = FlatType<
|
|
@@ -1246,25 +1287,28 @@ export type PathConfig<Params> = FlatType<
|
|
|
1246
1287
|
* }
|
|
1247
1288
|
* ```
|
|
1248
1289
|
*/
|
|
1249
|
-
stringify?: StringifyConfig<Params
|
|
1290
|
+
stringify?: StringifyConfig<Params> | undefined;
|
|
1250
1291
|
/**
|
|
1251
1292
|
* Additional path alias that will be matched to the same screen.
|
|
1252
1293
|
*/
|
|
1253
|
-
alias?: (string | PathConfigAlias<Params>)[];
|
|
1294
|
+
alias?: (string | PathConfigAlias<Params>)[] | undefined;
|
|
1254
1295
|
} & (NonNullable<Params> extends NavigatorScreenParams<infer ParamList>
|
|
1255
1296
|
? {
|
|
1256
1297
|
/**
|
|
1257
1298
|
* Path configuration for child screens.
|
|
1258
1299
|
*/
|
|
1259
|
-
screens?: PathConfigMap<ParamList
|
|
1300
|
+
screens?: PathConfigMap<ParamList> | undefined;
|
|
1260
1301
|
/**
|
|
1261
1302
|
* Name of the initial route to use for the navigator when the path matches.
|
|
1262
1303
|
*/
|
|
1263
|
-
initialRouteName?: keyof ParamList;
|
|
1304
|
+
initialRouteName?: keyof ParamList | undefined;
|
|
1264
1305
|
}
|
|
1265
1306
|
: {})
|
|
1266
1307
|
>;
|
|
1267
1308
|
|
|
1268
1309
|
export type PathConfigMap<ParamList extends {}> = {
|
|
1269
|
-
[RouteName in keyof ParamList]?:
|
|
1310
|
+
[RouteName in keyof ParamList]?:
|
|
1311
|
+
| string
|
|
1312
|
+
| PathConfig<ParamList[RouteName]>
|
|
1313
|
+
| undefined;
|
|
1270
1314
|
};
|
package/src/useIsFocused.tsx
CHANGED
|
@@ -1,32 +1,25 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const FocusedRouteKeyContext = React.createContext<string | undefined>(
|
|
4
|
+
undefined
|
|
5
|
+
);
|
|
6
|
+
|
|
7
|
+
export const IsFocusedContext = React.createContext<boolean | undefined>(
|
|
8
|
+
undefined
|
|
9
|
+
);
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* Hook to get the current focus state of the screen. Returns a `true` if screen is focused, otherwise `false`.
|
|
7
13
|
* This can be used if a component needs to render something based on the focus state.
|
|
8
14
|
*/
|
|
9
15
|
export function useIsFocused(): boolean {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
const subscribe = React.useCallback(
|
|
13
|
-
(callback: () => void) => {
|
|
14
|
-
const unsubscribeFocus = navigation.addListener('focus', callback);
|
|
15
|
-
const unsubscribeBlur = navigation.addListener('blur', callback);
|
|
16
|
-
|
|
17
|
-
return () => {
|
|
18
|
-
unsubscribeFocus();
|
|
19
|
-
unsubscribeBlur();
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
[navigation]
|
|
23
|
-
);
|
|
16
|
+
const isFocused = React.use(IsFocusedContext);
|
|
24
17
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
if (isFocused === undefined) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"Couldn't determine focus state. Is your component inside a screen in a navigator?"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
30
23
|
|
|
31
|
-
return
|
|
24
|
+
return isFocused;
|
|
32
25
|
}
|