hybrid-navigation 2.20.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HybridNavigation.podspec +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/{HBDBarButtonItem.m → HBDBarButtonItem.mm} +19 -11
- package/ios/HybridNavigation/View/{HBDNavigationBar.m → HBDNavigationBar.mm} +68 -5
- 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} +1 -42
- 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/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
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {Visibility} from '../Route';
|
|
2
|
-
import
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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 {
|
|
8
|
-
export {
|
|
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';
|
package/src/router/drawer.ts
CHANGED
|
@@ -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
|
|
package/src/router/index.ts
CHANGED
|
@@ -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';
|
package/src/router/screen.ts
CHANGED
|
@@ -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
|
}
|
package/src/router/stack.ts
CHANGED
|
@@ -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);
|
package/src/router/tabs.ts
CHANGED
|
@@ -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,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
|
-
}
|
|
@@ -1,230 +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.toBundle;
|
|
8
|
-
import static com.reactnative.hybridnavigation.Parameters.toList;
|
|
9
|
-
|
|
10
|
-
import android.app.Activity;
|
|
11
|
-
import android.content.res.Resources;
|
|
12
|
-
import android.os.Bundle;
|
|
13
|
-
|
|
14
|
-
import androidx.annotation.NonNull;
|
|
15
|
-
import androidx.annotation.Nullable;
|
|
16
|
-
import androidx.fragment.app.FragmentManager;
|
|
17
|
-
|
|
18
|
-
import com.facebook.common.logging.FLog;
|
|
19
|
-
import com.facebook.react.bridge.JavaOnlyMap;
|
|
20
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
21
|
-
import com.facebook.react.bridge.ReactContext;
|
|
22
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
23
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
24
|
-
import com.facebook.react.bridge.ReadableArray;
|
|
25
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
26
|
-
import com.facebook.react.bridge.UiThreadUtil;
|
|
27
|
-
import com.facebook.react.bridge.WritableMap;
|
|
28
|
-
import com.facebook.react.uimanager.PixelUtil;
|
|
29
|
-
import com.navigation.androidx.AwesomeFragment;
|
|
30
|
-
import com.navigation.androidx.DrawerFragment;
|
|
31
|
-
import com.navigation.androidx.FragmentHelper;
|
|
32
|
-
import com.navigation.androidx.TabBarFragment;
|
|
33
|
-
|
|
34
|
-
import java.util.HashMap;
|
|
35
|
-
import java.util.Map;
|
|
36
|
-
|
|
37
|
-
public class GardenModule extends ReactContextBaseJavaModule {
|
|
38
|
-
|
|
39
|
-
private static final String TAG = "Navigation";
|
|
40
|
-
private final ReactBridgeManager bridgeManager;
|
|
41
|
-
|
|
42
|
-
public GardenModule(ReactApplicationContext reactContext, ReactBridgeManager bridgeManager) {
|
|
43
|
-
super(reactContext);
|
|
44
|
-
this.bridgeManager = bridgeManager;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@NonNull
|
|
48
|
-
@Override
|
|
49
|
-
public String getName() {
|
|
50
|
-
return "GardenModule";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Nullable
|
|
54
|
-
@Override
|
|
55
|
-
public Map<String, Object> getConstants() {
|
|
56
|
-
final Map<String, Object> constants = new HashMap<>();
|
|
57
|
-
constants.put("TOOLBAR_HEIGHT", 56);
|
|
58
|
-
Resources resources = getReactApplicationContextIfActiveOrWarn().getResources();
|
|
59
|
-
int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
|
|
60
|
-
float statusBarHeight = PixelUtil.toDIPFromPixel(resources.getDimensionPixelSize(resourceId));
|
|
61
|
-
constants.put("STATUSBAR_HEIGHT", statusBarHeight);
|
|
62
|
-
return constants;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@ReactMethod
|
|
66
|
-
public void setStyle(final ReadableMap style) {
|
|
67
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
68
|
-
FLog.i(TAG, "GardenModule#setStyle");
|
|
69
|
-
Garden.createGlobalStyle(toBundle(style));
|
|
70
|
-
|
|
71
|
-
ReactAppCompatActivity activity = getActiveActivity();
|
|
72
|
-
if (activity != null) {
|
|
73
|
-
activity.inflateStyle();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
@ReactMethod
|
|
79
|
-
public void setLeftBarButtonItem(final String sceneId, @Nullable final ReadableMap readableMap) {
|
|
80
|
-
updateOptions(sceneId, readableMap, "leftBarButtonItem");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@ReactMethod
|
|
84
|
-
public void setRightBarButtonItem(final String sceneId, @Nullable final ReadableMap readableMap) {
|
|
85
|
-
updateOptions(sceneId, readableMap, "rightBarButtonItem");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@ReactMethod
|
|
89
|
-
public void setLeftBarButtonItems(final String sceneId, @Nullable final ReadableArray readableArray) {
|
|
90
|
-
updateOptions(sceneId, readableArray, "leftBarButtonItems");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@ReactMethod
|
|
94
|
-
public void setRightBarButtonItems(final String sceneId, @Nullable final ReadableArray readableArray) {
|
|
95
|
-
updateOptions(sceneId, readableArray, "rightBarButtonItems");
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
@ReactMethod
|
|
99
|
-
public void setTitleItem(final String sceneId, final ReadableMap readableMap) {
|
|
100
|
-
updateOptions(sceneId, readableMap, "titleItem");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
@ReactMethod
|
|
104
|
-
public void updateOptions(final String sceneId, final ReadableMap readableMap) {
|
|
105
|
-
FLog.i(TAG, "update options:" + readableMap);
|
|
106
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
107
|
-
HybridFragment fragment = findHybridFragmentBySceneId(sceneId);
|
|
108
|
-
if (fragment != null) {
|
|
109
|
-
fragment.getGarden().updateOptions(readableMap);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private void updateOptions(String sceneId, @Nullable ReadableMap readableMap, String key) {
|
|
115
|
-
WritableMap writableMap = new JavaOnlyMap();
|
|
116
|
-
if (readableMap == null) {
|
|
117
|
-
writableMap.putNull(key);
|
|
118
|
-
} else {
|
|
119
|
-
writableMap.putMap(key, readableMap);
|
|
120
|
-
}
|
|
121
|
-
updateOptions(sceneId, writableMap);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private void updateOptions(String sceneId, @Nullable ReadableArray readableArray, String key) {
|
|
125
|
-
WritableMap writableMap = new JavaOnlyMap();
|
|
126
|
-
if (readableArray == null) {
|
|
127
|
-
writableMap.putNull(key);
|
|
128
|
-
} else {
|
|
129
|
-
writableMap.putArray(key, readableArray);
|
|
130
|
-
}
|
|
131
|
-
updateOptions(sceneId, writableMap);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@ReactMethod
|
|
135
|
-
public void updateTabBar(final String sceneId, final ReadableMap readableMap) {
|
|
136
|
-
FLog.i(TAG, "updateTabBar:" + readableMap);
|
|
137
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
138
|
-
TabBarFragment tabBarFragment = getTabBarFragment(sceneId);
|
|
139
|
-
if (tabBarFragment == null) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
Bundle bundle = new Bundle();
|
|
144
|
-
bundle.putString(ARG_ACTION, ACTION_UPDATE_TAB_BAR);
|
|
145
|
-
bundle.putBundle(ARG_OPTIONS, toBundle(readableMap));
|
|
146
|
-
tabBarFragment.updateTabBar(bundle);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
@ReactMethod
|
|
151
|
-
public void setTabItem(final String sceneId, @NonNull final ReadableArray options) {
|
|
152
|
-
FLog.i(TAG, "setTabItem:" + options);
|
|
153
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
154
|
-
TabBarFragment tabBarFragment = getTabBarFragment(sceneId);
|
|
155
|
-
if (tabBarFragment == null) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
Bundle bundle = new Bundle();
|
|
160
|
-
bundle.putString(ARG_ACTION, ACTION_SET_TAB_ITEM);
|
|
161
|
-
bundle.putSerializable(ARG_OPTIONS, toList(options));
|
|
162
|
-
tabBarFragment.updateTabBar(bundle);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
@Nullable
|
|
167
|
-
private TabBarFragment getTabBarFragment(String sceneId) {
|
|
168
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
169
|
-
if (fragment != null) {
|
|
170
|
-
return fragment.getTabBarFragment();
|
|
171
|
-
}
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
@ReactMethod
|
|
176
|
-
public void setMenuInteractive(final String sceneId, final boolean enabled) {
|
|
177
|
-
UiThreadUtil.runOnUiThread(() -> {
|
|
178
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
179
|
-
if (fragment == null) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
DrawerFragment drawerFragment = fragment.getDrawerFragment();
|
|
184
|
-
if (drawerFragment == null) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
drawerFragment.setMenuInteractive(enabled);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
193
|
-
if (!bridgeManager.isViewHierarchyReady()) {
|
|
194
|
-
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
ReactAppCompatActivity activity = getActiveActivity();
|
|
199
|
-
if (activity == null) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
204
|
-
return FragmentHelper.findAwesomeFragment(fragmentManager, sceneId);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
@Nullable
|
|
208
|
-
private ReactAppCompatActivity getActiveActivity() {
|
|
209
|
-
ReactContext reactContext = getReactApplicationContext();
|
|
210
|
-
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
Activity activity = reactContext.getCurrentActivity();
|
|
215
|
-
if (activity instanceof ReactAppCompatActivity) {
|
|
216
|
-
return (ReactAppCompatActivity) activity;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
private HybridFragment findHybridFragmentBySceneId(String sceneId) {
|
|
223
|
-
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
224
|
-
if (fragment instanceof HybridFragment) {
|
|
225
|
-
return (HybridFragment) fragment;
|
|
226
|
-
}
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
}
|