hybrid-navigation 2.18.3 → 2.18.4
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/LICENSE +1 -1
- package/{lib → dist}/Navigation.js +3 -2
- package/{lib → dist}/NavigationComponentWrap.js +6 -5
- package/{lib → dist}/Navigator.d.ts +0 -1
- package/{lib → dist}/Navigator.js +15 -4
- package/{lib → dist}/hooks.js +2 -1
- package/{lib → dist}/router/index.js +6 -2
- package/{lib → dist}/router/stack.js +1 -1
- package/ios/HybridNavigation/HBDUtils.h +2 -0
- package/ios/HybridNavigation/HBDUtils.m +12 -3
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +2 -6
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +11 -12
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +1 -1
- package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
- package/package.json +47 -78
- package/src/DeepLink.ts +52 -52
- package/src/Event.ts +88 -83
- package/src/GardenModule.ts +30 -30
- package/src/Navigation.ts +293 -281
- package/src/NavigationComponentWrap.tsx +52 -47
- package/src/NavigationModule.ts +77 -77
- package/src/Navigator.ts +212 -201
- package/src/Options.ts +120 -112
- package/src/Route.ts +59 -59
- package/src/handler/BarButtonEventHandler.ts +50 -46
- package/src/handler/DispatchCommandHandler.ts +56 -52
- package/src/handler/LayoutCommandHandler.ts +21 -21
- package/src/handler/ResultEventHandler.ts +63 -49
- package/src/handler/VisibilityEventHandler.ts +57 -40
- package/src/hooks.ts +23 -21
- package/src/index.ts +15 -15
- package/src/router/drawer.ts +24 -24
- package/src/router/index.ts +206 -198
- package/src/router/screen.ts +28 -28
- package/src/router/stack.ts +76 -76
- package/src/router/tabs.ts +28 -28
- package/src/store.ts +9 -9
- package/README.md +0 -79
- /package/{lib → dist}/DeepLink.d.ts +0 -0
- /package/{lib → dist}/DeepLink.js +0 -0
- /package/{lib → dist}/Event.d.ts +0 -0
- /package/{lib → dist}/Event.js +0 -0
- /package/{lib → dist}/GardenModule.d.ts +0 -0
- /package/{lib → dist}/GardenModule.js +0 -0
- /package/{lib → dist}/Navigation.d.ts +0 -0
- /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
- /package/{lib → dist}/NavigationModule.d.ts +0 -0
- /package/{lib → dist}/NavigationModule.js +0 -0
- /package/{lib → dist}/Options.d.ts +0 -0
- /package/{lib → dist}/Options.js +0 -0
- /package/{lib → dist}/Route.d.ts +0 -0
- /package/{lib → dist}/Route.js +0 -0
- /package/{lib → dist}/handler/BarButtonEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/BarButtonEventHandler.js +0 -0
- /package/{lib → dist}/handler/DispatchCommandHandler.d.ts +0 -0
- /package/{lib → dist}/handler/DispatchCommandHandler.js +0 -0
- /package/{lib → dist}/handler/LayoutCommandHandler.d.ts +0 -0
- /package/{lib → dist}/handler/LayoutCommandHandler.js +0 -0
- /package/{lib → dist}/handler/ResultEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/ResultEventHandler.js +0 -0
- /package/{lib → dist}/handler/VisibilityEventHandler.d.ts +0 -0
- /package/{lib → dist}/handler/VisibilityEventHandler.js +0 -0
- /package/{lib → dist}/hooks.d.ts +0 -0
- /package/{lib → dist}/index.d.ts +0 -0
- /package/{lib → dist}/index.js +0 -0
- /package/{lib → dist}/router/drawer.d.ts +0 -0
- /package/{lib → dist}/router/drawer.js +0 -0
- /package/{lib → dist}/router/index.d.ts +0 -0
- /package/{lib → dist}/router/screen.d.ts +0 -0
- /package/{lib → dist}/router/screen.js +0 -0
- /package/{lib → dist}/router/stack.d.ts +0 -0
- /package/{lib → dist}/router/tabs.d.ts +0 -0
- /package/{lib → dist}/router/tabs.js +0 -0
- /package/{lib → dist}/store.d.ts +0 -0
- /package/{lib → dist}/store.js +0 -0
package/src/router/stack.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import Navigation from '../Navigation'
|
|
1
|
+
import {ScreenGraph, isScreenGraph, isTargetLocateIn} from './screen';
|
|
2
|
+
import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
|
|
3
|
+
import Navigation from '../Navigation';
|
|
4
4
|
|
|
5
5
|
export interface StackGraph extends RouteGraph {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
layout: 'stack';
|
|
7
|
+
sceneId: string;
|
|
8
|
+
mode: LayoutMode;
|
|
9
|
+
children: RouteGraph[];
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function isStackGraph(graph: RouteGraph): graph is StackGraph {
|
|
13
|
-
|
|
13
|
+
return graph.layout === 'stack';
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export class StackRouteHandler implements RouteHandler {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]> {
|
|
18
|
+
if (!isStackGraph(graph)) {
|
|
19
|
+
throw new Error(`${graph} is Not a StackGraph`);
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const {children} = graph;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
for (let i = children.length - 1; i > -1; i--) {
|
|
25
|
+
const childGraph = children[i];
|
|
26
|
+
if (isTargetLocateIn(childGraph, target)) {
|
|
27
|
+
if (isScreenGraph(childGraph)) {
|
|
28
|
+
this.navigateTo(childGraph, target);
|
|
29
|
+
return [true, null];
|
|
30
|
+
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
await this.popToIfNeeded(childGraph, i === children.length - 1);
|
|
33
|
+
return [true, childGraph];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
return [false, graph];
|
|
38
|
+
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
private async popToIfNeeded(childGraph: RouteGraph, isLastChildAtStack: boolean) {
|
|
41
|
+
if (!isLastChildAtStack) {
|
|
42
|
+
await Navigation.dispatch(childGraph.sceneId, 'popTo', {
|
|
43
|
+
moduleName: childGraph.sceneId,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
private navigateTo(childGraph: ScreenGraph, target: RouteInfo) {
|
|
49
|
+
const {moduleName, dependencies, props} = target;
|
|
50
|
+
const expectations = [...dependencies, moduleName];
|
|
51
|
+
const index = expectations.findIndex(name => name === childGraph.moduleName);
|
|
52
|
+
const pendings = expectations.slice(index + 1);
|
|
53
|
+
console.log('pendings', pendings, 'moduleName', childGraph.moduleName);
|
|
54
|
+
const sceneId = childGraph.sceneId;
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
const moduleExisting = pendings.length === 0;
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
58
|
+
if (moduleExisting) {
|
|
59
|
+
if (JSON.stringify(props) === '{}') {
|
|
60
|
+
Navigation.dispatch(sceneId, 'popTo', {
|
|
61
|
+
moduleName,
|
|
62
|
+
from: childGraph.moduleName,
|
|
63
|
+
to: moduleName,
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
Navigation.dispatch(sceneId, 'redirectTo', {
|
|
67
|
+
moduleName,
|
|
68
|
+
from: childGraph.moduleName,
|
|
69
|
+
to: moduleName,
|
|
70
|
+
props,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
for (let i = 0; i < pendings.length; i++) {
|
|
75
|
+
const isLast = i === pendings.length - 1;
|
|
76
|
+
if (isLast) {
|
|
77
|
+
Navigation.dispatch(sceneId, 'push', {
|
|
78
|
+
moduleName,
|
|
79
|
+
from: childGraph.moduleName,
|
|
80
|
+
to: moduleName,
|
|
81
|
+
props,
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
Navigation.dispatch(sceneId, 'push', {
|
|
85
|
+
moduleName: pendings[i],
|
|
86
|
+
from: childGraph.moduleName,
|
|
87
|
+
to: pendings[i],
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
93
|
}
|
package/src/router/tabs.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import Navigation from '../Navigation'
|
|
1
|
+
import {isTargetLocateIn} from './screen';
|
|
2
|
+
import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
|
|
3
|
+
import Navigation from '../Navigation';
|
|
4
4
|
|
|
5
5
|
export interface TabsGraph extends RouteGraph {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
layout: 'tabs';
|
|
7
|
+
sceneId: string;
|
|
8
|
+
selectedIndex: number;
|
|
9
|
+
mode: LayoutMode;
|
|
10
|
+
children: RouteGraph[];
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function isTabsGraph(graph: RouteGraph): graph is TabsGraph {
|
|
14
|
-
|
|
14
|
+
return graph.layout === 'tabs';
|
|
15
15
|
}
|
|
16
16
|
export class TabsRouteHandler implements RouteHandler {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph]> {
|
|
18
|
+
if (!isTabsGraph(graph)) {
|
|
19
|
+
throw new Error(`${graph} is NOT a TabsGraph`);
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const {children, selectedIndex} = graph;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
for (let i = 0; i < children.length; i++) {
|
|
25
|
+
if (isTargetLocateIn(children[i], target)) {
|
|
26
|
+
if (selectedIndex !== i) {
|
|
27
|
+
await Navigation.dispatch(children[selectedIndex].sceneId, 'switchTab', {
|
|
28
|
+
from: selectedIndex,
|
|
29
|
+
to: i,
|
|
30
|
+
popToRoot: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return [true, children[i]];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
return [false, graph];
|
|
38
|
+
}
|
|
39
39
|
}
|
package/src/store.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Navigator} from './Navigator';
|
|
2
2
|
|
|
3
|
-
const navigators = new Map<string, Navigator>()
|
|
3
|
+
const navigators = new Map<string, Navigator>();
|
|
4
4
|
|
|
5
5
|
function addNavigator(sceneId: string, navigator: Navigator) {
|
|
6
|
-
|
|
6
|
+
navigators.set(sceneId, navigator);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
function removeNavigator(sceneId: string) {
|
|
10
|
-
|
|
10
|
+
navigators.delete(sceneId);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
function getNavigator(sceneId: string) {
|
|
14
|
-
|
|
14
|
+
return navigators.get(sceneId);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export default {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
18
|
+
addNavigator,
|
|
19
|
+
removeNavigator,
|
|
20
|
+
getNavigator,
|
|
21
|
+
};
|
package/README.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# hybrid-navigation
|
|
2
|
-
|
|
3
|
-
React Native Navigation that supports seamless navigation between Native and React.
|
|
4
|
-
|
|
5
|
-
## 特性
|
|
6
|
-
|
|
7
|
-
- 使用原生导航组件实现 React Native 页面间的导航,不仅具有更优的性能,而且使得 RN 页面具有原生质感
|
|
8
|
-
- 原生页面和 RN 页面共享路由, 使得它们之间相互跳转和传值轻而易举
|
|
9
|
-
- 内置 drawer, tabs, stack 标准容器,同时支持自定义容器和导航
|
|
10
|
-
- 支持 Deep Link
|
|
11
|
-
|
|
12
|
-

|
|
13
|
-
|
|
14
|
-
## Support
|
|
15
|
-
|
|
16
|
-
| version | react-native version |
|
|
17
|
-
| ------- | -------------------- |
|
|
18
|
-
| 1.0.0+ | 0.60.0+ |
|
|
19
|
-
|
|
20
|
-
## 运行 example 项目
|
|
21
|
-
|
|
22
|
-
首先 clone 本项目
|
|
23
|
-
|
|
24
|
-
```shell
|
|
25
|
-
git clone git@github.com:listenzz/hybrid-navigation.git
|
|
26
|
-
cd hybrid-navigation
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
然后在项目根目录下运行如下命令:
|
|
30
|
-
|
|
31
|
-
```shell
|
|
32
|
-
yarn install
|
|
33
|
-
# &
|
|
34
|
-
yarn start
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### 在 Android 上运行
|
|
38
|
-
|
|
39
|
-
首先,确保你有一个模拟器或设备
|
|
40
|
-
|
|
41
|
-
如果熟悉原生开发,使用 Android Studio 打开 example/android,像运行原生应用那样运行它,也可以使用命令行:
|
|
42
|
-
|
|
43
|
-
```sh
|
|
44
|
-
# 在项目根目录下运行
|
|
45
|
-
yarn android
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
你可能需要运行如下命令,才可以使用 Hot Reload 功能
|
|
49
|
-
|
|
50
|
-
```sh
|
|
51
|
-
adb reverse tcp:8081 tcp:8081
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
[**Download demo apk**](https://todoit.oss-cn-shanghai.aliyuncs.com/app-release.apk)
|
|
55
|
-
|
|
56
|
-
或通过扫描二维码安装 demo
|
|
57
|
-
|
|
58
|
-

|
|
59
|
-
|
|
60
|
-
### 在 iOS 上运行
|
|
61
|
-
|
|
62
|
-
首先安装 cocoapods 依赖,在项目根目录下运行如下命令:
|
|
63
|
-
|
|
64
|
-
```sh
|
|
65
|
-
cd example/ios && pod install
|
|
66
|
-
# 成功安装依赖后,回到根目录
|
|
67
|
-
cd -
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
如果熟悉原生开发,使用 Xcode 打开 example/ios,像运行原生应用那样运行它,或者使用命令行:
|
|
71
|
-
|
|
72
|
-
```sh
|
|
73
|
-
# 在项目根目录下运行
|
|
74
|
-
yarn ios
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## 文档
|
|
78
|
-
|
|
79
|
-
[从这里开始](https://todoit.tech/rn/hybrid-navigation/)
|
|
File without changes
|
|
File without changes
|
/package/{lib → dist}/Event.d.ts
RENAMED
|
File without changes
|
/package/{lib → dist}/Event.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{lib → dist}/Options.js
RENAMED
|
File without changes
|
/package/{lib → dist}/Route.d.ts
RENAMED
|
File without changes
|
/package/{lib → dist}/Route.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{lib → dist}/hooks.d.ts
RENAMED
|
File without changes
|
/package/{lib → dist}/index.d.ts
RENAMED
|
File without changes
|
/package/{lib → dist}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{lib → dist}/store.d.ts
RENAMED
|
File without changes
|
/package/{lib → dist}/store.js
RENAMED
|
File without changes
|