UNPKG

4.3 kBTypeScriptView Raw
1import type { NavigationAction, NavigationState, ParamListBase, Router } from '@react-navigation/routers';
2import { AddKeyedListener, AddListener } from './NavigationBuilderContext';
3import type { Descriptor, EventMapBase, NavigationHelpers, NavigationProp, RouteConfig, RouteProp } from './types';
4import type { NavigationEventEmitter } from './useEventEmitter';
5export declare type ScreenConfigWithParent<State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase> = [
6 (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined,
7 RouteConfig<ParamListBase, string, State, ScreenOptions, EventMap>
8];
9declare type ScreenOptionsOrCallback<ScreenOptions extends {}> = ScreenOptions | ((props: {
10 route: RouteProp<ParamListBase, string>;
11 navigation: any;
12}) => ScreenOptions);
13declare type Options<State extends NavigationState, ScreenOptions extends {}, EventMap extends EventMapBase> = {
14 state: State;
15 screens: Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>;
16 navigation: NavigationHelpers<ParamListBase>;
17 screenOptions?: ScreenOptionsOrCallback<ScreenOptions>;
18 defaultScreenOptions?: ScreenOptions | ((props: {
19 route: RouteProp<ParamListBase>;
20 navigation: any;
21 options: ScreenOptions;
22 }) => ScreenOptions);
23 onAction: (action: NavigationAction) => boolean;
24 getState: () => State;
25 setState: (state: State) => void;
26 addListener: AddListener;
27 addKeyedListener: AddKeyedListener;
28 onRouteFocus: (key: string) => void;
29 router: Router<State, NavigationAction>;
30 emitter: NavigationEventEmitter<EventMap>;
31};
32/**
33 * Hook to create descriptor objects for the child routes.
34 *
35 * A descriptor object provides 3 things:
36 * - Helper method to render a screen
37 * - Options specified by the screen for the navigator
38 * - Navigation object intended for the route
39 */
40export default function useDescriptors<State extends NavigationState, ActionHelpers extends Record<string, () => void>, ScreenOptions extends {}, EventMap extends EventMapBase>({ state, screens, navigation, screenOptions, defaultScreenOptions, onAction, getState, setState, addListener, addKeyedListener, onRouteFocus, router, emitter, }: Options<State, ScreenOptions, EventMap>): Record<string, Descriptor<ScreenOptions, {
41 dispatch(action: Readonly<{
42 type: string;
43 payload?: object | undefined;
44 source?: string | undefined;
45 target?: string | undefined;
46 }> | ((state: State) => Readonly<{
47 type: string;
48 payload?: object | undefined;
49 source?: string | undefined;
50 target?: string | undefined;
51 }>)): void;
52 navigate<RouteName extends string>(...args: [screen: RouteName] | [screen: RouteName, params: object | undefined]): void;
53 navigate<RouteName_1 extends string>(options: {
54 key: string;
55 params?: object | undefined;
56 merge?: boolean | undefined;
57 } | {
58 name: RouteName_1;
59 key?: string | undefined;
60 params: object | undefined;
61 merge?: boolean | undefined;
62 }): void;
63 reset(state: State | import("@react-navigation/routers").PartialState<State>): void;
64 goBack(): void;
65 isFocused(): boolean;
66 canGoBack(): boolean;
67 getParent<T = NavigationProp<ParamListBase, string, Readonly<{
68 key: string;
69 index: number;
70 routeNames: string[];
71 history?: unknown[] | undefined;
72 routes: (Readonly<{
73 key: string;
74 name: string;
75 path?: string | undefined;
76 }> & Readonly<{
77 params?: Readonly<object | undefined>;
78 }> & {
79 state?: Readonly<any> | import("@react-navigation/routers").PartialState<Readonly<any>> | undefined;
80 })[];
81 type: string;
82 stale: false;
83 }>, {}, {}> | undefined>(): T;
84 getState(): State;
85} & import("./types").PrivateValueStore<ParamListBase, string, {}> & {
86 setParams(params: Partial<object | undefined>): void;
87 setOptions(options: Partial<ScreenOptions>): void;
88} & import("./types").EventConsumer<EventMap & import("./types").EventMapCore<State>> & import("./types").PrivateValueStore<ParamListBase, string, EventMap> & ActionHelpers, RouteProp<ParamListBase, string>>>;
89export {};
90
\No newline at end of file