UNPKG

7.12 kBTypeScriptView Raw
1import { DefaultRouterOptions, NavigationState, ParamListBase, PartialState, RouterFactory } from '@react-navigation/routers';
2import * as React from 'react';
3import { DefaultNavigatorOptions, EventMapCore, PrivateValueStore } from './types';
4/**
5 * Hook for building navigators.
6 *
7 * @param createRouter Factory method which returns router object.
8 * @param options Options object containing `children` and additional options for the router.
9 * @returns An object containing `state`, `navigation`, `descriptors` objects.
10 */
11export default function useNavigationBuilder<State extends NavigationState, RouterOptions extends DefaultRouterOptions, ActionHelpers extends Record<string, () => void>, ScreenOptions extends {}, EventMap extends Record<string, any>>(createRouter: RouterFactory<State, any, RouterOptions>, options: DefaultNavigatorOptions<ParamListBase, State, ScreenOptions, EventMap> & RouterOptions): {
12 state: State;
13 navigation: {
14 dispatch(action: Readonly<{
15 type: string;
16 payload?: object | undefined;
17 source?: string | undefined;
18 target?: string | undefined;
19 }> | ((state: Readonly<{
20 key: string;
21 index: number;
22 routeNames: string[];
23 history?: unknown[] | undefined;
24 routes: (Readonly<{
25 key: string;
26 name: string;
27 path?: string | undefined;
28 }> & Readonly<{
29 params?: Readonly<object | undefined>;
30 }> & {
31 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
32 })[];
33 type: string;
34 stale: false;
35 }>) => Readonly<{
36 type: string;
37 payload?: object | undefined;
38 source?: string | undefined;
39 target?: string | undefined;
40 }>)): void;
41 navigate<RouteName extends string>(...args: RouteName extends unknown ? [screen: RouteName] | [screen: RouteName, params: object | undefined] : never): void;
42 navigate<RouteName_1 extends string>(options: RouteName_1 extends unknown ? {
43 key: string;
44 params?: object | undefined;
45 merge?: boolean | undefined;
46 } | {
47 name: RouteName_1;
48 key?: string | undefined;
49 params: object | undefined;
50 merge?: boolean | undefined;
51 } : never): void;
52 reset(state: Readonly<{
53 key: string;
54 index: number;
55 routeNames: string[];
56 history?: unknown[] | undefined;
57 routes: (Readonly<{
58 key: string;
59 name: string;
60 path?: string | undefined;
61 }> & Readonly<{
62 params?: Readonly<object | undefined>;
63 }> & {
64 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
65 })[];
66 type: string;
67 stale: false;
68 }> | PartialState<Readonly<{
69 key: string;
70 index: number;
71 routeNames: string[];
72 history?: unknown[] | undefined;
73 routes: (Readonly<{
74 key: string;
75 name: string;
76 path?: string | undefined;
77 }> & Readonly<{
78 params?: Readonly<object | undefined>;
79 }> & {
80 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
81 })[];
82 type: string;
83 stale: false;
84 }>>): void;
85 goBack(): void;
86 isFocused(): boolean;
87 canGoBack(): boolean;
88 getId(): string | undefined;
89 getParent<T = import("./types").NavigationHelpers<ParamListBase, {}> | undefined>(id?: string | undefined): T;
90 getState(): Readonly<{
91 key: string;
92 index: number;
93 routeNames: string[];
94 history?: unknown[] | undefined;
95 routes: (Readonly<{
96 key: string;
97 name: string;
98 path?: string | undefined;
99 }> & Readonly<{
100 params?: Readonly<object | undefined>;
101 }> & {
102 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
103 })[];
104 type: string;
105 stale: false;
106 }>;
107 } & PrivateValueStore<[ParamListBase, unknown, unknown]> & import("./types").EventEmitter<EventMap> & {
108 setParams<RouteName_2 extends string>(params: Partial<object | undefined>): void;
109 } & ActionHelpers;
110 descriptors: Record<string, import("./types").Descriptor<ScreenOptions, Omit<{
111 dispatch(action: Readonly<{
112 type: string;
113 payload?: object | undefined;
114 source?: string | undefined;
115 target?: string | undefined;
116 }> | ((state: State) => Readonly<{
117 type: string;
118 payload?: object | undefined;
119 source?: string | undefined;
120 target?: string | undefined;
121 }>)): void;
122 navigate<RouteName extends string>(...args: RouteName extends unknown ? [screen: RouteName] | [screen: RouteName, params: object | undefined] : never): void;
123 navigate<RouteName_1 extends string>(options: RouteName_1 extends unknown ? {
124 key: string;
125 params?: object | undefined;
126 merge?: boolean | undefined;
127 } | {
128 name: RouteName_1;
129 key?: string | undefined;
130 params: object | undefined;
131 merge?: boolean | undefined;
132 } : never): void;
133 reset(state: State | PartialState<State>): void;
134 goBack(): void;
135 isFocused(): boolean;
136 canGoBack(): boolean;
137 getId(): string | undefined;
138 getParent<T = import("./types").NavigationHelpers<ParamListBase, {}> | undefined>(id?: string | undefined): T;
139 getState(): State;
140 } & PrivateValueStore<[ParamListBase, unknown, unknown]>, "getParent"> & {
141 getParent<T_1 = import("./types").NavigationProp<ParamListBase, string, undefined, Readonly<{
142 key: string;
143 index: number;
144 routeNames: string[];
145 history?: unknown[] | undefined;
146 routes: (Readonly<{
147 key: string;
148 name: string;
149 path?: string | undefined;
150 }> & Readonly<{
151 params?: Readonly<object | undefined>;
152 }> & {
153 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
154 })[];
155 type: string;
156 stale: false;
157 }>, {}, {}> | undefined>(id?: string | undefined): T_1;
158 setParams(params: Partial<object | undefined>): void;
159 setOptions(options: Partial<ScreenOptions>): void;
160 } & import("./types").EventConsumer<EventMap & EventMapCore<State>> & PrivateValueStore<[ParamListBase, string, EventMap]> & ActionHelpers, import("./types").RouteProp<ParamListBase, string>>>;
161 NavigationContent: ({ children }: {
162 children: React.ReactNode;
163 }) => JSX.Element;
164};