hybrid-navigation 2.20.1 → 3.0.1
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 +7 -5
- package/README.md +17 -0
- package/android/build.gradle +56 -19
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
- package/dist/NativeEvent.d.ts +33 -0
- package/dist/NativeEvent.js +2 -0
- package/dist/NativeGarden.d.ts +18 -0
- package/dist/NativeGarden.js +2 -0
- package/dist/NativeNavigation.d.ts +47 -0
- package/dist/NativeNavigation.js +2 -0
- package/dist/Navigation.js +3 -3
- package/dist/NavigationModule.d.ts +3 -3
- package/dist/NavigationModule.js +18 -19
- package/dist/Navigator.js +1 -2
- package/dist/Options.d.ts +4 -7
- package/dist/Route.d.ts +0 -2
- package/dist/handler/BarButtonEventHandler.js +2 -2
- package/dist/handler/LayoutCommandHandler.js +3 -3
- package/dist/handler/ResultEventHandler.js +3 -3
- package/dist/handler/VisibilityEventHandler.js +11 -4
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/ios/HybridNavigation/GlobalStyle.h +0 -6
- package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
- package/ios/HybridNavigation/HBDUtils.h +0 -4
- package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
- package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
- package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
- package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
- package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
- package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
- package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
- package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
- package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
- package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
- package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +8 -28
- package/ios/HybridNavigation/View/HBDRootView.h +2 -2
- package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
- package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
- package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
- package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
- package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
- package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
- package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
- package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
- package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
- package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
- package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
- package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +10 -44
- package/package.json +11 -2
- package/src/DeepLink.ts +3 -3
- package/src/NativeEvent.ts +40 -0
- package/src/NativeGarden.ts +27 -0
- package/src/NativeNavigation.ts +72 -0
- package/src/Navigation.ts +13 -13
- package/src/NavigationComponentWrap.tsx +4 -4
- package/src/NavigationModule.ts +21 -46
- package/src/Navigator.ts +13 -13
- package/src/Options.ts +9 -9
- package/src/Route.ts +0 -2
- package/src/handler/BarButtonEventHandler.ts +4 -8
- package/src/handler/DispatchCommandHandler.ts +4 -8
- package/src/handler/LayoutCommandHandler.ts +4 -5
- package/src/handler/ResultEventHandler.ts +11 -27
- package/src/handler/VisibilityEventHandler.ts +23 -32
- package/src/hooks.ts +2 -2
- package/src/index.ts +4 -5
- package/src/router/drawer.ts +5 -5
- package/src/router/index.ts +15 -15
- package/src/router/screen.ts +2 -2
- package/src/router/stack.ts +4 -4
- package/src/router/tabs.ts +3 -3
- package/src/store.ts +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
- package/dist/Event.d.ts +0 -16
- package/dist/Event.js +0 -62
- package/dist/GardenModule.d.ts +0 -24
- package/dist/GardenModule.js +0 -21
- package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
- package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
- package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
- package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
- package/src/Event.ts +0 -117
- package/src/GardenModule.ts +0 -50
- /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
- /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
- /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
- /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
- /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"android",
|
|
13
13
|
"ios",
|
|
14
14
|
"HybridNavigation.podspec",
|
|
15
|
+
"README.md",
|
|
15
16
|
"!android/build",
|
|
16
17
|
"!android/.gradle",
|
|
17
18
|
"!android/.idea",
|
|
@@ -46,5 +47,13 @@
|
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"path-to-regexp": "^6.1.0"
|
|
48
49
|
},
|
|
49
|
-
"devDependencies": {}
|
|
50
|
+
"devDependencies": {},
|
|
51
|
+
"codegenConfig": {
|
|
52
|
+
"name": "navigation",
|
|
53
|
+
"type": "modules",
|
|
54
|
+
"jsSrcsDir": "src",
|
|
55
|
+
"android": {
|
|
56
|
+
"javaPackageName": "com.reactnative.hybridnavigation"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
50
59
|
}
|
package/src/DeepLink.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {EmitterSubscription, Linking} from 'react-native';
|
|
2
|
-
import {router} from './router';
|
|
1
|
+
import { EmitterSubscription, Linking } from 'react-native';
|
|
2
|
+
import { router } from './router';
|
|
3
3
|
|
|
4
4
|
class DeepLinkImpl {
|
|
5
5
|
private active = 0;
|
|
@@ -47,7 +47,7 @@ class DeepLinkImpl {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
private handleLinking = (event: {url: string}) => {
|
|
50
|
+
private handleLinking = (event: { url: string }) => {
|
|
51
51
|
console.info(`deeplink:${event.url}`);
|
|
52
52
|
let path = event.url.replace(this.uriPrefix, '');
|
|
53
53
|
if (!path.startsWith('/')) {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import type { CodegenTypes, TurboModule } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export type ComponentAppearEvent = {
|
|
5
|
+
sceneId: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ComponentDisappearEvent = {
|
|
9
|
+
sceneId: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type BarButtonItemClickEvent = {
|
|
13
|
+
sceneId: string;
|
|
14
|
+
action: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type ResultEvent = {
|
|
18
|
+
sceneId: string;
|
|
19
|
+
requestCode: number;
|
|
20
|
+
resultCode: number;
|
|
21
|
+
resultData: {};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type SwitchTabEvent = {
|
|
25
|
+
sceneId: string;
|
|
26
|
+
from: number;
|
|
27
|
+
to: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface Spec extends TurboModule {
|
|
31
|
+
readonly onResult: CodegenTypes.EventEmitter<ResultEvent>;
|
|
32
|
+
readonly willSetRoot: CodegenTypes.EventEmitter<void>;
|
|
33
|
+
readonly didSetRoot: CodegenTypes.EventEmitter<void>;
|
|
34
|
+
readonly onSwitchTab: CodegenTypes.EventEmitter<SwitchTabEvent>;
|
|
35
|
+
readonly onBarButtonItemClick: CodegenTypes.EventEmitter<BarButtonItemClickEvent>;
|
|
36
|
+
readonly onComponentAppear: CodegenTypes.EventEmitter<ComponentAppearEvent>;
|
|
37
|
+
readonly onComponentDisappear: CodegenTypes.EventEmitter<ComponentDisappearEvent>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('HBDNativeEvent');
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import type { CodegenTypes, TurboModule } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
getConstants: () => {
|
|
6
|
+
TOOLBAR_HEIGHT: number;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
setStyle: (style: CodegenTypes.UnsafeObject) => void;
|
|
10
|
+
setTitleItem: (sceneId: string, item: CodegenTypes.UnsafeObject) => void;
|
|
11
|
+
setLeftBarButtonItem: (sceneId: string, item: CodegenTypes.UnsafeObject | null) => void;
|
|
12
|
+
setRightBarButtonItem: (sceneId: string, item: CodegenTypes.UnsafeObject | null) => void;
|
|
13
|
+
setLeftBarButtonItems: (
|
|
14
|
+
sceneId: string,
|
|
15
|
+
items: Array<CodegenTypes.UnsafeObject> | null,
|
|
16
|
+
) => void;
|
|
17
|
+
setRightBarButtonItems: (
|
|
18
|
+
sceneId: string,
|
|
19
|
+
items: Array<CodegenTypes.UnsafeObject> | null,
|
|
20
|
+
) => void;
|
|
21
|
+
updateOptions: (sceneId: string, options: CodegenTypes.UnsafeObject) => void;
|
|
22
|
+
updateTabBar: (sceneId: string, item: CodegenTypes.UnsafeObject) => void;
|
|
23
|
+
setTabItem: (sceneId: string, item: Array<CodegenTypes.UnsafeObject>) => void;
|
|
24
|
+
setMenuInteractive: (sceneId: string, enabled: boolean) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('HBDNativeGarden');
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import type { CodegenTypes, TurboModule } from 'react-native';
|
|
3
|
+
|
|
4
|
+
type Error = {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type LayoutMode = 'modal' | 'present' | 'normal';
|
|
10
|
+
|
|
11
|
+
export interface Route {
|
|
12
|
+
sceneId: string;
|
|
13
|
+
moduleName: string;
|
|
14
|
+
mode: LayoutMode;
|
|
15
|
+
presentingId: string | null;
|
|
16
|
+
requestCode: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface RouteGraph {
|
|
20
|
+
layout: string;
|
|
21
|
+
sceneId: string;
|
|
22
|
+
mode: LayoutMode;
|
|
23
|
+
children?: RouteGraph[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type RouteMode = 'modal' | 'present' | 'push';
|
|
27
|
+
|
|
28
|
+
export interface RouteConfig {
|
|
29
|
+
path?: string;
|
|
30
|
+
dependency?: string;
|
|
31
|
+
mode?: RouteMode;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type ResultType = {} | null;
|
|
35
|
+
|
|
36
|
+
export interface Spec extends TurboModule {
|
|
37
|
+
getConstants: () => {
|
|
38
|
+
RESULT_OK: number;
|
|
39
|
+
RESULT_CANCEL: number;
|
|
40
|
+
RESULT_BLOCK: number;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
startRegisterReactComponent: () => void;
|
|
44
|
+
endRegisterReactComponent: () => void;
|
|
45
|
+
registerReactComponent: (appKey: string, options: CodegenTypes.UnsafeObject) => void;
|
|
46
|
+
signalFirstRenderComplete: (sceneId: string) => void;
|
|
47
|
+
setRoot: (
|
|
48
|
+
layout: CodegenTypes.UnsafeObject,
|
|
49
|
+
sticky: boolean,
|
|
50
|
+
callback: (error: Error | null, result: boolean) => void,
|
|
51
|
+
) => void;
|
|
52
|
+
setResult: (sceneId: string, resultCode: number, data: CodegenTypes.UnsafeObject) => void;
|
|
53
|
+
dispatch: (
|
|
54
|
+
sceneId: string,
|
|
55
|
+
action: string,
|
|
56
|
+
params: CodegenTypes.UnsafeObject,
|
|
57
|
+
callback: (error: Error | null, result: boolean) => void,
|
|
58
|
+
) => void;
|
|
59
|
+
currentTab: (sceneId: string, callback: (error: Error | null, index: number) => void) => void;
|
|
60
|
+
isStackRoot: (
|
|
61
|
+
sceneId: string,
|
|
62
|
+
callback: (error: Error | null, result: boolean) => void,
|
|
63
|
+
) => void;
|
|
64
|
+
findSceneIdByModuleName: (
|
|
65
|
+
moduleName: string,
|
|
66
|
+
callback: (error: Error | null, sceneId: string | null) => void,
|
|
67
|
+
) => void;
|
|
68
|
+
currentRoute: (callback: (error: Error | null, route: Route) => void) => void;
|
|
69
|
+
routeGraph: (callback: (error: Error | null, graph: RouteGraph[]) => void) => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('HBDNativeNavigation');
|
package/src/Navigation.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import {AppRegistry, ComponentProvider} from 'react-native';
|
|
2
|
+
import { AppRegistry, ComponentProvider } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
BarButtonItem,
|
|
@@ -9,24 +9,24 @@ import type {
|
|
|
9
9
|
TabItemInfo,
|
|
10
10
|
TitleItem,
|
|
11
11
|
} from './Options';
|
|
12
|
-
import type {BuildInLayout, Layout, Route, RouteGraph, RouteConfig} from './Route';
|
|
12
|
+
import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route';
|
|
13
13
|
|
|
14
14
|
import BarButtonEventHandler from './handler/BarButtonEventHandler';
|
|
15
15
|
import LayoutCommandHandler from './handler/LayoutCommandHandler';
|
|
16
16
|
import DispatchCommandHandler from './handler/DispatchCommandHandler';
|
|
17
|
-
import ResultEventHandler, {ResultType} from './handler/ResultEventHandler';
|
|
17
|
+
import ResultEventHandler, { ResultType } from './handler/ResultEventHandler';
|
|
18
18
|
import VisibilityEventHandler, {
|
|
19
19
|
GlobalVisibilityEventListener,
|
|
20
20
|
VisibilityEventListener,
|
|
21
21
|
} from './handler/VisibilityEventHandler';
|
|
22
22
|
|
|
23
|
-
import
|
|
24
|
-
import GardenModule from './GardenModule';
|
|
23
|
+
import NativeEvent from './NativeEvent';
|
|
25
24
|
import NavigationModule from './NavigationModule';
|
|
25
|
+
import GardenModule from './NativeGarden';
|
|
26
26
|
|
|
27
|
-
export type {ResultType} from './handler/ResultEventHandler';
|
|
28
|
-
import type {DispatchParams, NavigationInterceptor} from './handler/DispatchCommandHandler';
|
|
29
|
-
export type {DispatchParams, NavigationInterceptor} from './handler/DispatchCommandHandler';
|
|
27
|
+
export type { ResultType } from './handler/ResultEventHandler';
|
|
28
|
+
import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
29
|
+
export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
30
30
|
|
|
31
31
|
type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ type Nullable<T> = {
|
|
|
34
34
|
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const {RESULT_CANCEL, RESULT_OK, RESULT_BLOCK} = NavigationModule.getConstants();
|
|
37
|
+
export const { RESULT_CANCEL, RESULT_OK, RESULT_BLOCK } = NavigationModule.getConstants();
|
|
38
38
|
|
|
39
39
|
export type NavigationSubscription = {
|
|
40
40
|
remove: () => void;
|
|
@@ -187,8 +187,8 @@ class NavigationImpl implements Navigation {
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
private handleTabSwitch() {
|
|
190
|
-
|
|
191
|
-
this.dispatch(sceneId, 'switchTab', {from, to});
|
|
190
|
+
NativeEvent.onSwitchTab(({ sceneId, from, to }) => {
|
|
191
|
+
this.dispatch(sceneId, 'switchTab', { from, to });
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -265,12 +265,12 @@ class NavigationImpl implements Navigation {
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
268
|
-
const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
|
|
268
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems) as Array<{}> | null;
|
|
269
269
|
GardenModule.setLeftBarButtonItems(sceneId, options);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
273
|
-
const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
|
|
273
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems) as Array<{}> | null;
|
|
274
274
|
GardenModule.setRightBarButtonItems(sceneId, options);
|
|
275
275
|
}
|
|
276
276
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, {useEffect} from 'react';
|
|
2
|
-
import type {NavigationItem} from './Options';
|
|
3
|
-
import {Navigator, NavigationContext} from './Navigator';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import type { NavigationItem } from './Options';
|
|
3
|
+
import { Navigator, NavigationContext } from './Navigator';
|
|
4
4
|
import Navigation from './Navigation';
|
|
5
5
|
|
|
6
6
|
export interface NavigationProps {
|
|
@@ -20,7 +20,7 @@ export function withNavigation(moduleName: string) {
|
|
|
20
20
|
return function (WrappedComponent: React.ComponentType<any>) {
|
|
21
21
|
const FC = React.forwardRef(
|
|
22
22
|
(props: NativeProps, ref: React.Ref<React.ComponentType<any>>) => {
|
|
23
|
-
const {sceneId} = props;
|
|
23
|
+
const { sceneId } = props;
|
|
24
24
|
|
|
25
25
|
const navigator = Navigator.of(sceneId);
|
|
26
26
|
if (navigator.moduleName === undefined) {
|
package/src/NavigationModule.ts
CHANGED
|
@@ -1,58 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
type Callback = (error: never, result: any) => void;
|
|
5
|
-
|
|
6
|
-
interface NavigationModule {
|
|
7
|
-
getConstants: () => {
|
|
8
|
-
RESULT_OK: number;
|
|
9
|
-
RESULT_CANCEL: number;
|
|
10
|
-
RESULT_BLOCK: number;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
startRegisterReactComponent: () => void;
|
|
14
|
-
endRegisterReactComponent: () => void;
|
|
15
|
-
registerReactComponent: (appKey: string, options: object) => void;
|
|
16
|
-
signalFirstRenderComplete: (sceneId: string) => void;
|
|
17
|
-
setRoot: (layout: object, sticky: boolean, callback: Callback) => void;
|
|
18
|
-
setResult: (sceneId: string, resultCode: number, data: object | null) => void;
|
|
19
|
-
dispatch: (sceneId: string, action: string, params: object, callback: Callback) => void;
|
|
20
|
-
currentTab: (sceneId: string, callback: Callback) => void;
|
|
21
|
-
isStackRoot: (sceneId: string, callback: Callback) => void;
|
|
22
|
-
findSceneIdByModuleName: (moduleName: string, callback: Callback) => void;
|
|
23
|
-
currentRoute: (callback: Callback) => void;
|
|
24
|
-
routeGraph: (callback: Callback) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const NavigationModule: NavigationModule = NativeModules.NavigationModule;
|
|
1
|
+
import type { Route, RouteGraph, RouteConfig, ResultType } from './NativeNavigation';
|
|
2
|
+
import NativeNavigation from './NativeNavigation';
|
|
28
3
|
|
|
29
4
|
function getConstants() {
|
|
30
|
-
return
|
|
5
|
+
return NativeNavigation.getConstants();
|
|
31
6
|
}
|
|
32
7
|
|
|
33
8
|
function startRegisterReactComponent() {
|
|
34
|
-
|
|
9
|
+
NativeNavigation.startRegisterReactComponent();
|
|
35
10
|
}
|
|
36
11
|
|
|
37
12
|
function endRegisterReactComponent() {
|
|
38
|
-
|
|
13
|
+
NativeNavigation.endRegisterReactComponent();
|
|
39
14
|
}
|
|
40
15
|
|
|
41
|
-
function registerReactComponent(appKey: string, options:
|
|
42
|
-
|
|
16
|
+
function registerReactComponent(appKey: string, options: RouteConfig) {
|
|
17
|
+
NativeNavigation.registerReactComponent(appKey, options);
|
|
43
18
|
}
|
|
44
19
|
|
|
45
20
|
function signalFirstRenderComplete(sceneId: string) {
|
|
46
|
-
|
|
21
|
+
NativeNavigation.signalFirstRenderComplete(sceneId);
|
|
47
22
|
}
|
|
48
23
|
|
|
49
|
-
function setResult(sceneId: string, resultCode: number, data:
|
|
50
|
-
|
|
24
|
+
function setResult<T extends ResultType>(sceneId: string, resultCode: number, data: T) {
|
|
25
|
+
NativeNavigation.setResult(sceneId, resultCode, data as object);
|
|
51
26
|
}
|
|
52
27
|
|
|
53
28
|
function setRoot(layout: object, sticky: boolean) {
|
|
54
29
|
return new Promise<boolean>(resolve => {
|
|
55
|
-
|
|
30
|
+
NativeNavigation.setRoot(layout, sticky, (_, success) => {
|
|
56
31
|
resolve(success);
|
|
57
32
|
});
|
|
58
33
|
});
|
|
@@ -60,7 +35,7 @@ function setRoot(layout: object, sticky: boolean) {
|
|
|
60
35
|
|
|
61
36
|
function dispatch(sceneId: string, action: string, params: object) {
|
|
62
37
|
return new Promise<boolean>(resolve => {
|
|
63
|
-
|
|
38
|
+
NativeNavigation.dispatch(sceneId, action, params, (_, result) => {
|
|
64
39
|
resolve(result);
|
|
65
40
|
});
|
|
66
41
|
});
|
|
@@ -68,15 +43,15 @@ function dispatch(sceneId: string, action: string, params: object) {
|
|
|
68
43
|
|
|
69
44
|
function currentTab(sceneId: string) {
|
|
70
45
|
return new Promise<number>(resolve => {
|
|
71
|
-
|
|
72
|
-
resolve(
|
|
46
|
+
NativeNavigation.currentTab(sceneId, (_, index) => {
|
|
47
|
+
resolve(index);
|
|
73
48
|
});
|
|
74
49
|
});
|
|
75
50
|
}
|
|
76
51
|
|
|
77
52
|
function isStackRoot(sceneId: string) {
|
|
78
53
|
return new Promise<boolean>(resolve => {
|
|
79
|
-
|
|
54
|
+
NativeNavigation.isStackRoot(sceneId, (_, result) => {
|
|
80
55
|
resolve(result);
|
|
81
56
|
});
|
|
82
57
|
});
|
|
@@ -84,24 +59,24 @@ function isStackRoot(sceneId: string) {
|
|
|
84
59
|
|
|
85
60
|
function findSceneIdByModuleName(moduleName: string) {
|
|
86
61
|
return new Promise<string | null>(resolve => {
|
|
87
|
-
|
|
88
|
-
resolve(
|
|
62
|
+
NativeNavigation.findSceneIdByModuleName(moduleName, (_, sceneId) => {
|
|
63
|
+
resolve(sceneId);
|
|
89
64
|
});
|
|
90
65
|
});
|
|
91
66
|
}
|
|
92
67
|
|
|
93
68
|
function currentRoute() {
|
|
94
69
|
return new Promise<Route>(resolve => {
|
|
95
|
-
|
|
96
|
-
resolve(
|
|
70
|
+
NativeNavigation.currentRoute((_, route) => {
|
|
71
|
+
resolve(route);
|
|
97
72
|
});
|
|
98
73
|
});
|
|
99
74
|
}
|
|
100
75
|
|
|
101
76
|
function routeGraph() {
|
|
102
77
|
return new Promise<RouteGraph[]>(resolve => {
|
|
103
|
-
|
|
104
|
-
resolve(
|
|
78
|
+
NativeNavigation.routeGraph((_, graph) => {
|
|
79
|
+
resolve(graph);
|
|
105
80
|
});
|
|
106
81
|
});
|
|
107
82
|
}
|
package/src/Navigator.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {createContext} from 'react';
|
|
1
|
+
import { createContext } from 'react';
|
|
2
2
|
|
|
3
3
|
import store from './store';
|
|
4
|
-
import type {Visibility, Layout, BuildInLayout} from './Route';
|
|
5
|
-
import type {NavigationItem} from './Options';
|
|
6
|
-
import Navigation, {ResultType, RESULT_BLOCK} from './Navigation';
|
|
4
|
+
import type { Visibility, Layout, BuildInLayout } from './Route';
|
|
5
|
+
import type { NavigationItem } from './Options';
|
|
6
|
+
import Navigation, { ResultType, RESULT_BLOCK } from './Navigation';
|
|
7
7
|
|
|
8
8
|
export const NavigationContext = createContext<any>(null);
|
|
9
9
|
|
|
10
10
|
interface NavigationState {
|
|
11
|
-
params: {readonly [index: string]: any};
|
|
11
|
+
params: { readonly [index: string]: any };
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
interface PropsType {
|
|
@@ -66,8 +66,8 @@ export class Navigator implements Navigator {
|
|
|
66
66
|
params: {},
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
-
setParams = (params: {[index: string]: any}) => {
|
|
70
|
-
this.state.params = {...this.state.params, ...params};
|
|
69
|
+
setParams = (params: { [index: string]: any }) => {
|
|
70
|
+
this.state.params = { ...this.state.params, ...params };
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
push = async <T extends ResultType, P extends PropsType = {}>(
|
|
@@ -99,7 +99,7 @@ export class Navigator implements Navigator {
|
|
|
99
99
|
return Navigation.result<T>(this.sceneId, 0);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
pop = () => Navigation.dispatch(this.sceneId, 'pop', {from: this.moduleName});
|
|
102
|
+
pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName });
|
|
103
103
|
|
|
104
104
|
popTo = (moduleName: string, inclusive: boolean = false) =>
|
|
105
105
|
Navigation.dispatch(this.sceneId, 'popTo', {
|
|
@@ -109,7 +109,7 @@ export class Navigator implements Navigator {
|
|
|
109
109
|
to: moduleName,
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', {from: this.moduleName});
|
|
112
|
+
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
|
|
113
113
|
|
|
114
114
|
redirectTo = <P extends PropsType>(
|
|
115
115
|
moduleName: string,
|
|
@@ -163,7 +163,7 @@ export class Navigator implements Navigator {
|
|
|
163
163
|
return Navigation.result<T>(this.sceneId, requestCode);
|
|
164
164
|
};
|
|
165
165
|
|
|
166
|
-
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', {from: this.moduleName});
|
|
166
|
+
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
167
167
|
|
|
168
168
|
showModal = async <T extends ResultType, P extends PropsType = {}>(
|
|
169
169
|
moduleName: string,
|
|
@@ -204,7 +204,7 @@ export class Navigator implements Navigator {
|
|
|
204
204
|
return Navigation.result<T>(this.sceneId, requestCode);
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', {from: this.moduleName});
|
|
207
|
+
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
|
|
208
208
|
|
|
209
209
|
setResult = <T extends ResultType>(resultCode: number, data: T = null as any): void =>
|
|
210
210
|
Navigation.setResult(this.sceneId, resultCode, data);
|
|
@@ -223,9 +223,9 @@ export class Navigator implements Navigator {
|
|
|
223
223
|
from: this.moduleName,
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
-
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', {from: this.moduleName});
|
|
226
|
+
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
|
|
227
227
|
|
|
228
|
-
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', {from: this.moduleName});
|
|
228
|
+
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
|
|
229
229
|
|
|
230
230
|
isStackRoot = () => Navigation.isStackRoot(this.sceneId);
|
|
231
231
|
}
|
package/src/Options.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {Navigator} from './Navigator';
|
|
1
|
+
import type { Navigator } from './Navigator';
|
|
3
2
|
|
|
4
3
|
export type Color = string;
|
|
5
4
|
export type ImageSource = {
|
|
@@ -59,14 +58,12 @@ export interface NavigationItem extends NavigationOption {
|
|
|
59
58
|
rightBarButtonItem?: BarButtonItem;
|
|
60
59
|
leftBarButtonItems?: BarButtonItem[];
|
|
61
60
|
rightBarButtonItems?: BarButtonItem[];
|
|
62
|
-
backItemIOS?: BackItem;
|
|
63
61
|
tabItem?: TabItem;
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
export interface BarButtonItem {
|
|
67
65
|
title?: string;
|
|
68
66
|
icon?: ImageSource;
|
|
69
|
-
insetsIOS?: Insets;
|
|
70
67
|
action?: (navigator: Navigator) => void;
|
|
71
68
|
enabled?: boolean;
|
|
72
69
|
tintColor?: Color;
|
|
@@ -122,16 +119,19 @@ export interface DefaultOptions {
|
|
|
122
119
|
fitsOpaqueNavigationBarAndroid?: boolean; // 适配不透明的导航栏边衬区,默认为 true
|
|
123
120
|
displayCutoutWhenLandscapeAndroid?: boolean; // 横屏时,是否将界面延伸至刘海区域,默认 true
|
|
124
121
|
|
|
125
|
-
|
|
126
|
-
tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
tabBarBackgroundColor?: Color; // 底部 TabBar 背景颜色,请勿使用带透明度的颜色。
|
|
123
|
+
tabBarShadowImage?: ShadowImage; // 底部 TabBar 阴影图片。对于 iOS, 只有同时设置了 tabBarBackgroundColor 才会生效
|
|
124
|
+
tabBarItemSelectedColor?: Color; // 底部 TabBarItem icon 选中颜色
|
|
125
|
+
tabBarItemNormalColor?: Color; // 底部 TabBarItem icon 未选中颜色,默认为 #666666
|
|
129
126
|
tabBarBadgeColor?: Color; // Tab badge 颜色
|
|
130
127
|
}
|
|
131
128
|
|
|
132
129
|
export type TabBarStyle = Pick<
|
|
133
130
|
DefaultOptions,
|
|
134
|
-
|
|
131
|
+
| 'tabBarBackgroundColor'
|
|
132
|
+
| 'tabBarShadowImage'
|
|
133
|
+
| 'tabBarItemSelectedColor'
|
|
134
|
+
| 'tabBarItemNormalColor'
|
|
135
135
|
>;
|
|
136
136
|
|
|
137
137
|
export interface TabItemInfo {
|
package/src/Route.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import NativeEvent from '../NativeEvent';
|
|
2
2
|
|
|
3
3
|
type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
|
|
4
4
|
|
|
@@ -7,10 +7,7 @@ export default class BarButtonEventHandler {
|
|
|
7
7
|
private keyPairs: Record<string, string[]> = {};
|
|
8
8
|
private actionIdGenerator = 0;
|
|
9
9
|
|
|
10
|
-
bindBarButtonClickEvent(
|
|
11
|
-
sceneId: string,
|
|
12
|
-
item: object | null | undefined,
|
|
13
|
-
): object | null {
|
|
10
|
+
bindBarButtonClickEvent(sceneId: string, item: object | null | undefined): object | null {
|
|
14
11
|
if (item === null || item === undefined) {
|
|
15
12
|
return null;
|
|
16
13
|
}
|
|
@@ -21,8 +18,7 @@ export default class BarButtonEventHandler {
|
|
|
21
18
|
return value;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
const actionKey =
|
|
25
|
-
'ON_BAR_BUTTON_ITEM_CLICK_' + this.actionIdGenerator++;
|
|
21
|
+
const actionKey = 'ON_BAR_BUTTON_ITEM_CLICK_' + this.actionIdGenerator++;
|
|
26
22
|
|
|
27
23
|
if (!this.keyPairs[sceneId]) {
|
|
28
24
|
this.keyPairs[sceneId] = [];
|
|
@@ -44,7 +40,7 @@ export default class BarButtonEventHandler {
|
|
|
44
40
|
}
|
|
45
41
|
|
|
46
42
|
setBarButtonClickEventListener(handler: BarButtonClickEventListener) {
|
|
47
|
-
|
|
43
|
+
NativeEvent.onBarButtonItemClick(({ sceneId, action }) => {
|
|
48
44
|
const listeners = this.actions;
|
|
49
45
|
if (listeners[action]) {
|
|
50
46
|
handler(sceneId, listeners[action]);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import NavigationModule from '../NavigationModule';
|
|
2
|
-
import {NavigationItem} from '../Options';
|
|
3
|
-
import {BuildInLayout, Layout} from '../Route';
|
|
2
|
+
import { NavigationItem } from '../Options';
|
|
3
|
+
import { BuildInLayout, Layout } from '../Route';
|
|
4
4
|
|
|
5
5
|
export interface DispatchParams {
|
|
6
6
|
animated?: boolean;
|
|
@@ -30,12 +30,8 @@ export type NavigationInterceptor = (
|
|
|
30
30
|
export default class DispatchCommandHandler {
|
|
31
31
|
private interceptor: NavigationInterceptor = () => false;
|
|
32
32
|
|
|
33
|
-
async dispatch(
|
|
34
|
-
|
|
35
|
-
action: string,
|
|
36
|
-
params: DispatchParams,
|
|
37
|
-
): Promise<boolean> {
|
|
38
|
-
const {from, to, props} = params;
|
|
33
|
+
async dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean> {
|
|
34
|
+
const { from, to, props } = params;
|
|
39
35
|
const intercepted = await this.intercept(action, {
|
|
40
36
|
sceneId,
|
|
41
37
|
from,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Event from '../Event';
|
|
2
1
|
import NavigationModule from '../NavigationModule';
|
|
3
|
-
import {BuildInLayout, Layout} from '../Route';
|
|
2
|
+
import { BuildInLayout, Layout } from '../Route';
|
|
3
|
+
import NativeEvent from '../NativeEvent';
|
|
4
4
|
|
|
5
5
|
export default class LayoutCommandHandler {
|
|
6
6
|
private willSetRoot = () => {};
|
|
@@ -9,11 +9,10 @@ export default class LayoutCommandHandler {
|
|
|
9
9
|
constructor() {}
|
|
10
10
|
|
|
11
11
|
handleRootLayoutChange() {
|
|
12
|
-
|
|
12
|
+
NativeEvent.willSetRoot(() => {
|
|
13
13
|
this.willSetRoot();
|
|
14
14
|
});
|
|
15
|
-
|
|
16
|
-
Event.listenDidSetRoot(() => {
|
|
15
|
+
NativeEvent.didSetRoot(() => {
|
|
17
16
|
this.didSetRoot();
|
|
18
17
|
});
|
|
19
18
|
}
|