hybrid-navigation 5.0.0 → 5.1.0
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/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +2 -4
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +48 -2
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +7 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +2 -4
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +3 -0
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +50 -0
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +16 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +19 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +17 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +66 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +116 -18
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +8 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +376 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +72 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +134 -12
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +29 -4
- package/dist/NativeEvent.d.ts +15 -0
- package/dist/NativeNavigation.d.ts +8 -0
- package/dist/Navigation.d.ts +14 -1
- package/dist/Navigation.js +153 -12
- package/dist/NavigationComponentWrap.d.ts +3 -2
- package/dist/Navigator.d.ts +3 -2
- package/dist/Navigator.js +28 -9
- package/dist/Options.d.ts +12 -2
- package/dist/Route.d.ts +70 -5
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +16 -1
- package/dist/handler/DispatchCommandHandler.js +63 -5
- package/dist/handler/LayoutCommandHandler.d.ts +1 -0
- package/dist/handler/LayoutCommandHandler.js +3 -0
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +7 -3
- package/dist/handler/LifecycleEventHandler.js +36 -3
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +7 -0
- package/dist/handler/ResultEventHandler.js +13 -5
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +3 -1
- package/dist/hooks.js +20 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3 -0
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/index.js +5 -41
- package/dist/router/tabs.d.ts +1 -0
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +3 -0
- package/ios/HBDGlobalStyle.mm +13 -0
- package/ios/HybridNavigation.h +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +177 -11
- package/ios/Navigator/HBDStackNavigator.mm +50 -7
- package/ios/Navigator/HBDTabNavigator.mm +33 -5
- package/ios/React/HBDNativeNavigation.mm +73 -12
- package/ios/React/HBDNavigator.h +8 -0
- package/ios/React/HBDOrientationCoordinator.h +2 -0
- package/ios/React/HBDOrientationCoordinator.mm +27 -0
- package/ios/React/HBDReactBridgeManager.h +10 -0
- package/ios/React/HBDReactBridgeManager.mm +48 -2
- package/ios/ViewController/HBDNavigationController.mm +14 -0
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +177 -1
- package/ios/ViewController/HBDTabBarController.h +11 -0
- package/ios/ViewController/HBDTabBarController.mm +170 -3
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +1 -0
- package/ios/ViewController/HBDViewController.mm +57 -9
- package/ios/ViewController/UIViewController+HBD.h +1 -0
- package/ios/ViewController/UIViewController+HBD.mm +13 -4
- package/package.json +3 -1
- package/src/NativeEvent.ts +17 -0
- package/src/NativeNavigation.ts +9 -0
- package/src/Navigation.ts +228 -12
- package/src/NavigationComponentWrap.tsx +11 -2
- package/src/Navigator.ts +38 -9
- package/src/Options.ts +9 -2
- package/src/Route.ts +102 -6
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +110 -11
- package/src/handler/LayoutCommandHandler.ts +4 -0
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +85 -38
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +23 -9
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +37 -1
- package/src/index.ts +11 -0
- package/src/reveal.ts +565 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/index.ts +5 -40
- package/src/router/tabs.ts +1 -0
- package/src/store.ts +5 -0
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
package/src/store.ts
CHANGED
package/src/testing.ts
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
import type { TabItemInfo } from './Options';
|
|
4
|
+
import type {
|
|
5
|
+
DispatchResult,
|
|
6
|
+
LayoutMode,
|
|
7
|
+
LeaveAction,
|
|
8
|
+
ResultMap,
|
|
9
|
+
Route,
|
|
10
|
+
RouteGraph,
|
|
11
|
+
SceneLifecycleState,
|
|
12
|
+
TabPressEvent,
|
|
13
|
+
} from './Route';
|
|
14
|
+
import type {
|
|
15
|
+
BeforeRemoveRequestEvent,
|
|
16
|
+
ResultEvent,
|
|
17
|
+
SceneStateChangeEvent,
|
|
18
|
+
Spec as NativeEventSpec,
|
|
19
|
+
TabPressEventWire,
|
|
20
|
+
} from './NativeEvent';
|
|
21
|
+
import type { DispatchResultWire, Spec as NativeNavigationSpec } from './NativeNavigation';
|
|
22
|
+
import type { DispatchParams } from './handler/DispatchCommandHandler';
|
|
23
|
+
import type { Navigator } from './Navigator';
|
|
24
|
+
|
|
25
|
+
const DEFAULT_CONSTANTS = {
|
|
26
|
+
RESULT_OK: -1,
|
|
27
|
+
RESULT_CANCEL: 0,
|
|
28
|
+
RESULT_BLOCK: -2,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export interface MockNavigationOptions {
|
|
32
|
+
defaultSceneId?: string;
|
|
33
|
+
defaultModuleName?: string;
|
|
34
|
+
onDispatch?: (
|
|
35
|
+
sceneId: string,
|
|
36
|
+
action: string,
|
|
37
|
+
params: DispatchParams,
|
|
38
|
+
) => DispatchResult | Promise<DispatchResult>;
|
|
39
|
+
onSetResult?: (sceneId: string, resultCode: number, data: ResultMap | null) => void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface MockNavigationController {
|
|
43
|
+
readonly dispatchCalls: ReadonlyArray<{
|
|
44
|
+
sceneId: string;
|
|
45
|
+
action: string;
|
|
46
|
+
params: DispatchParams;
|
|
47
|
+
}>;
|
|
48
|
+
readonly setResultCalls: ReadonlyArray<{
|
|
49
|
+
sceneId: string;
|
|
50
|
+
resultCode: number;
|
|
51
|
+
data: ResultMap | null;
|
|
52
|
+
}>;
|
|
53
|
+
readonly tabItemCalls: ReadonlyArray<{ sceneId: string; items: TabItemInfo[] }>;
|
|
54
|
+
readonly beforeRemoveEnabled: ReadonlySet<string>;
|
|
55
|
+
setCurrentRoute(route: Route | null): void;
|
|
56
|
+
setRouteGraph(layers: RouteGraph[]): void;
|
|
57
|
+
setOnDispatch(fn: MockNavigationOptions['onDispatch']): void;
|
|
58
|
+
setOnSetResult(fn: MockNavigationOptions['onSetResult']): void;
|
|
59
|
+
emitSceneState(event: {
|
|
60
|
+
sceneId: string;
|
|
61
|
+
state: SceneLifecycleState;
|
|
62
|
+
prevState?: SceneLifecycleState;
|
|
63
|
+
moduleName?: string;
|
|
64
|
+
mode?: LayoutMode;
|
|
65
|
+
presentingId?: string | null;
|
|
66
|
+
}): void;
|
|
67
|
+
emitResult(event: ResultEvent): void;
|
|
68
|
+
emitBeforeRemove(sceneId: string, action?: LeaveAction): void;
|
|
69
|
+
emitTabPress(event: TabPressEvent): void;
|
|
70
|
+
emitRootReset(): void;
|
|
71
|
+
getNavigator(sceneId: string): Navigator;
|
|
72
|
+
reset(): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type Listener<T> = (payload: T) => void;
|
|
76
|
+
|
|
77
|
+
interface NativeEventListeners {
|
|
78
|
+
onResult: Set<Listener<ResultEvent>>;
|
|
79
|
+
willSetRoot: Set<Listener<void>>;
|
|
80
|
+
didSetRoot: Set<Listener<void>>;
|
|
81
|
+
onSceneStateChange: Set<Listener<SceneStateChangeEvent>>;
|
|
82
|
+
onBeforeRemoveRequest: Set<Listener<BeforeRemoveRequestEvent>>;
|
|
83
|
+
onTabPress: Set<Listener<TabPressEventWire>>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface BridgeState {
|
|
87
|
+
dispatchCalls: Array<{ sceneId: string; action: string; params: DispatchParams }>;
|
|
88
|
+
setResultCalls: Array<{ sceneId: string; resultCode: number; data: ResultMap | null }>;
|
|
89
|
+
tabItemCalls: Array<{ sceneId: string; items: TabItemInfo[] }>;
|
|
90
|
+
beforeRemoveEnabled: Set<string>;
|
|
91
|
+
currentRoute: Route | null;
|
|
92
|
+
routeGraph: RouteGraph[];
|
|
93
|
+
rootGeneration: number;
|
|
94
|
+
onDispatch?: MockNavigationOptions['onDispatch'];
|
|
95
|
+
onSetResult?: MockNavigationOptions['onSetResult'];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function createInitialState(options: MockNavigationOptions = {}): BridgeState {
|
|
99
|
+
return {
|
|
100
|
+
dispatchCalls: [],
|
|
101
|
+
setResultCalls: [],
|
|
102
|
+
tabItemCalls: [],
|
|
103
|
+
beforeRemoveEnabled: new Set(),
|
|
104
|
+
currentRoute: null,
|
|
105
|
+
routeGraph: [],
|
|
106
|
+
rootGeneration: 0,
|
|
107
|
+
onDispatch: options.onDispatch,
|
|
108
|
+
onSetResult: options.onSetResult,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const nativeEventListeners: NativeEventListeners = {
|
|
113
|
+
onResult: new Set(),
|
|
114
|
+
willSetRoot: new Set(),
|
|
115
|
+
didSetRoot: new Set(),
|
|
116
|
+
onSceneStateChange: new Set(),
|
|
117
|
+
onBeforeRemoveRequest: new Set(),
|
|
118
|
+
onTabPress: new Set(),
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
let activeState: BridgeState = createInitialState();
|
|
122
|
+
let bridgeInstalled = false;
|
|
123
|
+
|
|
124
|
+
function subscribe<T>(set: Set<Listener<T>>, listener: Listener<T>) {
|
|
125
|
+
set.add(listener);
|
|
126
|
+
return {
|
|
127
|
+
remove: () => {
|
|
128
|
+
set.delete(listener);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function emit<T>(set: Set<Listener<T>>, payload: T) {
|
|
134
|
+
for (const listener of Array.from(set)) {
|
|
135
|
+
listener(payload);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export const mockNativeEvent: NativeEventSpec = {
|
|
140
|
+
onResult: listener => subscribe(nativeEventListeners.onResult, listener),
|
|
141
|
+
willSetRoot: listener => subscribe(nativeEventListeners.willSetRoot, listener),
|
|
142
|
+
didSetRoot: listener => subscribe(nativeEventListeners.didSetRoot, listener),
|
|
143
|
+
onSceneStateChange: listener => subscribe(nativeEventListeners.onSceneStateChange, listener),
|
|
144
|
+
onBeforeRemoveRequest: listener =>
|
|
145
|
+
subscribe(nativeEventListeners.onBeforeRemoveRequest, listener),
|
|
146
|
+
onTabPress: listener => subscribe(nativeEventListeners.onTabPress, listener),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const mockNativeNavigation: NativeNavigationSpec = {
|
|
150
|
+
getConstants: () => DEFAULT_CONSTANTS,
|
|
151
|
+
startRegisterReactComponent: () => {},
|
|
152
|
+
endRegisterReactComponent: () => {},
|
|
153
|
+
registerReactComponent: () => {},
|
|
154
|
+
signalFirstRenderComplete: () => {},
|
|
155
|
+
setRoot: async (): Promise<DispatchResultWire> => {
|
|
156
|
+
activeState.rootGeneration += 1;
|
|
157
|
+
emit(nativeEventListeners.willSetRoot, undefined);
|
|
158
|
+
emit(nativeEventListeners.didSetRoot, undefined);
|
|
159
|
+
return { ok: true, code: 'ok' };
|
|
160
|
+
},
|
|
161
|
+
setResult: (sceneId, resultCode, data = null) => {
|
|
162
|
+
const normalizedData = (data ?? null) as ResultMap | null;
|
|
163
|
+
activeState.setResultCalls.push({ sceneId, resultCode, data: normalizedData });
|
|
164
|
+
activeState.onSetResult?.(sceneId, resultCode, normalizedData);
|
|
165
|
+
},
|
|
166
|
+
dispatch: async (sceneId, action, params): Promise<DispatchResultWire> => {
|
|
167
|
+
const typedParams = (params ?? {}) as DispatchParams;
|
|
168
|
+
activeState.dispatchCalls.push({ sceneId, action, params: typedParams });
|
|
169
|
+
if (activeState.onDispatch) {
|
|
170
|
+
return await activeState.onDispatch(sceneId, action, typedParams);
|
|
171
|
+
}
|
|
172
|
+
return { ok: true, code: 'ok' };
|
|
173
|
+
},
|
|
174
|
+
currentTab: async () => 0,
|
|
175
|
+
isStackRoot: async () => true,
|
|
176
|
+
findSceneIdByModuleName: async () => null,
|
|
177
|
+
currentRoute: async () => activeState.currentRoute,
|
|
178
|
+
routeGraph: async () => activeState.routeGraph,
|
|
179
|
+
navigationSnapshot: async () => ({
|
|
180
|
+
rootGeneration: activeState.rootGeneration,
|
|
181
|
+
currentRoute: activeState.currentRoute,
|
|
182
|
+
layers: activeState.routeGraph,
|
|
183
|
+
}),
|
|
184
|
+
setDefaultOptions: () => {},
|
|
185
|
+
updateOptions: () => {},
|
|
186
|
+
setBeforeRemoveEnabled: (sceneId, enabled) => {
|
|
187
|
+
if (enabled) {
|
|
188
|
+
activeState.beforeRemoveEnabled.add(sceneId);
|
|
189
|
+
} else {
|
|
190
|
+
activeState.beforeRemoveEnabled.delete(sceneId);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
updateTabBar: () => {},
|
|
194
|
+
setTabItem: (sceneId, items) => {
|
|
195
|
+
activeState.tabItemCalls.push({ sceneId, items: items as TabItemInfo[] });
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
function installNativeBridge() {
|
|
200
|
+
if (bridgeInstalled) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
bridgeInstalled = true;
|
|
204
|
+
const registry = TurboModuleRegistry as unknown as {
|
|
205
|
+
get?: (name: string) => unknown;
|
|
206
|
+
getEnforcing?: (name: string) => unknown;
|
|
207
|
+
};
|
|
208
|
+
const originalGet = registry.get?.bind(TurboModuleRegistry);
|
|
209
|
+
const originalGetEnforcing = registry.getEnforcing?.bind(TurboModuleRegistry);
|
|
210
|
+
|
|
211
|
+
registry.get = (name: string) => {
|
|
212
|
+
if (name === 'HBDNativeNavigation') {
|
|
213
|
+
return mockNativeNavigation;
|
|
214
|
+
}
|
|
215
|
+
if (name === 'HBDNativeEvent') {
|
|
216
|
+
return mockNativeEvent;
|
|
217
|
+
}
|
|
218
|
+
return originalGet ? originalGet(name) : null;
|
|
219
|
+
};
|
|
220
|
+
registry.getEnforcing = (name: string) => {
|
|
221
|
+
if (name === 'HBDNativeNavigation') {
|
|
222
|
+
return mockNativeNavigation;
|
|
223
|
+
}
|
|
224
|
+
if (name === 'HBDNativeEvent') {
|
|
225
|
+
return mockNativeEvent;
|
|
226
|
+
}
|
|
227
|
+
if (originalGetEnforcing) {
|
|
228
|
+
return originalGetEnforcing(name);
|
|
229
|
+
}
|
|
230
|
+
throw new Error(`TurboModule '${name}' could not be found.`);
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface MockNavigationModule {
|
|
235
|
+
readonly __esModule: true;
|
|
236
|
+
readonly default: import('./Navigation').Navigation;
|
|
237
|
+
readonly Navigator: typeof import('./Navigator').Navigator;
|
|
238
|
+
readonly NavigationContext: typeof import('./Navigator').NavigationContext;
|
|
239
|
+
readonly RESULT_OK: number;
|
|
240
|
+
readonly RESULT_CANCEL: number;
|
|
241
|
+
readonly RESULT_BLOCK: number;
|
|
242
|
+
readonly useNavigator: typeof import('./hooks').useNavigator;
|
|
243
|
+
readonly useSceneState: typeof import('./hooks').useSceneState;
|
|
244
|
+
readonly useIsVisible: typeof import('./hooks').useIsVisible;
|
|
245
|
+
readonly useBeforeRemove: typeof import('./hooks').useBeforeRemove;
|
|
246
|
+
readonly useVisibleEffect: typeof import('./hooks').useVisibleEffect;
|
|
247
|
+
readonly withNavigationItem: typeof import('./NavigationComponentWrap').withNavigationItem;
|
|
248
|
+
readonly defineRoute: typeof import('./defineRoutes').defineRoute;
|
|
249
|
+
readonly defineRoutes: typeof import('./defineRoutes').defineRoutes;
|
|
250
|
+
readonly containsScene: typeof import('./routeGraph').containsScene;
|
|
251
|
+
readonly findSceneInGraph: typeof import('./routeGraph').findSceneInGraph;
|
|
252
|
+
readonly findTabIndex: typeof import('./routeGraph').findTabIndex;
|
|
253
|
+
readonly findTabsGraph: typeof import('./routeGraph').findTabsGraph;
|
|
254
|
+
readonly dismissPresentedLayers: typeof import('./reveal').dismissPresentedLayers;
|
|
255
|
+
readonly executeReveal: typeof import('./reveal').executeReveal;
|
|
256
|
+
readonly __mock: MockNavigationController;
|
|
257
|
+
readonly [key: string]: any;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Thin test harness that mocks only the two native TurboModule boundaries
|
|
262
|
+
* (`HBDNativeNavigation` and `HBDNativeEvent`) and runs the real JS navigation layer on top.
|
|
263
|
+
*/
|
|
264
|
+
export function createMockNavigation(
|
|
265
|
+
options: MockNavigationOptions = {},
|
|
266
|
+
): MockNavigationModule {
|
|
267
|
+
installNativeBridge();
|
|
268
|
+
activeState = createInitialState(options);
|
|
269
|
+
|
|
270
|
+
// Require internal submodules directly instead of `./index` so Jest's
|
|
271
|
+
// `jest.mock('hybrid-navigation', () => require('hybrid-navigation/testing').createMockNavigation())`
|
|
272
|
+
// does not recursively re-enter its own factory.
|
|
273
|
+
const navMod: typeof import('./Navigation') = require('./Navigation');
|
|
274
|
+
const navigatorMod: typeof import('./Navigator') = require('./Navigator');
|
|
275
|
+
const hooksMod: typeof import('./hooks') = require('./hooks');
|
|
276
|
+
const wrapMod: typeof import('./NavigationComponentWrap') = require('./NavigationComponentWrap');
|
|
277
|
+
const routerMod: typeof import('./router') = require('./router');
|
|
278
|
+
const routeGraphMod: typeof import('./routeGraph') = require('./routeGraph');
|
|
279
|
+
const revealMod: typeof import('./reveal') = require('./reveal');
|
|
280
|
+
const defineRoutesMod: typeof import('./defineRoutes') = require('./defineRoutes');
|
|
281
|
+
const deepLinkMod: typeof import('./DeepLink') = require('./DeepLink');
|
|
282
|
+
const optionsMod: typeof import('./Options') = require('./Options');
|
|
283
|
+
const {
|
|
284
|
+
lifecycleHandler,
|
|
285
|
+
}: typeof import('./handler/LifecycleEventHandler') = require('./handler/LifecycleEventHandler');
|
|
286
|
+
const {
|
|
287
|
+
dispatchHandler,
|
|
288
|
+
}: typeof import('./handler/DispatchCommandHandler') = require('./handler/DispatchCommandHandler');
|
|
289
|
+
const {
|
|
290
|
+
tabEventHandler,
|
|
291
|
+
}: typeof import('./handler/TabEventHandler') = require('./handler/TabEventHandler');
|
|
292
|
+
const {
|
|
293
|
+
layoutHandler,
|
|
294
|
+
}: typeof import('./handler/LayoutCommandHandler') = require('./handler/LayoutCommandHandler');
|
|
295
|
+
const storeMod: typeof import('./store') = require('./store');
|
|
296
|
+
|
|
297
|
+
const navigation = navMod.default;
|
|
298
|
+
const defaultSceneId = options.defaultSceneId ?? 'scene-1';
|
|
299
|
+
const defaultModuleName = options.defaultModuleName;
|
|
300
|
+
|
|
301
|
+
const getNavigator = (sceneId: string): Navigator => {
|
|
302
|
+
const nav = navigatorMod.Navigator.of(sceneId);
|
|
303
|
+
if (sceneId === defaultSceneId && defaultModuleName && nav.moduleName === undefined) {
|
|
304
|
+
nav.moduleName = defaultModuleName;
|
|
305
|
+
}
|
|
306
|
+
return nav;
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const useNavigator = () => {
|
|
310
|
+
const nav = useContext(navigatorMod.NavigationContext);
|
|
311
|
+
return nav ?? getNavigator(defaultSceneId);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const controller: MockNavigationController = {
|
|
315
|
+
get dispatchCalls() {
|
|
316
|
+
return activeState.dispatchCalls;
|
|
317
|
+
},
|
|
318
|
+
get setResultCalls() {
|
|
319
|
+
return activeState.setResultCalls;
|
|
320
|
+
},
|
|
321
|
+
get tabItemCalls() {
|
|
322
|
+
return activeState.tabItemCalls;
|
|
323
|
+
},
|
|
324
|
+
get beforeRemoveEnabled() {
|
|
325
|
+
return activeState.beforeRemoveEnabled;
|
|
326
|
+
},
|
|
327
|
+
setCurrentRoute(route) {
|
|
328
|
+
activeState.currentRoute = route;
|
|
329
|
+
},
|
|
330
|
+
setRouteGraph(layers) {
|
|
331
|
+
activeState.routeGraph = layers;
|
|
332
|
+
},
|
|
333
|
+
setOnDispatch(fn) {
|
|
334
|
+
activeState.onDispatch = fn;
|
|
335
|
+
},
|
|
336
|
+
setOnSetResult(fn) {
|
|
337
|
+
activeState.onSetResult = fn;
|
|
338
|
+
},
|
|
339
|
+
emitSceneState(event) {
|
|
340
|
+
const prevState = event.prevState ?? navigation.getSceneState(event.sceneId);
|
|
341
|
+
emit(nativeEventListeners.onSceneStateChange, {
|
|
342
|
+
sceneId: event.sceneId,
|
|
343
|
+
state: event.state,
|
|
344
|
+
prevState,
|
|
345
|
+
moduleName: event.moduleName,
|
|
346
|
+
mode: event.mode,
|
|
347
|
+
presentingId: event.presentingId ?? undefined,
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
emitResult(event) {
|
|
351
|
+
emit(nativeEventListeners.onResult, event);
|
|
352
|
+
},
|
|
353
|
+
emitBeforeRemove(sceneId, action = 'back') {
|
|
354
|
+
emit(nativeEventListeners.onBeforeRemoveRequest, { sceneId, action });
|
|
355
|
+
},
|
|
356
|
+
emitTabPress(event) {
|
|
357
|
+
emit(nativeEventListeners.onTabPress, event);
|
|
358
|
+
},
|
|
359
|
+
emitRootReset() {
|
|
360
|
+
activeState.rootGeneration += 1;
|
|
361
|
+
emit(nativeEventListeners.willSetRoot, undefined);
|
|
362
|
+
emit(nativeEventListeners.didSetRoot, undefined);
|
|
363
|
+
},
|
|
364
|
+
getNavigator,
|
|
365
|
+
reset() {
|
|
366
|
+
activeState = createInitialState(options);
|
|
367
|
+
layoutHandler.clearListeners();
|
|
368
|
+
emit(nativeEventListeners.willSetRoot, undefined);
|
|
369
|
+
emit(nativeEventListeners.didSetRoot, undefined);
|
|
370
|
+
lifecycleHandler.resetForTesting();
|
|
371
|
+
storeMod.default.clear();
|
|
372
|
+
dispatchHandler.clearInterceptors();
|
|
373
|
+
tabEventHandler.clearListeners();
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
__esModule: true,
|
|
379
|
+
...optionsMod,
|
|
380
|
+
...deepLinkMod,
|
|
381
|
+
...defineRoutesMod,
|
|
382
|
+
...revealMod,
|
|
383
|
+
...routeGraphMod,
|
|
384
|
+
...routerMod,
|
|
385
|
+
...wrapMod,
|
|
386
|
+
...hooksMod,
|
|
387
|
+
...navigatorMod,
|
|
388
|
+
RESULT_OK: navMod.RESULT_OK,
|
|
389
|
+
RESULT_CANCEL: navMod.RESULT_CANCEL,
|
|
390
|
+
RESULT_BLOCK: navMod.RESULT_BLOCK,
|
|
391
|
+
default: navigation,
|
|
392
|
+
useNavigator: useNavigator as typeof import('./hooks').useNavigator,
|
|
393
|
+
__mock: controller,
|
|
394
|
+
};
|
|
395
|
+
}
|
package/testing.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/testing';
|
package/testing.js
ADDED