hybrid-navigation 4.1.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/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +18 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +39 -12
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +106 -58
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -108
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +126 -5
- package/ios/ViewController/HBDNavigationController.mm +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
package/dist/testing.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { useContext } from 'react';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
const DEFAULT_CONSTANTS = {
|
|
4
|
+
RESULT_OK: -1,
|
|
5
|
+
RESULT_CANCEL: 0,
|
|
6
|
+
RESULT_BLOCK: -2,
|
|
7
|
+
};
|
|
8
|
+
function createInitialState(options = {}) {
|
|
9
|
+
return {
|
|
10
|
+
dispatchCalls: [],
|
|
11
|
+
setResultCalls: [],
|
|
12
|
+
tabItemCalls: [],
|
|
13
|
+
beforeRemoveEnabled: new Set(),
|
|
14
|
+
currentRoute: null,
|
|
15
|
+
routeGraph: [],
|
|
16
|
+
rootGeneration: 0,
|
|
17
|
+
onDispatch: options.onDispatch,
|
|
18
|
+
onSetResult: options.onSetResult,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const nativeEventListeners = {
|
|
22
|
+
onResult: new Set(),
|
|
23
|
+
willSetRoot: new Set(),
|
|
24
|
+
didSetRoot: new Set(),
|
|
25
|
+
onSceneStateChange: new Set(),
|
|
26
|
+
onBeforeRemoveRequest: new Set(),
|
|
27
|
+
onTabPress: new Set(),
|
|
28
|
+
};
|
|
29
|
+
let activeState = createInitialState();
|
|
30
|
+
let bridgeInstalled = false;
|
|
31
|
+
function subscribe(set, listener) {
|
|
32
|
+
set.add(listener);
|
|
33
|
+
return {
|
|
34
|
+
remove: () => {
|
|
35
|
+
set.delete(listener);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function emit(set, payload) {
|
|
40
|
+
for (const listener of Array.from(set)) {
|
|
41
|
+
listener(payload);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export const mockNativeEvent = {
|
|
45
|
+
onResult: listener => subscribe(nativeEventListeners.onResult, listener),
|
|
46
|
+
willSetRoot: listener => subscribe(nativeEventListeners.willSetRoot, listener),
|
|
47
|
+
didSetRoot: listener => subscribe(nativeEventListeners.didSetRoot, listener),
|
|
48
|
+
onSceneStateChange: listener => subscribe(nativeEventListeners.onSceneStateChange, listener),
|
|
49
|
+
onBeforeRemoveRequest: listener => subscribe(nativeEventListeners.onBeforeRemoveRequest, listener),
|
|
50
|
+
onTabPress: listener => subscribe(nativeEventListeners.onTabPress, listener),
|
|
51
|
+
};
|
|
52
|
+
export const mockNativeNavigation = {
|
|
53
|
+
getConstants: () => DEFAULT_CONSTANTS,
|
|
54
|
+
startRegisterReactComponent: () => { },
|
|
55
|
+
endRegisterReactComponent: () => { },
|
|
56
|
+
registerReactComponent: () => { },
|
|
57
|
+
signalFirstRenderComplete: () => { },
|
|
58
|
+
setRoot: async () => {
|
|
59
|
+
activeState.rootGeneration += 1;
|
|
60
|
+
emit(nativeEventListeners.willSetRoot, undefined);
|
|
61
|
+
emit(nativeEventListeners.didSetRoot, undefined);
|
|
62
|
+
return { ok: true, code: 'ok' };
|
|
63
|
+
},
|
|
64
|
+
setResult: (sceneId, resultCode, data = null) => {
|
|
65
|
+
const normalizedData = (data ?? null);
|
|
66
|
+
activeState.setResultCalls.push({ sceneId, resultCode, data: normalizedData });
|
|
67
|
+
activeState.onSetResult?.(sceneId, resultCode, normalizedData);
|
|
68
|
+
},
|
|
69
|
+
dispatch: async (sceneId, action, params) => {
|
|
70
|
+
const typedParams = (params ?? {});
|
|
71
|
+
activeState.dispatchCalls.push({ sceneId, action, params: typedParams });
|
|
72
|
+
if (activeState.onDispatch) {
|
|
73
|
+
return await activeState.onDispatch(sceneId, action, typedParams);
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, code: 'ok' };
|
|
76
|
+
},
|
|
77
|
+
currentTab: async () => 0,
|
|
78
|
+
isStackRoot: async () => true,
|
|
79
|
+
findSceneIdByModuleName: async () => null,
|
|
80
|
+
currentRoute: async () => activeState.currentRoute,
|
|
81
|
+
routeGraph: async () => activeState.routeGraph,
|
|
82
|
+
navigationSnapshot: async () => ({
|
|
83
|
+
rootGeneration: activeState.rootGeneration,
|
|
84
|
+
currentRoute: activeState.currentRoute,
|
|
85
|
+
layers: activeState.routeGraph,
|
|
86
|
+
}),
|
|
87
|
+
setDefaultOptions: () => { },
|
|
88
|
+
updateOptions: () => { },
|
|
89
|
+
setBeforeRemoveEnabled: (sceneId, enabled) => {
|
|
90
|
+
if (enabled) {
|
|
91
|
+
activeState.beforeRemoveEnabled.add(sceneId);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
activeState.beforeRemoveEnabled.delete(sceneId);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
updateTabBar: () => { },
|
|
98
|
+
setTabItem: (sceneId, items) => {
|
|
99
|
+
activeState.tabItemCalls.push({ sceneId, items: items });
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
function installNativeBridge() {
|
|
103
|
+
if (bridgeInstalled) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
bridgeInstalled = true;
|
|
107
|
+
const registry = TurboModuleRegistry;
|
|
108
|
+
const originalGet = registry.get?.bind(TurboModuleRegistry);
|
|
109
|
+
const originalGetEnforcing = registry.getEnforcing?.bind(TurboModuleRegistry);
|
|
110
|
+
registry.get = (name) => {
|
|
111
|
+
if (name === 'HBDNativeNavigation') {
|
|
112
|
+
return mockNativeNavigation;
|
|
113
|
+
}
|
|
114
|
+
if (name === 'HBDNativeEvent') {
|
|
115
|
+
return mockNativeEvent;
|
|
116
|
+
}
|
|
117
|
+
return originalGet ? originalGet(name) : null;
|
|
118
|
+
};
|
|
119
|
+
registry.getEnforcing = (name) => {
|
|
120
|
+
if (name === 'HBDNativeNavigation') {
|
|
121
|
+
return mockNativeNavigation;
|
|
122
|
+
}
|
|
123
|
+
if (name === 'HBDNativeEvent') {
|
|
124
|
+
return mockNativeEvent;
|
|
125
|
+
}
|
|
126
|
+
if (originalGetEnforcing) {
|
|
127
|
+
return originalGetEnforcing(name);
|
|
128
|
+
}
|
|
129
|
+
throw new Error(`TurboModule '${name}' could not be found.`);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Thin test harness that mocks only the two native TurboModule boundaries
|
|
134
|
+
* (`HBDNativeNavigation` and `HBDNativeEvent`) and runs the real JS navigation layer on top.
|
|
135
|
+
*/
|
|
136
|
+
export function createMockNavigation(options = {}) {
|
|
137
|
+
installNativeBridge();
|
|
138
|
+
activeState = createInitialState(options);
|
|
139
|
+
// Require internal submodules directly instead of `./index` so Jest's
|
|
140
|
+
// `jest.mock('hybrid-navigation', () => require('hybrid-navigation/testing').createMockNavigation())`
|
|
141
|
+
// does not recursively re-enter its own factory.
|
|
142
|
+
const navMod = require('./Navigation');
|
|
143
|
+
const navigatorMod = require('./Navigator');
|
|
144
|
+
const hooksMod = require('./hooks');
|
|
145
|
+
const wrapMod = require('./NavigationComponentWrap');
|
|
146
|
+
const routerMod = require('./router');
|
|
147
|
+
const routeGraphMod = require('./routeGraph');
|
|
148
|
+
const revealMod = require('./reveal');
|
|
149
|
+
const defineRoutesMod = require('./defineRoutes');
|
|
150
|
+
const deepLinkMod = require('./DeepLink');
|
|
151
|
+
const optionsMod = require('./Options');
|
|
152
|
+
const { lifecycleHandler, } = require('./handler/LifecycleEventHandler');
|
|
153
|
+
const { dispatchHandler, } = require('./handler/DispatchCommandHandler');
|
|
154
|
+
const { tabEventHandler, } = require('./handler/TabEventHandler');
|
|
155
|
+
const { layoutHandler, } = require('./handler/LayoutCommandHandler');
|
|
156
|
+
const storeMod = require('./store');
|
|
157
|
+
const navigation = navMod.default;
|
|
158
|
+
const defaultSceneId = options.defaultSceneId ?? 'scene-1';
|
|
159
|
+
const defaultModuleName = options.defaultModuleName;
|
|
160
|
+
const getNavigator = (sceneId) => {
|
|
161
|
+
const nav = navigatorMod.Navigator.of(sceneId);
|
|
162
|
+
if (sceneId === defaultSceneId && defaultModuleName && nav.moduleName === undefined) {
|
|
163
|
+
nav.moduleName = defaultModuleName;
|
|
164
|
+
}
|
|
165
|
+
return nav;
|
|
166
|
+
};
|
|
167
|
+
const useNavigator = () => {
|
|
168
|
+
const nav = useContext(navigatorMod.NavigationContext);
|
|
169
|
+
return nav ?? getNavigator(defaultSceneId);
|
|
170
|
+
};
|
|
171
|
+
const controller = {
|
|
172
|
+
get dispatchCalls() {
|
|
173
|
+
return activeState.dispatchCalls;
|
|
174
|
+
},
|
|
175
|
+
get setResultCalls() {
|
|
176
|
+
return activeState.setResultCalls;
|
|
177
|
+
},
|
|
178
|
+
get tabItemCalls() {
|
|
179
|
+
return activeState.tabItemCalls;
|
|
180
|
+
},
|
|
181
|
+
get beforeRemoveEnabled() {
|
|
182
|
+
return activeState.beforeRemoveEnabled;
|
|
183
|
+
},
|
|
184
|
+
setCurrentRoute(route) {
|
|
185
|
+
activeState.currentRoute = route;
|
|
186
|
+
},
|
|
187
|
+
setRouteGraph(layers) {
|
|
188
|
+
activeState.routeGraph = layers;
|
|
189
|
+
},
|
|
190
|
+
setOnDispatch(fn) {
|
|
191
|
+
activeState.onDispatch = fn;
|
|
192
|
+
},
|
|
193
|
+
setOnSetResult(fn) {
|
|
194
|
+
activeState.onSetResult = fn;
|
|
195
|
+
},
|
|
196
|
+
emitSceneState(event) {
|
|
197
|
+
const prevState = event.prevState ?? navigation.getSceneState(event.sceneId);
|
|
198
|
+
emit(nativeEventListeners.onSceneStateChange, {
|
|
199
|
+
sceneId: event.sceneId,
|
|
200
|
+
state: event.state,
|
|
201
|
+
prevState,
|
|
202
|
+
moduleName: event.moduleName,
|
|
203
|
+
mode: event.mode,
|
|
204
|
+
presentingId: event.presentingId ?? undefined,
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
emitResult(event) {
|
|
208
|
+
emit(nativeEventListeners.onResult, event);
|
|
209
|
+
},
|
|
210
|
+
emitBeforeRemove(sceneId, action = 'back') {
|
|
211
|
+
emit(nativeEventListeners.onBeforeRemoveRequest, { sceneId, action });
|
|
212
|
+
},
|
|
213
|
+
emitTabPress(event) {
|
|
214
|
+
emit(nativeEventListeners.onTabPress, event);
|
|
215
|
+
},
|
|
216
|
+
emitRootReset() {
|
|
217
|
+
activeState.rootGeneration += 1;
|
|
218
|
+
emit(nativeEventListeners.willSetRoot, undefined);
|
|
219
|
+
emit(nativeEventListeners.didSetRoot, undefined);
|
|
220
|
+
},
|
|
221
|
+
getNavigator,
|
|
222
|
+
reset() {
|
|
223
|
+
activeState = createInitialState(options);
|
|
224
|
+
layoutHandler.clearListeners();
|
|
225
|
+
emit(nativeEventListeners.willSetRoot, undefined);
|
|
226
|
+
emit(nativeEventListeners.didSetRoot, undefined);
|
|
227
|
+
lifecycleHandler.resetForTesting();
|
|
228
|
+
storeMod.default.clear();
|
|
229
|
+
dispatchHandler.clearInterceptors();
|
|
230
|
+
tabEventHandler.clearListeners();
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
return {
|
|
234
|
+
__esModule: true,
|
|
235
|
+
...optionsMod,
|
|
236
|
+
...deepLinkMod,
|
|
237
|
+
...defineRoutesMod,
|
|
238
|
+
...revealMod,
|
|
239
|
+
...routeGraphMod,
|
|
240
|
+
...routerMod,
|
|
241
|
+
...wrapMod,
|
|
242
|
+
...hooksMod,
|
|
243
|
+
...navigatorMod,
|
|
244
|
+
RESULT_OK: navMod.RESULT_OK,
|
|
245
|
+
RESULT_CANCEL: navMod.RESULT_CANCEL,
|
|
246
|
+
RESULT_BLOCK: navMod.RESULT_BLOCK,
|
|
247
|
+
default: navigation,
|
|
248
|
+
useNavigator: useNavigator,
|
|
249
|
+
__mock: controller,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
#import "HBDOrientationCoordinator.h"
|
|
3
|
+
|
|
4
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
5
|
+
|
|
6
|
+
@interface HBDGlobalStyle : NSObject
|
|
7
|
+
|
|
8
|
+
+ (void)createWithOptions:(nullable NSDictionary *)options;
|
|
9
|
+
|
|
10
|
+
+ (HBDGlobalStyle *)globalStyle;
|
|
11
|
+
|
|
12
|
+
@property(nonatomic, strong, readonly) UIColor *screenBackgroundColor;
|
|
13
|
+
@property(nonatomic, strong, readonly) UIColor *modalBackgroundColor;
|
|
14
|
+
@property(nonatomic, assign, readonly) BOOL injectInitialMetrics;
|
|
15
|
+
@property(nonatomic, assign, readonly) BOOL prewarmPush;
|
|
16
|
+
@property(nonatomic, assign, readonly) UIBarStyle statusBarStyle;
|
|
17
|
+
@property(nonatomic, strong, readonly) UIColor *tabBarBackgroundColor;
|
|
18
|
+
@property(nonatomic, strong, readonly, nullable) UIImage *tabBarShadowImage;
|
|
19
|
+
@property(nonatomic, strong, readonly) UIColor *tabBarItemSelectedColor;
|
|
20
|
+
@property(nonatomic, strong, readonly) UIColor *tabBarItemNormalColor;
|
|
21
|
+
@property(nonatomic, strong, readonly) UIColor *tabBarBadgeColor;
|
|
22
|
+
@property(nonatomic, assign, readonly) HBDScreenOrientation defaultOrientation;
|
|
23
|
+
|
|
24
|
+
- (instancetype)initWithOptions:(nullable NSDictionary *)options;
|
|
25
|
+
- (void)applyToTabBar:(UITabBar *)tabBar;
|
|
26
|
+
|
|
27
|
+
@end
|
|
28
|
+
|
|
29
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -1,63 +1,73 @@
|
|
|
1
|
-
#import "
|
|
1
|
+
#import "HBDGlobalStyle.h"
|
|
2
2
|
|
|
3
|
+
#import "HBDReactBridgeManager.h"
|
|
3
4
|
#import "HBDUtils.h"
|
|
4
5
|
|
|
5
|
-
@interface
|
|
6
|
+
@interface HBDGlobalStyle ()
|
|
6
7
|
|
|
7
8
|
@property(nonatomic, copy, readonly) NSDictionary *options;
|
|
8
9
|
@property(nonatomic, assign, readwrite) UIBarStyle statusBarStyle;
|
|
9
10
|
|
|
10
|
-
@property(nonatomic, strong) UIColor *tabBarBackgroundColor;
|
|
11
|
-
@property(nonatomic, strong) UIImage *tabBarShadowImage;
|
|
12
|
-
@property(nonatomic, strong) UIColor *tabBarItemSelectedColor;
|
|
13
|
-
@property(nonatomic, strong) UIColor *tabBarItemNormalColor;
|
|
11
|
+
@property(nonatomic, strong, readwrite) UIColor *tabBarBackgroundColor;
|
|
12
|
+
@property(nonatomic, strong, readwrite, nullable) UIImage *tabBarShadowImage;
|
|
13
|
+
@property(nonatomic, strong, readwrite) UIColor *tabBarItemSelectedColor;
|
|
14
|
+
@property(nonatomic, strong, readwrite) UIColor *tabBarItemNormalColor;
|
|
15
|
+
@property(nonatomic, strong, readwrite) UIColor *tabBarBadgeColor;
|
|
16
|
+
@property(nonatomic, assign, readwrite) HBDScreenOrientation defaultOrientation;
|
|
14
17
|
|
|
15
18
|
@end
|
|
16
19
|
|
|
17
|
-
@implementation
|
|
18
|
-
|
|
19
|
-
static GlobalStyle *globalStyle;
|
|
20
|
+
@implementation HBDGlobalStyle
|
|
20
21
|
|
|
21
22
|
+ (void)createWithOptions:(NSDictionary *)options {
|
|
22
|
-
|
|
23
|
-
globalStyle =
|
|
24
|
-
globalStyle.interfaceOrientation = interfaceOrientation;
|
|
25
|
-
[globalStyle inflateTabBar:[UITabBar appearance]];
|
|
23
|
+
HBDGlobalStyle *style = [[HBDGlobalStyle alloc] initWithOptions:options];
|
|
24
|
+
[HBDReactBridgeManager get].globalStyle = style;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
+ (
|
|
29
|
-
|
|
30
|
-
[self createWithOptions:@{}];
|
|
31
|
-
}
|
|
32
|
-
return globalStyle;
|
|
27
|
+
+ (HBDGlobalStyle *)globalStyle {
|
|
28
|
+
return [HBDReactBridgeManager get].globalStyle;
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
- (instancetype)initWithOptions:(NSDictionary *)options {
|
|
36
32
|
if (self = [super init]) {
|
|
37
|
-
_options = options;
|
|
38
|
-
|
|
33
|
+
_options = options ? [options copy] : @{};
|
|
34
|
+
HBDScreenOrientation parsedOrientation = HBDScreenOrientationFromString(_options[@"orientation"]);
|
|
35
|
+
_defaultOrientation = parsedOrientation != HBDScreenOrientationUnspecified ? parsedOrientation : HBDScreenOrientationPortrait;
|
|
39
36
|
|
|
40
|
-
NSString *screenBackgroundColor =
|
|
37
|
+
NSString *screenBackgroundColor = _options[@"screenBackgroundColor"];
|
|
41
38
|
if (screenBackgroundColor) {
|
|
42
39
|
_screenBackgroundColor = [HBDUtils colorWithHexString:screenBackgroundColor];
|
|
43
40
|
} else {
|
|
44
41
|
_screenBackgroundColor = UIColor.whiteColor;
|
|
45
42
|
}
|
|
46
43
|
|
|
47
|
-
NSString *
|
|
44
|
+
NSString *modalBackgroundColor = _options[@"modalBackgroundColor"];
|
|
45
|
+
if (modalBackgroundColor) {
|
|
46
|
+
_modalBackgroundColor = [HBDUtils colorWithHexString:modalBackgroundColor];
|
|
47
|
+
} else {
|
|
48
|
+
_modalBackgroundColor = UIColor.clearColor;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
id injectInitialMetrics = _options[@"injectInitialMetrics"];
|
|
52
|
+
_injectInitialMetrics = [injectInitialMetrics isKindOfClass:[NSNumber class]] ? [injectInitialMetrics boolValue] : NO;
|
|
53
|
+
|
|
54
|
+
id prewarmPush = _options[@"prewarmPush"];
|
|
55
|
+
_prewarmPush = [prewarmPush isKindOfClass:[NSNumber class]] ? [prewarmPush boolValue] : NO;
|
|
56
|
+
|
|
57
|
+
NSString *statusBarStyle = _options[@"statusBarStyle"];
|
|
48
58
|
if (statusBarStyle && [statusBarStyle isEqualToString:@"light-content"]) {
|
|
49
59
|
_statusBarStyle = UIBarStyleBlack;
|
|
50
60
|
} else {
|
|
51
61
|
_statusBarStyle = UIBarStyleDefault;
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
NSString *tabBarBackgroundColor =
|
|
64
|
+
NSString *tabBarBackgroundColor = _options[@"tabBarBackgroundColor"];
|
|
55
65
|
if (!tabBarBackgroundColor) {
|
|
56
66
|
tabBarBackgroundColor = @"#FFFFFF";
|
|
57
67
|
}
|
|
58
68
|
self.tabBarBackgroundColor = [HBDUtils colorWithHexString:tabBarBackgroundColor];
|
|
59
69
|
|
|
60
|
-
NSDictionary *tabBarShadowImage =
|
|
70
|
+
NSDictionary *tabBarShadowImage = _options[@"tabBarShadowImage"];
|
|
61
71
|
if ([tabBarShadowImage isKindOfClass:[NSDictionary class]]) {
|
|
62
72
|
UIImage *image = [UIImage new];
|
|
63
73
|
NSDictionary *imageItem = tabBarShadowImage[@"image"];
|
|
@@ -70,8 +80,8 @@ static GlobalStyle *globalStyle;
|
|
|
70
80
|
self.tabBarShadowImage = image;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
|
-
NSString *tabBarItemSelectedColor =
|
|
74
|
-
NSString *tabBarItemNormalColor =
|
|
83
|
+
NSString *tabBarItemSelectedColor = _options[@"tabBarItemSelectedColor"];
|
|
84
|
+
NSString *tabBarItemNormalColor = _options[@"tabBarItemNormalColor"];
|
|
75
85
|
if (!tabBarItemSelectedColor) {
|
|
76
86
|
tabBarItemSelectedColor = @"#FF5722";
|
|
77
87
|
}
|
|
@@ -81,16 +91,19 @@ static GlobalStyle *globalStyle;
|
|
|
81
91
|
self.tabBarItemSelectedColor = [HBDUtils colorWithHexString:tabBarItemSelectedColor];
|
|
82
92
|
self.tabBarItemNormalColor = [HBDUtils colorWithHexString:tabBarItemNormalColor];
|
|
83
93
|
|
|
84
|
-
NSString *tabBarBadgeColor =
|
|
94
|
+
NSString *tabBarBadgeColor = _options[@"tabBarBadgeColor"];
|
|
85
95
|
if (!tabBarBadgeColor) {
|
|
86
96
|
tabBarBadgeColor = @"#FF3B30";
|
|
87
97
|
}
|
|
88
|
-
|
|
98
|
+
self.tabBarBadgeColor = [HBDUtils colorWithHexString:tabBarBadgeColor];
|
|
89
99
|
}
|
|
90
100
|
return self;
|
|
91
101
|
}
|
|
92
102
|
|
|
93
|
-
- (void)
|
|
103
|
+
- (void)applyToTabBar:(UITabBar *)tabBar {
|
|
104
|
+
if (!tabBar) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
94
107
|
UITabBarItemAppearance *tabBarItem = [UITabBarItemAppearance new];
|
|
95
108
|
tabBarItem.normal.titleTextAttributes = @{
|
|
96
109
|
NSForegroundColorAttributeName: self.tabBarItemNormalColor,
|
|
@@ -115,6 +128,7 @@ static GlobalStyle *globalStyle;
|
|
|
115
128
|
//
|
|
116
129
|
} else {
|
|
117
130
|
tabBar.standardAppearance.backgroundImage = [HBDUtils imageWithColor:self.tabBarBackgroundColor];
|
|
131
|
+
tabBar.scrollEdgeAppearance.backgroundImage = [HBDUtils imageWithColor:self.tabBarBackgroundColor];
|
|
118
132
|
}
|
|
119
133
|
}
|
|
120
134
|
|
package/ios/HybridNavigation.h
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
#define HybridNavigation_h
|
|
3
3
|
|
|
4
4
|
#import "HBDReactBridgeManager.h"
|
|
5
|
+
#import "HBDSceneLifecycleStateMachine.h"
|
|
6
|
+
#import "HBDOrientationCoordinator.h"
|
|
5
7
|
|
|
6
8
|
#import "HBDViewController.h"
|
|
7
9
|
#import "HBDNavigationController.h"
|
|
8
10
|
#import "HBDTabBarController.h"
|
|
11
|
+
#import "HBDTabBarRenderer.h"
|
|
9
12
|
#import "HBDDrawerController.h"
|
|
10
13
|
#import "UIViewController+HBD.h"
|
|
14
|
+
#import "UINavigationController+HBD.h"
|
|
11
15
|
|
|
12
16
|
#import "HBDNavigator.h"
|
|
13
17
|
#import "HBDScreenNavigator.h"
|
|
@@ -16,6 +20,6 @@
|
|
|
16
20
|
#import "HBDDrawerNavigator.h"
|
|
17
21
|
|
|
18
22
|
#import "HBDUtils.h"
|
|
19
|
-
#import "
|
|
23
|
+
#import "HBDGlobalStyle.h"
|
|
20
24
|
|
|
21
25
|
#endif /* HybridNavigation_h */
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
- (NSArray<NSString *> *)supportActions {
|
|
12
|
-
return @[@"toggleMenu", @"openMenu", @"closeMenu"];
|
|
12
|
+
return @[@"toggleMenu", @"openMenu", @"closeMenu", @"setMenuInteractive"];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
@@ -59,12 +59,19 @@
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
HBDDrawerController *drawer = (HBDDrawerController *) vc;
|
|
62
|
+
NSMutableArray *children = [[NSMutableArray alloc] initWithCapacity:2];
|
|
62
63
|
NSDictionary *content = [[HBDReactBridgeManager get] routeGraphWithViewController:drawer.contentController];
|
|
64
|
+
if (content) {
|
|
65
|
+
[children addObject:content];
|
|
66
|
+
}
|
|
63
67
|
NSDictionary *menu = [[HBDReactBridgeManager get] routeGraphWithViewController:drawer.menuController];
|
|
68
|
+
if (menu) {
|
|
69
|
+
[children addObject:menu];
|
|
70
|
+
}
|
|
64
71
|
return @{
|
|
65
72
|
@"layout": @"drawer",
|
|
66
|
-
@"sceneId": drawer.
|
|
67
|
-
@"children":
|
|
73
|
+
@"sceneId": drawer.hbd_sceneId,
|
|
74
|
+
@"children": children,
|
|
68
75
|
@"mode": [drawer hbd_mode],
|
|
69
76
|
};
|
|
70
77
|
}
|
|
@@ -82,29 +89,38 @@
|
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
|
|
85
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
86
|
-
HBDDrawerController *drawer = [vc
|
|
92
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
93
|
+
HBDDrawerController *drawer = [vc hbd_drawerController];
|
|
87
94
|
if (!drawer) {
|
|
88
|
-
|
|
95
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not inside a drawer."));
|
|
89
96
|
return;
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
callback(@[NSNull.null, @YES]);
|
|
93
|
-
|
|
94
99
|
if ([action isEqualToString:@"toggleMenu"]) {
|
|
95
100
|
[drawer toggleMenu];
|
|
101
|
+
completion(HBDDispatchResultOk());
|
|
96
102
|
return;
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
if ([action isEqualToString:@"openMenu"]) {
|
|
100
106
|
[drawer openMenu];
|
|
107
|
+
completion(HBDDispatchResultOk());
|
|
101
108
|
return;
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
if ([action isEqualToString:@"closeMenu"]) {
|
|
105
112
|
[drawer closeMenu];
|
|
113
|
+
completion(HBDDispatchResultOk());
|
|
106
114
|
return;
|
|
107
115
|
}
|
|
116
|
+
|
|
117
|
+
if ([action isEqualToString:@"setMenuInteractive"]) {
|
|
118
|
+
drawer.menuInteractive = [extras[@"enabled"] boolValue];
|
|
119
|
+
completion(HBDDispatchResultOk());
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported drawer action: %@", action]));
|
|
108
124
|
}
|
|
109
125
|
|
|
110
126
|
- (void)invalidate {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
- (instancetype)init {
|
|
25
25
|
if (self = [super init]) {
|
|
26
26
|
_layouts = [NSMutableArray new];
|
|
27
|
+
_navigators = [NSMutableArray new];
|
|
27
28
|
_actionNavigatorPairs = [NSMutableDictionary new];
|
|
28
29
|
_layoutNavigatorPairs = [NSMutableDictionary new];
|
|
29
30
|
_classLayoutPairs = [NSMutableDictionary new];
|