UNPKG

9.16 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: [screen: RouteName] | [screen: RouteName, params: object | undefined]): void;
42 navigate<RouteName_1 extends string>(options: {
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 }): 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 getParent<T = import("./types").NavigationProp<ParamListBase, string, Readonly<{
89 key: string;
90 index: number;
91 routeNames: string[];
92 history?: unknown[] | undefined;
93 routes: (Readonly<{
94 key: string;
95 name: string;
96 path?: string | undefined;
97 }> & Readonly<{
98 params?: Readonly<object | undefined>;
99 }> & {
100 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
101 })[];
102 type: string;
103 stale: false;
104 }>, {}, {}> | undefined>(): T;
105 getState(): Readonly<{
106 key: string;
107 index: number;
108 routeNames: string[];
109 history?: unknown[] | undefined;
110 routes: (Readonly<{
111 key: string;
112 name: string;
113 path?: string | undefined;
114 }> & Readonly<{
115 params?: Readonly<object | undefined>;
116 }> & {
117 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
118 })[];
119 type: string;
120 stale: false;
121 }>;
122 } & PrivateValueStore<ParamListBase, string, {}> & import("./types").EventEmitter<EventMap> & {
123 setParams<RouteName_2 extends string>(params: Partial<object | undefined>): void;
124 } & {
125 dispatch(action: Readonly<{
126 type: string;
127 payload?: object | undefined;
128 source?: string | undefined;
129 target?: string | undefined;
130 }> | ((state: any) => Readonly<{
131 type: string;
132 payload?: object | undefined;
133 source?: string | undefined;
134 target?: string | undefined;
135 }>)): void;
136 navigate<RouteName extends string>(...args: [screen: RouteName] | [screen: RouteName, params: object | undefined]): void;
137 navigate<RouteName_1 extends string>(options: {
138 key: string;
139 params?: object | undefined;
140 merge?: boolean | undefined;
141 } | {
142 name: RouteName_1;
143 key?: string | undefined;
144 params: object | undefined;
145 merge?: boolean | undefined;
146 }): void;
147 reset(state: any): void;
148 goBack(): void;
149 isFocused(): boolean;
150 canGoBack(): boolean;
151 getParent<T = import("./types").NavigationProp<ParamListBase, string, Readonly<{
152 key: string;
153 index: number;
154 routeNames: string[];
155 history?: unknown[] | undefined;
156 routes: (Readonly<{
157 key: string;
158 name: string;
159 path?: string | undefined;
160 }> & Readonly<{
161 params?: Readonly<object | undefined>;
162 }> & {
163 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
164 })[];
165 type: string;
166 stale: false;
167 }>, {}, {}> | undefined>(): T;
168 getState(): any;
169 } & {
170 setParams(params: Partial<object | undefined>): void;
171 setOptions(options: Partial<any>): void;
172 } & import("./types").EventConsumer<any> & PrivateValueStore<ParamListBase, string, any> & ActionHelpers;
173 descriptors: Record<string, import("./types").Descriptor<ScreenOptions, {
174 dispatch(action: Readonly<{
175 type: string;
176 payload?: object | undefined;
177 source?: string | undefined;
178 target?: string | undefined;
179 }> | ((state: State) => Readonly<{
180 type: string;
181 payload?: object | undefined;
182 source?: string | undefined;
183 target?: string | undefined;
184 }>)): void;
185 navigate<RouteName extends string>(...args: [screen: RouteName] | [screen: RouteName, params: object | undefined]): void;
186 navigate<RouteName_1 extends string>(options: {
187 key: string;
188 params?: object | undefined;
189 merge?: boolean | undefined;
190 } | {
191 name: RouteName_1;
192 key?: string | undefined;
193 params: object | undefined;
194 merge?: boolean | undefined;
195 }): void;
196 reset(state: State | PartialState<State>): void;
197 goBack(): void;
198 isFocused(): boolean;
199 canGoBack(): boolean;
200 getParent<T = import("./types").NavigationProp<ParamListBase, string, Readonly<{
201 key: string;
202 index: number;
203 routeNames: string[];
204 history?: unknown[] | undefined;
205 routes: (Readonly<{
206 key: string;
207 name: string;
208 path?: string | undefined;
209 }> & Readonly<{
210 params?: Readonly<object | undefined>;
211 }> & {
212 state?: Readonly<any> | PartialState<Readonly<any>> | undefined;
213 })[];
214 type: string;
215 stale: false;
216 }>, {}, {}> | undefined>(): T;
217 getState(): State;
218 } & PrivateValueStore<ParamListBase, string, {}> & {
219 setParams(params: Partial<object | undefined>): void;
220 setOptions(options: Partial<ScreenOptions>): void;
221 } & import("./types").EventConsumer<EventMap & EventMapCore<State>> & PrivateValueStore<ParamListBase, string, EventMap> & ActionHelpers, import("./types").RouteProp<ParamListBase, string>>>;
222 NavigationContent: (rest: Omit<React.ProviderProps<import("./types").NavigationHelpers<ParamListBase, {}> | undefined>, "value">) => JSX.Element;
223};