hybrid-navigation 2.18.3 → 2.18.5

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.
Files changed (78) hide show
  1. package/LICENSE +1 -1
  2. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +4 -54
  3. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +0 -3
  4. package/{lib → dist}/Navigation.js +3 -2
  5. package/{lib → dist}/NavigationComponentWrap.js +6 -5
  6. package/{lib → dist}/Navigator.d.ts +0 -1
  7. package/{lib → dist}/Navigator.js +15 -4
  8. package/{lib → dist}/hooks.js +2 -1
  9. package/{lib → dist}/router/index.js +6 -2
  10. package/{lib → dist}/router/stack.js +1 -1
  11. package/ios/HybridNavigation/HBDUtils.h +2 -0
  12. package/ios/HybridNavigation/HBDUtils.m +12 -3
  13. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +2 -6
  14. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +11 -12
  15. package/ios/HybridNavigation/ViewController/HBDDrawerController.m +1 -1
  16. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +1 -1
  17. package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
  18. package/package.json +47 -78
  19. package/src/DeepLink.ts +52 -52
  20. package/src/Event.ts +88 -83
  21. package/src/GardenModule.ts +30 -30
  22. package/src/Navigation.ts +293 -281
  23. package/src/NavigationComponentWrap.tsx +52 -47
  24. package/src/NavigationModule.ts +77 -77
  25. package/src/Navigator.ts +212 -201
  26. package/src/Options.ts +120 -112
  27. package/src/Route.ts +59 -59
  28. package/src/handler/BarButtonEventHandler.ts +50 -46
  29. package/src/handler/DispatchCommandHandler.ts +56 -52
  30. package/src/handler/LayoutCommandHandler.ts +21 -21
  31. package/src/handler/ResultEventHandler.ts +63 -49
  32. package/src/handler/VisibilityEventHandler.ts +57 -40
  33. package/src/hooks.ts +23 -21
  34. package/src/index.ts +15 -15
  35. package/src/router/drawer.ts +24 -24
  36. package/src/router/index.ts +206 -198
  37. package/src/router/screen.ts +28 -28
  38. package/src/router/stack.ts +76 -76
  39. package/src/router/tabs.ts +28 -28
  40. package/src/store.ts +9 -9
  41. package/README.md +0 -79
  42. /package/{lib → dist}/DeepLink.d.ts +0 -0
  43. /package/{lib → dist}/DeepLink.js +0 -0
  44. /package/{lib → dist}/Event.d.ts +0 -0
  45. /package/{lib → dist}/Event.js +0 -0
  46. /package/{lib → dist}/GardenModule.d.ts +0 -0
  47. /package/{lib → dist}/GardenModule.js +0 -0
  48. /package/{lib → dist}/Navigation.d.ts +0 -0
  49. /package/{lib → dist}/NavigationComponentWrap.d.ts +0 -0
  50. /package/{lib → dist}/NavigationModule.d.ts +0 -0
  51. /package/{lib → dist}/NavigationModule.js +0 -0
  52. /package/{lib → dist}/Options.d.ts +0 -0
  53. /package/{lib → dist}/Options.js +0 -0
  54. /package/{lib → dist}/Route.d.ts +0 -0
  55. /package/{lib → dist}/Route.js +0 -0
  56. /package/{lib → dist}/handler/BarButtonEventHandler.d.ts +0 -0
  57. /package/{lib → dist}/handler/BarButtonEventHandler.js +0 -0
  58. /package/{lib → dist}/handler/DispatchCommandHandler.d.ts +0 -0
  59. /package/{lib → dist}/handler/DispatchCommandHandler.js +0 -0
  60. /package/{lib → dist}/handler/LayoutCommandHandler.d.ts +0 -0
  61. /package/{lib → dist}/handler/LayoutCommandHandler.js +0 -0
  62. /package/{lib → dist}/handler/ResultEventHandler.d.ts +0 -0
  63. /package/{lib → dist}/handler/ResultEventHandler.js +0 -0
  64. /package/{lib → dist}/handler/VisibilityEventHandler.d.ts +0 -0
  65. /package/{lib → dist}/handler/VisibilityEventHandler.js +0 -0
  66. /package/{lib → dist}/hooks.d.ts +0 -0
  67. /package/{lib → dist}/index.d.ts +0 -0
  68. /package/{lib → dist}/index.js +0 -0
  69. /package/{lib → dist}/router/drawer.d.ts +0 -0
  70. /package/{lib → dist}/router/drawer.js +0 -0
  71. /package/{lib → dist}/router/index.d.ts +0 -0
  72. /package/{lib → dist}/router/screen.d.ts +0 -0
  73. /package/{lib → dist}/router/screen.js +0 -0
  74. /package/{lib → dist}/router/stack.d.ts +0 -0
  75. /package/{lib → dist}/router/tabs.d.ts +0 -0
  76. /package/{lib → dist}/router/tabs.js +0 -0
  77. /package/{lib → dist}/store.d.ts +0 -0
  78. /package/{lib → dist}/store.js +0 -0
@@ -1,29 +1,29 @@
1
- import Event from '../Event'
2
- import NavigationModule from '../NavigationModule'
3
- import { BuildInLayout, Layout } from '../Route'
1
+ import Event from '../Event';
2
+ import NavigationModule from '../NavigationModule';
3
+ import {BuildInLayout, Layout} from '../Route';
4
4
 
5
5
  export default class LayoutCommandHandler {
6
- private willSetRoot = () => {}
7
- private didSetRoot = () => {}
6
+ private willSetRoot = () => {};
7
+ private didSetRoot = () => {};
8
8
 
9
- constructor() {}
9
+ constructor() {}
10
10
 
11
- handleRootLayoutChange() {
12
- Event.listenWillSetRoot(() => {
13
- this.willSetRoot()
14
- })
11
+ handleRootLayoutChange() {
12
+ Event.listenWillSetRoot(() => {
13
+ this.willSetRoot();
14
+ });
15
15
 
16
- Event.listenDidSetRoot(() => {
17
- this.didSetRoot()
18
- })
19
- }
16
+ Event.listenDidSetRoot(() => {
17
+ this.didSetRoot();
18
+ });
19
+ }
20
20
 
21
- setRoot(layout: BuildInLayout | Layout, sticky = false) {
22
- return NavigationModule.setRoot(layout, sticky)
23
- }
21
+ setRoot(layout: BuildInLayout | Layout, sticky = false) {
22
+ return NavigationModule.setRoot(layout, sticky);
23
+ }
24
24
 
25
- setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
26
- this.willSetRoot = willSetRoot
27
- this.didSetRoot = didSetRoot
28
- }
25
+ setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
26
+ this.willSetRoot = willSetRoot;
27
+ this.didSetRoot = didSetRoot;
28
+ }
29
29
  }
@@ -1,64 +1,78 @@
1
- import Event from '../Event'
1
+ import Event from '../Event';
2
2
 
3
3
  interface IndexType {
4
- [index: string]: any
4
+ [index: string]: any;
5
5
  }
6
6
 
7
- export type ResultType = IndexType | null
8
- export type ResultEventListener<T extends ResultType> = (resultCode: number, data: T) => void
7
+ export type ResultType = IndexType | null;
8
+ export type ResultEventListener<T extends ResultType> = (
9
+ resultCode: number,
10
+ data: T,
11
+ ) => void;
9
12
 
10
13
  export default class ResultEventHandler {
11
- private listenerRecords: Record<string, Record<number, Array<ResultEventListener<any>>>> = {}
14
+ private listenerRecords: Record<
15
+ string,
16
+ Record<number, Array<ResultEventListener<any>>>
17
+ > = {};
12
18
 
13
- constructor() {}
19
+ constructor() {}
14
20
 
15
- handleComponentResult() {
16
- Event.listenComponentResult(
17
- (sceneId: string, requestCode: number, resultCode: number, data: any) => {
18
- const listeners = this.listenerRecords[sceneId]?.[requestCode]
19
- if (listeners) {
20
- delete this.listenerRecords[sceneId][requestCode]
21
- listeners.forEach(l => l(resultCode, data))
22
- }
23
- },
24
- )
25
- }
21
+ handleComponentResult() {
22
+ Event.listenComponentResult(
23
+ (
24
+ sceneId: string,
25
+ requestCode: number,
26
+ resultCode: number,
27
+ data: any,
28
+ ) => {
29
+ const listeners = this.listenerRecords[sceneId]?.[requestCode];
30
+ if (listeners) {
31
+ delete this.listenerRecords[sceneId][requestCode];
32
+ listeners.forEach(l => l(resultCode, data));
33
+ }
34
+ },
35
+ );
36
+ }
26
37
 
27
- private addResultEventListener(
28
- sceneId: string,
29
- requestCode: number,
30
- listener: ResultEventListener<any>,
31
- ) {
32
- if (!this.listenerRecords[sceneId]) {
33
- this.listenerRecords[sceneId] = {}
34
- }
38
+ private addResultEventListener(
39
+ sceneId: string,
40
+ requestCode: number,
41
+ listener: ResultEventListener<any>,
42
+ ) {
43
+ if (!this.listenerRecords[sceneId]) {
44
+ this.listenerRecords[sceneId] = {};
45
+ }
35
46
 
36
- if (!this.listenerRecords[sceneId][requestCode]) {
37
- this.listenerRecords[sceneId][requestCode] = []
38
- }
47
+ if (!this.listenerRecords[sceneId][requestCode]) {
48
+ this.listenerRecords[sceneId][requestCode] = [];
49
+ }
39
50
 
40
- this.listenerRecords[sceneId][requestCode].push(listener)
41
- }
51
+ this.listenerRecords[sceneId][requestCode].push(listener);
52
+ }
42
53
 
43
- private removeResultEventListener(sceneId: string, requestCode: number) {
44
- if (this.listenerRecords[sceneId]) {
45
- delete this.listenerRecords[sceneId][requestCode]
46
- }
47
- }
54
+ private removeResultEventListener(sceneId: string, requestCode: number) {
55
+ if (this.listenerRecords[sceneId]) {
56
+ delete this.listenerRecords[sceneId][requestCode];
57
+ }
58
+ }
48
59
 
49
- invalidateResultEventListener(sceneId: string) {
50
- if (this.listenerRecords[sceneId]) {
51
- delete this.listenerRecords[sceneId]
52
- }
53
- }
60
+ invalidateResultEventListener(sceneId: string) {
61
+ if (this.listenerRecords[sceneId]) {
62
+ delete this.listenerRecords[sceneId];
63
+ }
64
+ }
54
65
 
55
- waitResult<T extends ResultType>(sceneId: string, requestCode: number): Promise<[number, T]> {
56
- return new Promise<[number, T]>(resolve => {
57
- const listener = (resultCode: number, data: T) => {
58
- this.removeResultEventListener(sceneId, requestCode)
59
- resolve([resultCode, data])
60
- }
61
- this.addResultEventListener(sceneId, requestCode, listener)
62
- })
63
- }
66
+ waitResult<T extends ResultType>(
67
+ sceneId: string,
68
+ requestCode: number,
69
+ ): Promise<[number, T]> {
70
+ return new Promise<[number, T]>(resolve => {
71
+ const listener = (resultCode: number, data: T) => {
72
+ this.removeResultEventListener(sceneId, requestCode);
73
+ resolve([resultCode, data]);
74
+ };
75
+ this.addResultEventListener(sceneId, requestCode, listener);
76
+ });
77
+ }
64
78
  }
@@ -1,44 +1,61 @@
1
- import { Visibility } from '../Route'
2
- import Event from '../Event'
1
+ import {Visibility} from '../Route';
2
+ import Event from '../Event';
3
3
 
4
- export type VisibilityEventListener = (visibility: Visibility) => void
5
- export type GlobalVisibilityEventListener = (sceneId: string, visibility: Visibility) => void
4
+ export type VisibilityEventListener = (visibility: Visibility) => void;
5
+ export type GlobalVisibilityEventListener = (
6
+ sceneId: string,
7
+ visibility: Visibility,
8
+ ) => void;
6
9
 
7
10
  export default class VisibilityEventHandler {
8
- private listeners: Record<string, VisibilityEventListener[]> = {}
9
- private globalListeners: GlobalVisibilityEventListener[] = []
10
-
11
- constructor() {}
12
-
13
- handleComponentVisibility() {
14
- Event.listenComponentVisibility((sceneId: string, visibility: Visibility) => {
15
- const listeners = this.listeners[sceneId]
16
- if (listeners) {
17
- listeners.forEach(listener => listener(visibility))
18
- }
19
-
20
- this.globalListeners.forEach(listener => listener(sceneId, visibility))
21
- })
22
- }
23
-
24
- addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
25
- this.globalListeners.push(listener)
26
- }
27
-
28
- removeGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
29
- this.globalListeners = this.globalListeners.filter(l => l !== listener)
30
- }
31
-
32
- addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener) {
33
- if (!this.listeners[sceneId]) {
34
- this.listeners[sceneId] = []
35
- }
36
- this.listeners[sceneId].push(listener)
37
- }
38
-
39
- removeVisibilityEventListener(sceneId: string, listener: VisibilityEventListener) {
40
- if (this.listeners[sceneId]) {
41
- this.listeners[sceneId] = this.listeners[sceneId].filter(l => l !== listener)
42
- }
43
- }
11
+ private listeners: Record<string, VisibilityEventListener[]> = {};
12
+ private globalListeners: GlobalVisibilityEventListener[] = [];
13
+
14
+ constructor() {}
15
+
16
+ handleComponentVisibility() {
17
+ Event.listenComponentVisibility(
18
+ (sceneId: string, visibility: Visibility) => {
19
+ const listeners = this.listeners[sceneId];
20
+ if (listeners) {
21
+ listeners.forEach(listener => listener(visibility));
22
+ }
23
+
24
+ this.globalListeners.forEach(listener =>
25
+ listener(sceneId, visibility),
26
+ );
27
+ },
28
+ );
29
+ }
30
+
31
+ addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
32
+ this.globalListeners.push(listener);
33
+ }
34
+
35
+ removeGlobalVisibilityEventListener(
36
+ listener: GlobalVisibilityEventListener,
37
+ ) {
38
+ this.globalListeners = this.globalListeners.filter(l => l !== listener);
39
+ }
40
+
41
+ addVisibilityEventListener(
42
+ sceneId: string,
43
+ listener: VisibilityEventListener,
44
+ ) {
45
+ if (!this.listeners[sceneId]) {
46
+ this.listeners[sceneId] = [];
47
+ }
48
+ this.listeners[sceneId].push(listener);
49
+ }
50
+
51
+ removeVisibilityEventListener(
52
+ sceneId: string,
53
+ listener: VisibilityEventListener,
54
+ ) {
55
+ if (this.listeners[sceneId]) {
56
+ this.listeners[sceneId] = this.listeners[sceneId].filter(
57
+ l => l !== listener,
58
+ );
59
+ }
60
+ }
44
61
  }
package/src/hooks.ts CHANGED
@@ -1,35 +1,37 @@
1
- import React, { useContext, useEffect, useState } from 'react'
2
- import Navigation from './Navigation'
3
- import { Navigator, NavigationContext } from './Navigator'
1
+ import React, {useContext, useEffect, useState} from 'react';
2
+ import Navigation from './Navigation';
3
+ import {Navigator, NavigationContext} from './Navigator';
4
4
 
5
5
  export function useNavigator(): Navigator {
6
- return useContext<Navigator>(NavigationContext)
6
+ return useContext<Navigator>(NavigationContext);
7
7
  }
8
8
 
9
9
  export function useVisibility() {
10
- const navigator = useNavigator()
11
- const [visibility, setVisibility] = useState(navigator.visibility)
10
+ const navigator = useNavigator();
11
+ const [visibility, setVisibility] = useState(navigator.visibility);
12
12
 
13
- useEffect(() => {
14
- const subscription = Navigation.addVisibilityEventListener(navigator.sceneId, v => {
15
- setVisibility(v)
16
- })
17
- return () => subscription.remove()
18
- }, [navigator])
13
+ useEffect(() => {
14
+ const subscription = Navigation.addVisibilityEventListener(navigator.sceneId, v => {
15
+ setVisibility(v);
16
+ });
17
+ return () => subscription.remove();
18
+ }, [navigator]);
19
19
 
20
- return visibility
20
+ return visibility;
21
21
  }
22
22
 
23
23
  export function useVisible() {
24
- const visibility = useVisibility()
25
- return visibility === 'visible'
24
+ const visibility = useVisibility();
25
+ return visibility === 'visible';
26
26
  }
27
27
 
28
28
  export function useVisibleEffect(effect: React.EffectCallback) {
29
- const visible = useVisible()
30
- useEffect(() => {
31
- if (!visible) return
32
- const destructor = effect()
33
- return () => destructor && destructor()
34
- }, [effect, visible])
29
+ const visible = useVisible();
30
+ useEffect(() => {
31
+ if (!visible) {
32
+ return;
33
+ }
34
+ const destructor = effect();
35
+ return () => destructor && destructor();
36
+ }, [effect, visible]);
35
37
  }
package/src/index.ts CHANGED
@@ -1,16 +1,16 @@
1
- import { withNavigation } from './NavigationComponentWrap'
2
- import navigation from './Navigation'
3
- navigation.setNavigationComponentWrap(withNavigation)
4
- const Navigation = navigation
5
- export default Navigation
6
- export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation'
7
- export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule'
8
- export { withNavigationItem } from './NavigationComponentWrap'
9
- export type { NavigationProps } from './NavigationComponentWrap'
1
+ import {withNavigation} from './NavigationComponentWrap';
2
+ import navigation from './Navigation';
3
+ navigation.setNavigationComponentWrap(withNavigation);
4
+ const Navigation = navigation;
5
+ export default Navigation;
6
+ export {RESULT_OK, RESULT_CANCEL, RESULT_BLOCK} from './Navigation';
7
+ export {statusBarHeight, toolbarHeight, topBarHeight} from './GardenModule';
8
+ export {withNavigationItem} from './NavigationComponentWrap';
9
+ export type {NavigationProps} from './NavigationComponentWrap';
10
10
 
11
- export * from './Navigator'
12
- export * from './hooks'
13
- export * from './router'
14
- export * from './DeepLink'
15
- export * from './Route'
16
- export * from './Options'
11
+ export * from './Navigator';
12
+ export * from './hooks';
13
+ export * from './router';
14
+ export * from './DeepLink';
15
+ export * from './Route';
16
+ export * from './Options';
@@ -1,37 +1,37 @@
1
- import { ScreenGraph, isTargetLocateIn } from './screen'
2
- import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route'
3
- import Navigation from '../Navigation'
1
+ import {ScreenGraph, isTargetLocateIn} from './screen';
2
+ import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
3
+ import Navigation from '../Navigation';
4
4
 
5
5
  export interface DrawerGraph extends RouteGraph {
6
- layout: 'drawer'
7
- sceneId: string
8
- mode: LayoutMode
9
- children: [RouteGraph, ScreenGraph]
6
+ layout: 'drawer';
7
+ sceneId: string;
8
+ mode: LayoutMode;
9
+ children: [RouteGraph, ScreenGraph];
10
10
  }
11
11
 
12
12
  export function isDrawerGraph(graph: RouteGraph): graph is DrawerGraph {
13
- return graph.layout === 'drawer'
13
+ return graph.layout === 'drawer';
14
14
  }
15
15
 
16
16
  export class DrawerRouteHandler implements RouteHandler {
17
- async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]> {
18
- if (!isDrawerGraph(graph)) {
19
- throw new Error(`${graph} is Not a DrawerGraph`)
20
- }
17
+ async process(graph: RouteGraph, target: RouteInfo): Promise<[boolean, RouteGraph | null]> {
18
+ if (!isDrawerGraph(graph)) {
19
+ throw new Error(`${graph} is Not a DrawerGraph`);
20
+ }
21
21
 
22
- const { children } = graph
22
+ const {children} = graph;
23
23
 
24
- const { moduleName, sceneId } = children[1]
25
- if (moduleName === target.moduleName) {
26
- await Navigation.dispatch(sceneId, 'openMenu')
27
- return [true, null]
28
- }
24
+ const {moduleName, sceneId} = children[1];
25
+ if (moduleName === target.moduleName) {
26
+ await Navigation.dispatch(sceneId, 'openMenu');
27
+ return [true, null];
28
+ }
29
29
 
30
- if (isTargetLocateIn(children[0], target)) {
31
- Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName })
32
- return [true, children[0]]
33
- }
30
+ if (isTargetLocateIn(children[0], target)) {
31
+ Navigation.dispatch(sceneId, 'closeMenu', {from: moduleName});
32
+ return [true, children[0]];
33
+ }
34
34
 
35
- return [false, graph]
36
- }
35
+ return [false, graph];
36
+ }
37
37
  }