hybrid-navigation 2.16.0-beta.5 → 2.16.0-beta.7
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/lib/Garden.d.ts +65 -0
- package/lib/Garden.js +81 -0
- package/lib/NavigationComponentWrap.d.ts +6 -0
- package/lib/NavigationComponentWrap.js +6 -1
- package/lib/Navigator.d.ts +43 -2
- package/lib/Navigator.js +59 -1
- package/lib/ReactRegistry.d.ts +25 -0
- package/lib/ReactRegistry.js +29 -0
- package/lib/hooks.d.ts +5 -0
- package/lib/hooks.js +8 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +2 -0
- package/package.json +1 -1
- package/src/Garden.ts +103 -0
- package/src/NavigationComponentWrap.tsx +15 -1
- package/src/Navigator.ts +77 -2
- package/src/ReactRegistry.tsx +39 -0
- package/src/hooks.ts +9 -0
- package/src/index.ts +3 -1
package/lib/Garden.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
|
|
2
|
+
type Nullable<T> = {
|
|
3
|
+
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
|
|
4
|
+
};
|
|
5
|
+
export interface Garden {
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
9
|
+
*/
|
|
10
|
+
export declare class Garden implements Garden {
|
|
11
|
+
sceneId: string;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use Navigation.setDefaultOptions() instead.
|
|
14
|
+
* @param style
|
|
15
|
+
*/
|
|
16
|
+
static setStyle(style: DefaultOptions): void;
|
|
17
|
+
constructor(sceneId: string);
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use Navigation.setLeftBarButtonItem() instead.
|
|
20
|
+
* @param buttonItem
|
|
21
|
+
*/
|
|
22
|
+
setLeftBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use Navigation.setRightBarButtonItem() instead.
|
|
25
|
+
* @param buttonItem
|
|
26
|
+
*/
|
|
27
|
+
setRightBarButtonItem(buttonItem: Nullable<BarButtonItem> | null): void;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @deprecated Use Navigation.setLeftBarButtonItems() instead.
|
|
31
|
+
* @param buttonItems
|
|
32
|
+
*/
|
|
33
|
+
setLeftBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use Navigation.setRightBarButtonItems() instead.
|
|
36
|
+
* @param buttonItems
|
|
37
|
+
*/
|
|
38
|
+
setRightBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null): void;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use Navigation.setTitleItem() instead.
|
|
41
|
+
* @param titleItem
|
|
42
|
+
*/
|
|
43
|
+
setTitleItem(titleItem: TitleItem): void;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use Navigation.updateOptions() instead.
|
|
46
|
+
* @param options
|
|
47
|
+
*/
|
|
48
|
+
updateOptions(options: NavigationOption): void;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Use Navigation.updateTabBar() instead.
|
|
51
|
+
* @param options
|
|
52
|
+
*/
|
|
53
|
+
updateTabBar(options: TabBarStyle): void;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use Navigation.setTabItem() instead.
|
|
56
|
+
* @param item
|
|
57
|
+
*/
|
|
58
|
+
setTabItem(item: TabItemInfo | TabItemInfo[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* @deprecated Use Navigation.setMenuInteractive() instead.
|
|
61
|
+
* @param enabled
|
|
62
|
+
*/
|
|
63
|
+
setMenuInteractive(enabled: boolean): void;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
package/lib/Garden.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import Navigation from './Navigation';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
4
|
+
*/
|
|
5
|
+
export class Garden {
|
|
6
|
+
sceneId;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use Navigation.setDefaultOptions() instead.
|
|
9
|
+
* @param style
|
|
10
|
+
*/
|
|
11
|
+
static setStyle(style) {
|
|
12
|
+
Navigation.setDefaultOptions(style);
|
|
13
|
+
}
|
|
14
|
+
constructor(sceneId) {
|
|
15
|
+
this.sceneId = sceneId;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use Navigation.setLeftBarButtonItem() instead.
|
|
19
|
+
* @param buttonItem
|
|
20
|
+
*/
|
|
21
|
+
setLeftBarButtonItem(buttonItem) {
|
|
22
|
+
Navigation.setLeftBarButtonItem(this.sceneId, buttonItem);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated Use Navigation.setRightBarButtonItem() instead.
|
|
26
|
+
* @param buttonItem
|
|
27
|
+
*/
|
|
28
|
+
setRightBarButtonItem(buttonItem) {
|
|
29
|
+
Navigation.setRightBarButtonItem(this.sceneId, buttonItem);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Use Navigation.setLeftBarButtonItems() instead.
|
|
34
|
+
* @param buttonItems
|
|
35
|
+
*/
|
|
36
|
+
setLeftBarButtonItems(buttonItems) {
|
|
37
|
+
Navigation.setLeftBarButtonItems(this.sceneId, buttonItems);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use Navigation.setRightBarButtonItems() instead.
|
|
41
|
+
* @param buttonItems
|
|
42
|
+
*/
|
|
43
|
+
setRightBarButtonItems(buttonItems) {
|
|
44
|
+
Navigation.setRightBarButtonItems(this.sceneId, buttonItems);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Use Navigation.setTitleItem() instead.
|
|
48
|
+
* @param titleItem
|
|
49
|
+
*/
|
|
50
|
+
setTitleItem(titleItem) {
|
|
51
|
+
Navigation.setTitleItem(this.sceneId, titleItem);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use Navigation.updateOptions() instead.
|
|
55
|
+
* @param options
|
|
56
|
+
*/
|
|
57
|
+
updateOptions(options) {
|
|
58
|
+
Navigation.updateOptions(this.sceneId, options);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use Navigation.updateTabBar() instead.
|
|
62
|
+
* @param options
|
|
63
|
+
*/
|
|
64
|
+
updateTabBar(options) {
|
|
65
|
+
Navigation.updateTabBar(this.sceneId, options);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated Use Navigation.setTabItem() instead.
|
|
69
|
+
* @param item
|
|
70
|
+
*/
|
|
71
|
+
setTabItem(item) {
|
|
72
|
+
Navigation.setTabItem(this.sceneId, item);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated Use Navigation.setMenuInteractive() instead.
|
|
76
|
+
* @param enabled
|
|
77
|
+
*/
|
|
78
|
+
setMenuInteractive(enabled) {
|
|
79
|
+
Navigation.setMenuInteractive(this.sceneId, enabled);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { Garden } from './Garden';
|
|
2
3
|
import type { NavigationItem } from './Options';
|
|
3
4
|
import { Navigator } from './Navigator';
|
|
4
5
|
export interface NavigationProps {
|
|
5
6
|
navigator: Navigator;
|
|
7
|
+
garden: Garden;
|
|
6
8
|
sceneId: string;
|
|
7
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use NavigationProps instead.
|
|
12
|
+
*/
|
|
13
|
+
export type InjectedProps = NavigationProps;
|
|
8
14
|
interface NativeProps {
|
|
9
15
|
sceneId: string;
|
|
10
16
|
}
|
|
@@ -12,14 +12,19 @@ export function withNavigation(moduleName) {
|
|
|
12
12
|
if (navigator.moduleName === undefined) {
|
|
13
13
|
navigator.moduleName = moduleName;
|
|
14
14
|
}
|
|
15
|
+
const garden = navigator.garden;
|
|
15
16
|
useEffect(() => {
|
|
16
17
|
Navigation.signalFirstRenderComplete(navigator.sceneId);
|
|
17
18
|
return () => {
|
|
18
19
|
navigator.unmount();
|
|
19
20
|
};
|
|
20
21
|
}, [navigator]);
|
|
22
|
+
const injected = {
|
|
23
|
+
garden,
|
|
24
|
+
navigator,
|
|
25
|
+
};
|
|
21
26
|
return (<NavigationContext.Provider value={navigator}>
|
|
22
|
-
<WrappedComponent ref={ref} {...props}
|
|
27
|
+
<WrappedComponent ref={ref} {...props} {...injected}/>
|
|
23
28
|
</NavigationContext.Provider>);
|
|
24
29
|
});
|
|
25
30
|
FC.displayName = `withNavigation(${getDisplayName(WrappedComponent)})`;
|
package/lib/Navigator.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { Visibility, Layout, BuildInLayout } from './Route';
|
|
2
|
+
import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route';
|
|
3
3
|
import type { NavigationItem } from './Options';
|
|
4
|
-
import {
|
|
4
|
+
import { Garden } from './Garden';
|
|
5
|
+
import { NavigationInterceptor, DispatchParams, ResultType } from './Navigation';
|
|
5
6
|
export declare const NavigationContext: import("react").Context<any>;
|
|
6
7
|
interface NavigationState {
|
|
7
8
|
params: {
|
|
@@ -19,7 +20,47 @@ export declare class Navigator implements Navigator {
|
|
|
19
20
|
static of(sceneId: string): Navigator;
|
|
20
21
|
static find(moduleName: string): Promise<Navigator | undefined>;
|
|
21
22
|
static current(): Promise<Navigator>;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Use Navigation.currentRoute() instead
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
static currentRoute(): Promise<Route>;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use Navigation.routeGraph() instead
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
static routeGraph(): Promise<RouteGraph[]>;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use Navigation.setRoot() instead
|
|
35
|
+
* @param layout
|
|
36
|
+
* @param sticky
|
|
37
|
+
*/
|
|
38
|
+
static setRoot(layout: BuildInLayout | Layout, sticky?: boolean): void;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use Navigation.setRootLayoutUpdateListener() instead
|
|
41
|
+
* @param willSetRoot
|
|
42
|
+
* @param didSetRoot
|
|
43
|
+
*/
|
|
44
|
+
static setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use Navigation.dispatch() instead
|
|
47
|
+
* @param sceneId
|
|
48
|
+
* @param action
|
|
49
|
+
* @param params
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
static dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Use Navigation.setInterceptor() instead
|
|
55
|
+
* @param interceptor
|
|
56
|
+
*/
|
|
57
|
+
static setInterceptor(interceptor: NavigationInterceptor): void;
|
|
22
58
|
constructor(sceneId: string, moduleName?: string | undefined);
|
|
59
|
+
private _garden?;
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Garden is deprecated, Use Navigation related methods instead.
|
|
62
|
+
*/
|
|
63
|
+
get garden(): Garden;
|
|
23
64
|
visibility: Visibility;
|
|
24
65
|
readonly state: NavigationState;
|
|
25
66
|
setParams: (params: {
|
package/lib/Navigator.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
2
|
import store from './store';
|
|
3
|
-
import
|
|
3
|
+
import { Garden } from './Garden';
|
|
4
|
+
import Navigation, { RESULT_CANCEL, } from './Navigation';
|
|
4
5
|
export const NavigationContext = createContext(null);
|
|
5
6
|
let tagGenerator = 0;
|
|
6
7
|
Navigation.addGlobalVisibilityEventListener((sceneId, visibility) => {
|
|
@@ -34,10 +35,67 @@ export class Navigator {
|
|
|
34
35
|
const route = await Navigation.currentRoute();
|
|
35
36
|
return Navigator.of(route.sceneId);
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use Navigation.currentRoute() instead
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
static currentRoute() {
|
|
43
|
+
return Navigation.currentRoute();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use Navigation.routeGraph() instead
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
static routeGraph() {
|
|
50
|
+
return Navigation.routeGraph();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use Navigation.setRoot() instead
|
|
54
|
+
* @param layout
|
|
55
|
+
* @param sticky
|
|
56
|
+
*/
|
|
57
|
+
static setRoot(layout, sticky = false) {
|
|
58
|
+
Navigation.setRoot(layout, sticky);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use Navigation.setRootLayoutUpdateListener() instead
|
|
62
|
+
* @param willSetRoot
|
|
63
|
+
* @param didSetRoot
|
|
64
|
+
*/
|
|
65
|
+
static setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
66
|
+
Navigation.setRootLayoutUpdateListener(willSetRoot, didSetRoot);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use Navigation.dispatch() instead
|
|
70
|
+
* @param sceneId
|
|
71
|
+
* @param action
|
|
72
|
+
* @param params
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
static async dispatch(sceneId, action, params = {}) {
|
|
76
|
+
return Navigation.dispatch(sceneId, action, params);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated Use Navigation.setInterceptor() instead
|
|
80
|
+
* @param interceptor
|
|
81
|
+
*/
|
|
82
|
+
static setInterceptor(interceptor) {
|
|
83
|
+
Navigation.setInterceptor(interceptor);
|
|
84
|
+
}
|
|
37
85
|
constructor(sceneId, moduleName) {
|
|
38
86
|
this.sceneId = sceneId;
|
|
39
87
|
this.moduleName = moduleName;
|
|
40
88
|
}
|
|
89
|
+
_garden;
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Garden is deprecated, Use Navigation related methods instead.
|
|
92
|
+
*/
|
|
93
|
+
get garden() {
|
|
94
|
+
if (!this._garden) {
|
|
95
|
+
this._garden = new Garden(this.sceneId);
|
|
96
|
+
}
|
|
97
|
+
return this._garden;
|
|
98
|
+
}
|
|
41
99
|
visibility = 'pending';
|
|
42
100
|
state = {
|
|
43
101
|
params: {},
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ComponentProvider } from 'react-native';
|
|
2
|
+
import type { RouteConfig } from './Route';
|
|
3
|
+
import { HOC } from './Navigation';
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReactRegistry {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated Use Navigation.startRegisterComponent() instead.
|
|
10
|
+
* @param hoc
|
|
11
|
+
*/
|
|
12
|
+
static startRegisterComponent(hoc?: HOC): void;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use Navigation.endRegisterComponent() instead.
|
|
15
|
+
*/
|
|
16
|
+
static endRegisterComponent(): void;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @deprecated Use Navigation.registerComponent() instead.
|
|
20
|
+
* @param appKey
|
|
21
|
+
* @param getComponentFunc
|
|
22
|
+
* @param routeConfig
|
|
23
|
+
*/
|
|
24
|
+
static registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Navigation from './Navigation';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
4
|
+
*/
|
|
5
|
+
export class ReactRegistry {
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use Navigation.startRegisterComponent() instead.
|
|
8
|
+
* @param hoc
|
|
9
|
+
*/
|
|
10
|
+
static startRegisterComponent(hoc) {
|
|
11
|
+
Navigation.startRegisterComponent(hoc);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use Navigation.endRegisterComponent() instead.
|
|
15
|
+
*/
|
|
16
|
+
static endRegisterComponent() {
|
|
17
|
+
Navigation.endRegisterComponent();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Use Navigation.registerComponent() instead.
|
|
22
|
+
* @param appKey
|
|
23
|
+
* @param getComponentFunc
|
|
24
|
+
* @param routeConfig
|
|
25
|
+
*/
|
|
26
|
+
static registerComponent(appKey, getComponentFunc, routeConfig) {
|
|
27
|
+
Navigation.registerComponent(appKey, getComponentFunc, routeConfig);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/lib/hooks.d.ts
CHANGED
|
@@ -4,3 +4,8 @@ export declare function useVisible(): boolean;
|
|
|
4
4
|
export declare function useVisibility(): "visible" | "invisible" | "pending";
|
|
5
5
|
export declare function useVisibleEffect(effect: React.EffectCallback): void;
|
|
6
6
|
export declare function useNavigator(): Navigator;
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use Navigation related methods instead.
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function useGarden(): import("./Garden").Garden;
|
package/lib/hooks.js
CHANGED
|
@@ -42,3 +42,11 @@ export function useVisibleEffect(effect) {
|
|
|
42
42
|
export function useNavigator() {
|
|
43
43
|
return useContext(NavigationContext);
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use Navigation related methods instead.
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
export function useGarden() {
|
|
50
|
+
const ctx = useContext(NavigationContext);
|
|
51
|
+
return ctx.garden;
|
|
52
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ import Navigation from './Navigation';
|
|
|
2
2
|
export default Navigation;
|
|
3
3
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
4
4
|
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
5
|
-
export { withNavigationItem, NavigationProps } from './NavigationComponentWrap';
|
|
5
|
+
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
6
6
|
export * from './Navigator';
|
|
7
|
+
export * from './Garden';
|
|
8
|
+
export * from './ReactRegistry';
|
|
7
9
|
export * from './hooks';
|
|
8
10
|
export * from './router';
|
|
9
11
|
export * from './DeepLink';
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
|
6
6
|
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
7
7
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
8
8
|
export * from './Navigator';
|
|
9
|
+
export * from './Garden';
|
|
10
|
+
export * from './ReactRegistry';
|
|
9
11
|
export * from './hooks';
|
|
10
12
|
export * from './router';
|
|
11
13
|
export * from './DeepLink';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hybrid-navigation",
|
|
3
3
|
"description": "React Native Navigation that supports seamless navigation between Native and React.",
|
|
4
|
-
"version": "2.16.0-beta.
|
|
4
|
+
"version": "2.16.0-beta.7",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"typings": "./lib/index.d.ts",
|
|
7
7
|
"react-native": "src/index",
|
package/src/Garden.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import Navigation from './Navigation'
|
|
2
|
+
import type {
|
|
3
|
+
BarButtonItem,
|
|
4
|
+
DefaultOptions,
|
|
5
|
+
NavigationOption,
|
|
6
|
+
TabBarStyle,
|
|
7
|
+
TabItemInfo,
|
|
8
|
+
TitleItem,
|
|
9
|
+
} from './Options'
|
|
10
|
+
|
|
11
|
+
type Nullable<T> = {
|
|
12
|
+
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Garden {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
19
|
+
*/
|
|
20
|
+
export class Garden implements Garden {
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use Navigation.setDefaultOptions() instead.
|
|
23
|
+
* @param style
|
|
24
|
+
*/
|
|
25
|
+
static setStyle(style: DefaultOptions) {
|
|
26
|
+
Navigation.setDefaultOptions(style)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(public sceneId: string) {}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use Navigation.setLeftBarButtonItem() instead.
|
|
33
|
+
* @param buttonItem
|
|
34
|
+
*/
|
|
35
|
+
setLeftBarButtonItem(buttonItem: Nullable<BarButtonItem> | null) {
|
|
36
|
+
Navigation.setLeftBarButtonItem(this.sceneId, buttonItem)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use Navigation.setRightBarButtonItem() instead.
|
|
41
|
+
* @param buttonItem
|
|
42
|
+
*/
|
|
43
|
+
setRightBarButtonItem(buttonItem: Nullable<BarButtonItem> | null) {
|
|
44
|
+
Navigation.setRightBarButtonItem(this.sceneId, buttonItem)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @deprecated Use Navigation.setLeftBarButtonItems() instead.
|
|
50
|
+
* @param buttonItems
|
|
51
|
+
*/
|
|
52
|
+
setLeftBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
53
|
+
Navigation.setLeftBarButtonItems(this.sceneId, buttonItems)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated Use Navigation.setRightBarButtonItems() instead.
|
|
58
|
+
* @param buttonItems
|
|
59
|
+
*/
|
|
60
|
+
setRightBarButtonItems(buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
61
|
+
Navigation.setRightBarButtonItems(this.sceneId, buttonItems)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated Use Navigation.setTitleItem() instead.
|
|
66
|
+
* @param titleItem
|
|
67
|
+
*/
|
|
68
|
+
setTitleItem(titleItem: TitleItem) {
|
|
69
|
+
Navigation.setTitleItem(this.sceneId, titleItem)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated Use Navigation.updateOptions() instead.
|
|
74
|
+
* @param options
|
|
75
|
+
*/
|
|
76
|
+
updateOptions(options: NavigationOption) {
|
|
77
|
+
Navigation.updateOptions(this.sceneId, options)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Use Navigation.updateTabBar() instead.
|
|
82
|
+
* @param options
|
|
83
|
+
*/
|
|
84
|
+
updateTabBar(options: TabBarStyle) {
|
|
85
|
+
Navigation.updateTabBar(this.sceneId, options)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @deprecated Use Navigation.setTabItem() instead.
|
|
90
|
+
* @param item
|
|
91
|
+
*/
|
|
92
|
+
setTabItem(item: TabItemInfo | TabItemInfo[]) {
|
|
93
|
+
Navigation.setTabItem(this.sceneId, item)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use Navigation.setMenuInteractive() instead.
|
|
98
|
+
* @param enabled
|
|
99
|
+
*/
|
|
100
|
+
setMenuInteractive(enabled: boolean) {
|
|
101
|
+
Navigation.setMenuInteractive(this.sceneId, enabled)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import React, { useEffect } from 'react'
|
|
2
|
+
import type { Garden } from './Garden'
|
|
2
3
|
import type { NavigationItem } from './Options'
|
|
3
4
|
import { Navigator, NavigationContext } from './Navigator'
|
|
4
5
|
import Navigation from './Navigation'
|
|
5
6
|
|
|
6
7
|
export interface NavigationProps {
|
|
7
8
|
navigator: Navigator
|
|
9
|
+
garden: Garden
|
|
8
10
|
sceneId: string
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use NavigationProps instead.
|
|
15
|
+
*/
|
|
16
|
+
export type InjectedProps = NavigationProps
|
|
17
|
+
|
|
11
18
|
interface NativeProps {
|
|
12
19
|
sceneId: string
|
|
13
20
|
}
|
|
@@ -26,6 +33,8 @@ export function withNavigation(moduleName: string) {
|
|
|
26
33
|
navigator.moduleName = moduleName
|
|
27
34
|
}
|
|
28
35
|
|
|
36
|
+
const garden = navigator.garden
|
|
37
|
+
|
|
29
38
|
useEffect(() => {
|
|
30
39
|
Navigation.signalFirstRenderComplete(navigator.sceneId)
|
|
31
40
|
return () => {
|
|
@@ -33,9 +42,14 @@ export function withNavigation(moduleName: string) {
|
|
|
33
42
|
}
|
|
34
43
|
}, [navigator])
|
|
35
44
|
|
|
45
|
+
const injected = {
|
|
46
|
+
garden,
|
|
47
|
+
navigator,
|
|
48
|
+
}
|
|
49
|
+
|
|
36
50
|
return (
|
|
37
51
|
<NavigationContext.Provider value={navigator}>
|
|
38
|
-
<WrappedComponent ref={ref} {...props}
|
|
52
|
+
<WrappedComponent ref={ref} {...props} {...injected} />
|
|
39
53
|
</NavigationContext.Provider>
|
|
40
54
|
)
|
|
41
55
|
})
|
package/src/Navigator.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { createContext } from 'react'
|
|
2
2
|
|
|
3
3
|
import store from './store'
|
|
4
|
-
import type { Visibility, Layout, BuildInLayout } from './Route'
|
|
4
|
+
import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route'
|
|
5
5
|
import type { NavigationItem } from './Options'
|
|
6
|
-
import
|
|
6
|
+
import { Garden } from './Garden'
|
|
7
|
+
import Navigation, {
|
|
8
|
+
NavigationInterceptor,
|
|
9
|
+
DispatchParams,
|
|
10
|
+
ResultType,
|
|
11
|
+
RESULT_CANCEL,
|
|
12
|
+
} from './Navigation'
|
|
7
13
|
|
|
8
14
|
export const NavigationContext = createContext<any>(null)
|
|
9
15
|
|
|
@@ -53,8 +59,77 @@ export class Navigator implements Navigator {
|
|
|
53
59
|
return Navigator.of(route.sceneId)
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated Use Navigation.currentRoute() instead
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
static currentRoute(): Promise<Route> {
|
|
67
|
+
return Navigation.currentRoute()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @deprecated Use Navigation.routeGraph() instead
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
static routeGraph(): Promise<RouteGraph[]> {
|
|
75
|
+
return Navigation.routeGraph()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @deprecated Use Navigation.setRoot() instead
|
|
80
|
+
* @param layout
|
|
81
|
+
* @param sticky
|
|
82
|
+
*/
|
|
83
|
+
static setRoot(layout: BuildInLayout | Layout, sticky = false) {
|
|
84
|
+
Navigation.setRoot(layout, sticky)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @deprecated Use Navigation.setRootLayoutUpdateListener() instead
|
|
89
|
+
* @param willSetRoot
|
|
90
|
+
* @param didSetRoot
|
|
91
|
+
*/
|
|
92
|
+
static setRootLayoutUpdateListener(willSetRoot = () => {}, didSetRoot = () => {}) {
|
|
93
|
+
Navigation.setRootLayoutUpdateListener(willSetRoot, didSetRoot)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use Navigation.dispatch() instead
|
|
98
|
+
* @param sceneId
|
|
99
|
+
* @param action
|
|
100
|
+
* @param params
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
static async dispatch(
|
|
104
|
+
sceneId: string,
|
|
105
|
+
action: string,
|
|
106
|
+
params: DispatchParams = {},
|
|
107
|
+
): Promise<boolean> {
|
|
108
|
+
return Navigation.dispatch(sceneId, action, params)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @deprecated Use Navigation.setInterceptor() instead
|
|
113
|
+
* @param interceptor
|
|
114
|
+
*/
|
|
115
|
+
static setInterceptor(interceptor: NavigationInterceptor) {
|
|
116
|
+
Navigation.setInterceptor(interceptor)
|
|
117
|
+
}
|
|
118
|
+
|
|
56
119
|
constructor(public sceneId: string, public moduleName?: string) {}
|
|
57
120
|
|
|
121
|
+
private _garden?: Garden
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Garden is deprecated, Use Navigation related methods instead.
|
|
125
|
+
*/
|
|
126
|
+
get garden() {
|
|
127
|
+
if (!this._garden) {
|
|
128
|
+
this._garden = new Garden(this.sceneId)
|
|
129
|
+
}
|
|
130
|
+
return this._garden
|
|
131
|
+
}
|
|
132
|
+
|
|
58
133
|
visibility: Visibility = 'pending'
|
|
59
134
|
|
|
60
135
|
readonly state: NavigationState = {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ComponentProvider } from 'react-native'
|
|
2
|
+
import type { RouteConfig } from './Route'
|
|
3
|
+
|
|
4
|
+
import Navigation, { HOC } from './Navigation'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated use Navigation instead. import Navigation from 'hybrid-navigation'
|
|
8
|
+
*/
|
|
9
|
+
export class ReactRegistry {
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use Navigation.startRegisterComponent() instead.
|
|
12
|
+
* @param hoc
|
|
13
|
+
*/
|
|
14
|
+
static startRegisterComponent(hoc?: HOC) {
|
|
15
|
+
Navigation.startRegisterComponent(hoc)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use Navigation.endRegisterComponent() instead.
|
|
20
|
+
*/
|
|
21
|
+
static endRegisterComponent() {
|
|
22
|
+
Navigation.endRegisterComponent()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use Navigation.registerComponent() instead.
|
|
28
|
+
* @param appKey
|
|
29
|
+
* @param getComponentFunc
|
|
30
|
+
* @param routeConfig
|
|
31
|
+
*/
|
|
32
|
+
static registerComponent(
|
|
33
|
+
appKey: string,
|
|
34
|
+
getComponentFunc: ComponentProvider,
|
|
35
|
+
routeConfig?: RouteConfig,
|
|
36
|
+
) {
|
|
37
|
+
Navigation.registerComponent(appKey, getComponentFunc, routeConfig)
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/hooks.ts
CHANGED
|
@@ -50,3 +50,12 @@ export function useVisibleEffect(effect: React.EffectCallback) {
|
|
|
50
50
|
export function useNavigator(): Navigator {
|
|
51
51
|
return useContext<Navigator>(NavigationContext)
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use Navigation related methods instead.
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
export function useGarden() {
|
|
59
|
+
const ctx = useContext<Navigator>(NavigationContext)
|
|
60
|
+
return ctx.garden
|
|
61
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,11 @@ Navigation.setNavigationComponentWrap(withNavigation)
|
|
|
6
6
|
export default Navigation
|
|
7
7
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation'
|
|
8
8
|
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule'
|
|
9
|
-
export { withNavigationItem, NavigationProps } from './NavigationComponentWrap'
|
|
9
|
+
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap'
|
|
10
10
|
|
|
11
11
|
export * from './Navigator'
|
|
12
|
+
export * from './Garden'
|
|
13
|
+
export * from './ReactRegistry'
|
|
12
14
|
export * from './hooks'
|
|
13
15
|
export * from './router'
|
|
14
16
|
export * from './DeepLink'
|