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.
Files changed (136) hide show
  1. package/HybridNavigation.podspec +7 -5
  2. package/README.md +17 -0
  3. package/android/build.gradle +56 -19
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +1 -2
  6. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +320 -326
  7. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +13 -20
  8. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +6 -11
  9. package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +55 -21
  10. package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +31 -0
  11. package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +223 -0
  12. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +370 -0
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +239 -224
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +177 -198
  15. package/android/src/main/java/com/reactnative/hybridnavigation/ReactDrawerFragment.java +2 -9
  16. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +41 -78
  17. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +438 -0
  18. package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +10 -19
  19. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +7 -15
  20. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +135 -173
  21. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +54 -227
  22. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +2 -3
  23. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +12 -14
  24. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +18 -21
  25. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +17 -20
  26. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +13 -26
  27. package/dist/NativeEvent.d.ts +33 -0
  28. package/dist/NativeEvent.js +2 -0
  29. package/dist/NativeGarden.d.ts +18 -0
  30. package/dist/NativeGarden.js +2 -0
  31. package/dist/NativeNavigation.d.ts +47 -0
  32. package/dist/NativeNavigation.js +2 -0
  33. package/dist/Navigation.js +3 -3
  34. package/dist/NavigationModule.d.ts +3 -3
  35. package/dist/NavigationModule.js +18 -19
  36. package/dist/Navigator.js +1 -2
  37. package/dist/Options.d.ts +4 -7
  38. package/dist/Route.d.ts +0 -2
  39. package/dist/handler/BarButtonEventHandler.js +2 -2
  40. package/dist/handler/LayoutCommandHandler.js +3 -3
  41. package/dist/handler/ResultEventHandler.js +3 -3
  42. package/dist/handler/VisibilityEventHandler.js +11 -4
  43. package/dist/index.d.ts +0 -1
  44. package/dist/index.js +0 -1
  45. package/ios/HybridNavigation/GlobalStyle.h +0 -6
  46. package/ios/HybridNavigation/{GlobalStyle.m → GlobalStyle.mm} +54 -44
  47. package/ios/HybridNavigation/HBDUtils.h +0 -4
  48. package/ios/HybridNavigation/{HBDUtils.m → HBDUtils.mm} +0 -41
  49. package/ios/HybridNavigation/Navigator/{HBDScreenNavigator.m → HBDScreenNavigator.mm} +3 -9
  50. package/ios/HybridNavigation/Navigator/{HBDStackNavigator.m → HBDStackNavigator.mm} +0 -4
  51. package/ios/HybridNavigation/Navigator/{HBDTabNavigator.m → HBDTabNavigator.mm} +1 -55
  52. package/ios/HybridNavigation/React/HBDNativeEvent.h +13 -0
  53. package/ios/HybridNavigation/React/HBDNativeEvent.mm +31 -0
  54. package/ios/HybridNavigation/React/HBDNativeGarden.h +10 -0
  55. package/ios/HybridNavigation/React/HBDNativeGarden.mm +151 -0
  56. package/ios/HybridNavigation/React/HBDNativeNavigation.h +11 -0
  57. package/ios/HybridNavigation/React/HBDNativeNavigation.mm +263 -0
  58. package/ios/HybridNavigation/{ReactBridge → React}/HBDReactBridgeManager.h +3 -1
  59. package/ios/HybridNavigation/{ReactBridge/HBDReactBridgeManager.m → React/HBDReactBridgeManager.mm} +7 -30
  60. package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +8 -28
  61. package/ios/HybridNavigation/View/HBDRootView.h +2 -2
  62. package/ios/HybridNavigation/View/{HBDRootView.m → HBDRootView.mm} +2 -2
  63. package/ios/HybridNavigation/View/HBDTitleView.h +2 -2
  64. package/ios/HybridNavigation/View/{HBDTitleView.m → HBDTitleView.mm} +3 -3
  65. package/ios/HybridNavigation/View/UIImage+WithBadge.h +13 -0
  66. package/ios/HybridNavigation/View/UIImage+WithBadge.mm +36 -0
  67. package/ios/HybridNavigation/ViewController/{HBDDrawerController.m → HBDDrawerController.mm} +2 -25
  68. package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -4
  69. package/ios/HybridNavigation/ViewController/{HBDReactViewController.m → HBDReactViewController.mm} +40 -31
  70. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -2
  71. package/ios/HybridNavigation/ViewController/HBDTabBarController.mm +140 -0
  72. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.h +0 -2
  73. package/ios/HybridNavigation/ViewController/{HBDViewController+Garden.m → HBDViewController+Garden.mm} +8 -26
  74. package/ios/HybridNavigation/ViewController/HBDViewController.h +2 -0
  75. package/ios/HybridNavigation/ViewController/{HBDViewController.m → HBDViewController.mm} +67 -57
  76. package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +0 -2
  77. package/ios/HybridNavigation/ViewController/{UIViewController+HBD.m → UIViewController+HBD.mm} +10 -44
  78. package/package.json +11 -2
  79. package/src/DeepLink.ts +3 -3
  80. package/src/NativeEvent.ts +40 -0
  81. package/src/NativeGarden.ts +27 -0
  82. package/src/NativeNavigation.ts +72 -0
  83. package/src/Navigation.ts +13 -13
  84. package/src/NavigationComponentWrap.tsx +4 -4
  85. package/src/NavigationModule.ts +21 -46
  86. package/src/Navigator.ts +13 -13
  87. package/src/Options.ts +9 -9
  88. package/src/Route.ts +0 -2
  89. package/src/handler/BarButtonEventHandler.ts +4 -8
  90. package/src/handler/DispatchCommandHandler.ts +4 -8
  91. package/src/handler/LayoutCommandHandler.ts +4 -5
  92. package/src/handler/ResultEventHandler.ts +11 -27
  93. package/src/handler/VisibilityEventHandler.ts +23 -32
  94. package/src/hooks.ts +2 -2
  95. package/src/index.ts +4 -5
  96. package/src/router/drawer.ts +5 -5
  97. package/src/router/index.ts +15 -15
  98. package/src/router/screen.ts +2 -2
  99. package/src/router/stack.ts +4 -4
  100. package/src/router/tabs.ts +3 -3
  101. package/src/store.ts +1 -1
  102. package/android/src/main/java/com/reactnative/hybridnavigation/DefaultTabBarProvider.java +0 -143
  103. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +0 -230
  104. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +0 -89
  105. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +0 -71
  106. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +0 -370
  107. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +0 -445
  108. package/dist/Event.d.ts +0 -16
  109. package/dist/Event.js +0 -62
  110. package/dist/GardenModule.d.ts +0 -24
  111. package/dist/GardenModule.js +0 -21
  112. package/ios/HybridNavigation/HBDAnimationObserver.h +0 -24
  113. package/ios/HybridNavigation/HBDAnimationObserver.m +0 -45
  114. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.h +0 -28
  115. package/ios/HybridNavigation/ReactBridge/HBDEventEmitter.m +0 -72
  116. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +0 -6
  117. package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +0 -157
  118. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +0 -6
  119. package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +0 -249
  120. package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -9
  121. package/ios/HybridNavigation/View/HBDReactTabBar.m +0 -36
  122. package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -9
  123. package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -46
  124. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +0 -265
  125. package/src/Event.ts +0 -117
  126. package/src/GardenModule.ts +0 -50
  127. /package/ios/HybridNavigation/Navigator/{HBDDrawerNavigator.m → HBDDrawerNavigator.mm} +0 -0
  128. /package/ios/HybridNavigation/Navigator/{HBDNavigatorRegistry.m → HBDNavigatorRegistry.mm} +0 -0
  129. /package/ios/HybridNavigation/{ReactBridge → React}/HBDNavigator.h +0 -0
  130. /package/ios/HybridNavigation/View/{HBDBackBarButtonItem.m → HBDBackBarButtonItem.mm} +0 -0
  131. /package/ios/HybridNavigation/View/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +0 -0
  132. /package/ios/HybridNavigation/ViewController/{HBDFadeAnimation.m → HBDFadeAnimation.mm} +0 -0
  133. /package/ios/HybridNavigation/ViewController/{HBDNavigationController.m → HBDNavigationController.mm} +0 -0
  134. /package/ios/HybridNavigation/ViewController/{HBDPopAnimation.m → HBDPopAnimation.mm} +0 -0
  135. /package/ios/HybridNavigation/ViewController/{HBDPushAnimation.m → HBDPushAnimation.mm} +0 -0
  136. /package/ios/HybridNavigation/ViewController/{UINavigationController+HBD.m → UINavigationController+HBD.mm} +0 -0
@@ -1,38 +1,25 @@
1
- import Event from '../Event';
1
+ import NativeEvent from '../NativeEvent';
2
2
 
3
3
  interface IndexType {
4
4
  [index: string]: any;
5
5
  }
6
6
 
7
7
  export type ResultType = IndexType | null;
8
- export type ResultEventListener<T extends ResultType> = (
9
- resultCode: number,
10
- data: T,
11
- ) => void;
8
+ export type ResultEventListener<T extends ResultType> = (resultCode: number, data: T) => void;
12
9
 
13
10
  export default class ResultEventHandler {
14
- private listenerRecords: Record<
15
- string,
16
- Record<number, Array<ResultEventListener<any>>>
17
- > = {};
11
+ private listenerRecords: Record<string, Record<number, Array<ResultEventListener<any>>>> = {};
18
12
 
19
13
  constructor() {}
20
14
 
21
15
  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
- );
16
+ NativeEvent.onResult(({ sceneId, requestCode, resultCode, resultData }) => {
17
+ const listeners = this.listenerRecords[sceneId]?.[requestCode];
18
+ if (listeners) {
19
+ delete this.listenerRecords[sceneId][requestCode];
20
+ listeners.forEach(l => l(resultCode, resultData));
21
+ }
22
+ });
36
23
  }
37
24
 
38
25
  private addResultEventListener(
@@ -63,10 +50,7 @@ export default class ResultEventHandler {
63
50
  }
64
51
  }
65
52
 
66
- waitResult<T extends ResultType>(
67
- sceneId: string,
68
- requestCode: number,
69
- ): Promise<[number, T]> {
53
+ waitResult<T extends ResultType>(sceneId: string, requestCode: number): Promise<[number, T]> {
70
54
  return new Promise<[number, T]>(resolve => {
71
55
  const listener = (resultCode: number, data: T) => {
72
56
  this.removeResultEventListener(sceneId, requestCode);
@@ -1,11 +1,8 @@
1
- import {Visibility} from '../Route';
2
- import Event from '../Event';
1
+ import { Visibility } from '../Route';
2
+ import NativeEvent from '../NativeEvent';
3
3
 
4
4
  export type VisibilityEventListener = (visibility: Visibility) => void;
5
- export type GlobalVisibilityEventListener = (
6
- sceneId: string,
7
- visibility: Visibility,
8
- ) => void;
5
+ export type GlobalVisibilityEventListener = (sceneId: string, visibility: Visibility) => void;
9
6
 
10
7
  export default class VisibilityEventHandler {
11
8
  private listeners: Record<string, VisibilityEventListener[]> = {};
@@ -14,48 +11,42 @@ export default class VisibilityEventHandler {
14
11
  constructor() {}
15
12
 
16
13
  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
- );
14
+ NativeEvent.onComponentAppear(({ sceneId }) => {
15
+ const listeners = this.listeners[sceneId];
16
+ if (listeners) {
17
+ listeners.forEach(listener => listener('visible'));
18
+ }
19
+
20
+ this.globalListeners.forEach(listener => listener(sceneId, 'visible'));
21
+ });
22
+ NativeEvent.onComponentDisappear(({ sceneId }) => {
23
+ const listeners = this.listeners[sceneId];
24
+ if (listeners) {
25
+ listeners.forEach(listener => listener('invisible'));
26
+ }
27
+
28
+ this.globalListeners.forEach(listener => listener(sceneId, 'invisible'));
29
+ });
29
30
  }
30
31
 
31
32
  addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
32
33
  this.globalListeners.push(listener);
33
34
  }
34
35
 
35
- removeGlobalVisibilityEventListener(
36
- listener: GlobalVisibilityEventListener,
37
- ) {
36
+ removeGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener) {
38
37
  this.globalListeners = this.globalListeners.filter(l => l !== listener);
39
38
  }
40
39
 
41
- addVisibilityEventListener(
42
- sceneId: string,
43
- listener: VisibilityEventListener,
44
- ) {
40
+ addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener) {
45
41
  if (!this.listeners[sceneId]) {
46
42
  this.listeners[sceneId] = [];
47
43
  }
48
44
  this.listeners[sceneId].push(listener);
49
45
  }
50
46
 
51
- removeVisibilityEventListener(
52
- sceneId: string,
53
- listener: VisibilityEventListener,
54
- ) {
47
+ removeVisibilityEventListener(sceneId: string, listener: VisibilityEventListener) {
55
48
  if (this.listeners[sceneId]) {
56
- this.listeners[sceneId] = this.listeners[sceneId].filter(
57
- l => l !== listener,
58
- );
49
+ this.listeners[sceneId] = this.listeners[sceneId].filter(l => l !== listener);
59
50
  }
60
51
  }
61
52
  }
package/src/hooks.ts CHANGED
@@ -1,6 +1,6 @@
1
- import React, {useContext, useEffect, useState} from 'react';
1
+ import React, { useContext, useEffect, useState } from 'react';
2
2
  import Navigation from './Navigation';
3
- import {Navigator, NavigationContext} from './Navigator';
3
+ import { Navigator, NavigationContext } from './Navigator';
4
4
 
5
5
  export function useNavigator(): Navigator {
6
6
  return useContext<Navigator>(NavigationContext);
package/src/index.ts CHANGED
@@ -1,12 +1,11 @@
1
- import {withNavigation} from './NavigationComponentWrap';
1
+ import { withNavigation } from './NavigationComponentWrap';
2
2
  import navigation from './Navigation';
3
3
  navigation.setNavigationComponentWrap(withNavigation);
4
4
  const Navigation = navigation;
5
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';
6
+ export { RESULT_OK, RESULT_CANCEL, RESULT_BLOCK } from './Navigation';
7
+ export { withNavigationItem } from './NavigationComponentWrap';
8
+ export type { NavigationProps } from './NavigationComponentWrap';
10
9
 
11
10
  export * from './Navigator';
12
11
  export * from './hooks';
@@ -1,5 +1,5 @@
1
- import {ScreenGraph, isTargetLocateIn} from './screen';
2
- import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
1
+ import { ScreenGraph, isTargetLocateIn } from './screen';
2
+ import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
3
3
  import Navigation from '../Navigation';
4
4
 
5
5
  export interface DrawerGraph extends RouteGraph {
@@ -19,16 +19,16 @@ export class DrawerRouteHandler implements RouteHandler {
19
19
  throw new Error(`${graph} is Not a DrawerGraph`);
20
20
  }
21
21
 
22
- const {children} = graph;
22
+ const { children } = graph;
23
23
 
24
- const {moduleName, sceneId} = children[1];
24
+ const { moduleName, sceneId } = children[1];
25
25
  if (moduleName === target.moduleName) {
26
26
  await Navigation.dispatch(sceneId, 'openMenu');
27
27
  return [true, null];
28
28
  }
29
29
 
30
30
  if (isTargetLocateIn(children[0], target)) {
31
- Navigation.dispatch(sceneId, 'closeMenu', {from: moduleName});
31
+ Navigation.dispatch(sceneId, 'closeMenu', { from: moduleName });
32
32
  return [true, children[0]];
33
33
  }
34
34
 
@@ -1,4 +1,4 @@
1
- import {pathToRegexp, match} from 'path-to-regexp';
1
+ import { pathToRegexp, match } from 'path-to-regexp';
2
2
  import {
3
3
  RouteConfig,
4
4
  RouteData,
@@ -7,11 +7,11 @@ import {
7
7
  RouteInfo,
8
8
  RouteInterceptor,
9
9
  } from '../Route';
10
- import {NavigationItem} from '../Options';
11
- import {StackRouteHandler} from './stack';
12
- import {ScreenRouteHandler} from './screen';
13
- import {TabsRouteHandler} from './tabs';
14
- import {DrawerRouteHandler} from './drawer';
10
+ import { NavigationItem } from '../Options';
11
+ import { StackRouteHandler } from './stack';
12
+ import { ScreenRouteHandler } from './screen';
13
+ import { TabsRouteHandler } from './tabs';
14
+ import { DrawerRouteHandler } from './drawer';
15
15
 
16
16
  import Navigation from '../Navigation';
17
17
 
@@ -54,7 +54,7 @@ class Router {
54
54
  }
55
55
 
56
56
  private convertConfigToData(moduleName: string, route: RouteConfig) {
57
- let {path, dependency, mode} = route;
57
+ let { path, dependency, mode } = route;
58
58
  let regexp: RegExp | undefined;
59
59
  if (path) {
60
60
  if (!path.startsWith('/')) {
@@ -63,7 +63,7 @@ class Router {
63
63
  regexp = pathToRegexp(path);
64
64
  }
65
65
  mode = mode || 'push';
66
- return {moduleName, mode, path, regexp, dependency};
66
+ return { moduleName, mode, path, regexp, dependency };
67
67
  }
68
68
 
69
69
  private isRouteConfigInflated = false;
@@ -125,10 +125,10 @@ class Router {
125
125
  const moduleName = data.moduleName;
126
126
  const params = pathParams(pathName);
127
127
  const query = queryParams(queryString);
128
- props = {...query, ...params, ...props};
128
+ props = { ...query, ...params, ...props };
129
129
  const dependencies = this.routeDependencies(data);
130
130
  const mode = data.mode;
131
- return {moduleName, props, dependencies, mode, options};
131
+ return { moduleName, props, dependencies, mode, options };
132
132
  }
133
133
  }
134
134
  }
@@ -172,8 +172,8 @@ class Router {
172
172
  const graphArray = await Navigation.routeGraph();
173
173
  if (graphArray.length > 1) {
174
174
  for (let index = graphArray.length - 1; index > 0; index--) {
175
- const {mode: layoutMode} = graphArray[index];
176
- const {sceneId, moduleName} = await Navigation.currentRoute();
175
+ const { mode: layoutMode } = graphArray[index];
176
+ const { sceneId, moduleName } = await Navigation.currentRoute();
177
177
  if (layoutMode === 'present') {
178
178
  await Navigation.dispatch(sceneId, 'dismiss', {
179
179
  from: moduleName,
@@ -195,9 +195,9 @@ class Router {
195
195
  return;
196
196
  }
197
197
 
198
- const {sceneId, moduleName: from} = await Navigation.currentRoute();
199
- Navigation.dispatch(sceneId, 'closeMenu', {from});
200
- const {moduleName, mode: routeMode, props: initialProps} = route;
198
+ const { sceneId, moduleName: from } = await Navigation.currentRoute();
199
+ Navigation.dispatch(sceneId, 'closeMenu', { from });
200
+ const { moduleName, mode: routeMode, props: initialProps } = route;
201
201
  let action = 'push';
202
202
  if (routeMode === 'present') {
203
203
  action = 'present';
@@ -1,4 +1,4 @@
1
- import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
1
+ import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
2
2
 
3
3
  export interface ScreenGraph extends RouteGraph {
4
4
  layout: 'screen';
@@ -25,7 +25,7 @@ function extractModuleNames(graph: RouteGraph, set: string[]) {
25
25
  export function isTargetLocateIn(graph: RouteGraph, target: RouteInfo) {
26
26
  const existings: string[] = [];
27
27
  extractModuleNames(graph, existings);
28
- const {dependencies, moduleName} = target;
28
+ const { dependencies, moduleName } = target;
29
29
  const expectations = [...dependencies, moduleName];
30
30
  return expectations.some(name => existings.includes(name));
31
31
  }
@@ -1,5 +1,5 @@
1
- import {ScreenGraph, isScreenGraph, isTargetLocateIn} from './screen';
2
- import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
1
+ import { ScreenGraph, isScreenGraph, isTargetLocateIn } from './screen';
2
+ import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
3
3
  import Navigation from '../Navigation';
4
4
 
5
5
  export interface StackGraph extends RouteGraph {
@@ -19,7 +19,7 @@ export class StackRouteHandler implements RouteHandler {
19
19
  throw new Error(`${graph} is Not a StackGraph`);
20
20
  }
21
21
 
22
- const {children} = graph;
22
+ const { children } = graph;
23
23
 
24
24
  for (let i = children.length - 1; i > -1; i--) {
25
25
  const childGraph = children[i];
@@ -46,7 +46,7 @@ export class StackRouteHandler implements RouteHandler {
46
46
  }
47
47
 
48
48
  private navigateTo(childGraph: ScreenGraph, target: RouteInfo) {
49
- const {moduleName, dependencies, props} = target;
49
+ const { moduleName, dependencies, props } = target;
50
50
  const expectations = [...dependencies, moduleName];
51
51
  const index = expectations.findIndex(name => name === childGraph.moduleName);
52
52
  const pendings = expectations.slice(index + 1);
@@ -1,5 +1,5 @@
1
- import {isTargetLocateIn} from './screen';
2
- import {LayoutMode, RouteGraph, RouteHandler, RouteInfo} from '../Route';
1
+ import { isTargetLocateIn } from './screen';
2
+ import { LayoutMode, RouteGraph, RouteHandler, RouteInfo } from '../Route';
3
3
  import Navigation from '../Navigation';
4
4
 
5
5
  export interface TabsGraph extends RouteGraph {
@@ -19,7 +19,7 @@ export class TabsRouteHandler implements RouteHandler {
19
19
  throw new Error(`${graph} is NOT a TabsGraph`);
20
20
  }
21
21
 
22
- const {children, selectedIndex} = graph;
22
+ const { children, selectedIndex } = graph;
23
23
 
24
24
  for (let i = 0; i < children.length; i++) {
25
25
  if (isTargetLocateIn(children[i], target)) {
package/src/store.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {Navigator} from './Navigator';
1
+ import { Navigator } from './Navigator';
2
2
 
3
3
  const navigators = new Map<string, Navigator>();
4
4
 
@@ -1,143 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ITEM;
4
- import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
5
- import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
6
- import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
7
- import static com.reactnative.hybridnavigation.Parameters.mergeOptions;
8
-
9
- import android.os.Bundle;
10
- import android.view.View;
11
-
12
- import androidx.annotation.NonNull;
13
- import androidx.annotation.Nullable;
14
-
15
- import com.navigation.androidx.Style;
16
- import com.navigation.androidx.TabBar;
17
- import com.navigation.androidx.TabBarFragment;
18
- import com.navigation.androidx.TabBarItem;
19
-
20
- import java.util.ArrayList;
21
- import java.util.List;
22
-
23
- public class DefaultTabBarProvider extends com.navigation.androidx.DefaultTabBarProvider {
24
-
25
- private ReactTabBarFragment tabBarFragment;
26
-
27
- @Override
28
- public View onCreateTabBar(@NonNull List<TabBarItem> tabBarItems, @NonNull TabBarFragment tabBarFragment, @Nullable Bundle savedInstanceState) {
29
- this.tabBarFragment = (ReactTabBarFragment) tabBarFragment;
30
- return super.onCreateTabBar(tabBarItems, tabBarFragment, savedInstanceState);
31
- }
32
-
33
- @Override
34
- public void updateTabBar(@NonNull Bundle options) {
35
- String action = options.getString(ARG_ACTION);
36
- if (action == null) {
37
- return;
38
- }
39
-
40
- switch (action) {
41
- case ACTION_SET_TAB_ITEM:
42
- setTabItem(options.getParcelableArrayList(ARG_OPTIONS));
43
- break;
44
- case ACTION_UPDATE_TAB_BAR:
45
- updateTabBarStyle(options.getBundle(ARG_OPTIONS));
46
- break;
47
- }
48
- }
49
-
50
- private void setTabItem(@Nullable ArrayList<Bundle> options) {
51
- if (options == null) {
52
- return;
53
- }
54
-
55
- TabBar tabBar = tabBarFragment.getTabBar();
56
-
57
- for (Bundle option : options) {
58
- int index = (int) option.getDouble("index");
59
- TabBarItem tabBarItem = tabBar.getTabBarItem(index);
60
- if (tabBarItem == null) {
61
- continue;
62
- }
63
-
64
- setTabItemTitle(option, tabBarItem);
65
- setTabItemIcon(option, tabBarItem);
66
- setTabItemBadge(option, tabBarItem);
67
- tabBar.renderTabView(index);
68
- }
69
- }
70
-
71
- private void setTabItemBadge(Bundle option, TabBarItem tabBarItem) {
72
- Bundle badge = option.getBundle("badge");
73
- if (badge == null) {
74
- return;
75
- }
76
-
77
- boolean hidden = badge.getBoolean("hidden", true);
78
- String text = !hidden ? badge.getString("text", "") : "";
79
- boolean dot = !hidden && badge.getBoolean("dot", false);
80
-
81
- tabBarItem.badgeText = text;
82
- tabBarItem.showDotBadge = dot;
83
- }
84
-
85
- private void setTabItemIcon(Bundle option, TabBarItem tabBarItem) {
86
- Bundle icon = option.getBundle("icon");
87
- if (icon == null) {
88
- return;
89
- }
90
-
91
- Bundle selected = icon.getBundle("selected");
92
- tabBarItem.iconUri = selected.getString("uri");
93
-
94
- Bundle unselected = icon.getBundle("unselected");
95
- if (unselected != null) {
96
- tabBarItem.unselectedIconUri = unselected.getString("uri");
97
- }
98
- }
99
-
100
- private void setTabItemTitle(Bundle option, TabBarItem tabBarItem) {
101
- String title = option.getString("title");
102
- if (title != null) {
103
- tabBarItem.title = title;
104
- }
105
- }
106
-
107
- private void updateTabBarStyle(@Nullable Bundle options) {
108
- if (options == null) {
109
- return;
110
- }
111
-
112
- tabBarFragment.setOptions(mergeOptions(tabBarFragment.getOptions(), options));
113
- TabBar tabBar = tabBarFragment.getTabBar();
114
-
115
- String tabBarColor = options.getString("tabBarColor");
116
- Bundle shadowImage = options.getBundle("tabBarShadowImage");
117
- String tabBarItemColor = options.getString("tabBarItemColor");
118
- String tabBarUnselectedItemColor = options.getString("tabBarUnselectedItemColor");
119
-
120
- if (tabBarColor != null) {
121
- tabBar.setBarBackgroundColor(tabBarColor);
122
-
123
- Style style = tabBarFragment.getStyle();
124
- style.setTabBarBackgroundColor(tabBarColor);
125
- tabBarFragment.setNeedsNavigationBarAppearanceUpdate();
126
- }
127
-
128
- if (shadowImage != null) {
129
- tabBar.setShadowDrawable(Utils.createTabBarShadow(tabBarFragment.requireContext(), shadowImage));
130
- }
131
-
132
- if (tabBarItemColor != null) {
133
- tabBar.setSelectedItemColor(tabBarItemColor);
134
- }
135
-
136
- if (tabBarUnselectedItemColor != null) {
137
- tabBar.setUnselectedItemColor(tabBarUnselectedItemColor);
138
- }
139
-
140
- tabBar.initialise(tabBar.getCurrentSelectedPosition());
141
- }
142
-
143
- }