hybrid-navigation 2.16.0-beta.6 → 2.16.0-beta.8
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/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +50 -2
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +35 -0
- package/lib/Garden.d.ts +65 -0
- package/lib/Garden.js +81 -0
- package/lib/Navigation.d.ts +4 -16
- package/lib/Navigation.js +10 -12
- 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/Options.d.ts +5 -8
- 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 +4 -2
- package/lib/index.js +3 -1
- package/package.json +1 -1
- package/src/Garden.ts +103 -0
- package/src/Navigation.ts +14 -28
- package/src/NavigationComponentWrap.tsx +15 -1
- package/src/Navigator.ts +77 -2
- package/src/Options.ts +5 -10
- package/src/ReactRegistry.tsx +39 -0
- package/src/hooks.ts +9 -0
- package/src/index.ts +4 -2
|
@@ -13,9 +13,11 @@ import android.os.Bundle;
|
|
|
13
13
|
|
|
14
14
|
import androidx.annotation.NonNull;
|
|
15
15
|
import androidx.annotation.Nullable;
|
|
16
|
+
import androidx.drawerlayout.widget.DrawerLayout;
|
|
16
17
|
import androidx.fragment.app.FragmentManager;
|
|
17
18
|
|
|
18
19
|
import com.facebook.common.logging.FLog;
|
|
20
|
+
import com.facebook.react.bridge.JavaOnlyMap;
|
|
19
21
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
20
22
|
import com.facebook.react.bridge.ReactContext;
|
|
21
23
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
@@ -23,6 +25,7 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
23
25
|
import com.facebook.react.bridge.ReadableArray;
|
|
24
26
|
import com.facebook.react.bridge.ReadableMap;
|
|
25
27
|
import com.facebook.react.bridge.UiThreadUtil;
|
|
28
|
+
import com.facebook.react.bridge.WritableMap;
|
|
26
29
|
import com.facebook.react.uimanager.PixelUtil;
|
|
27
30
|
import com.navigation.androidx.AwesomeFragment;
|
|
28
31
|
import com.navigation.androidx.DrawerFragment;
|
|
@@ -72,7 +75,32 @@ public class GardenModule extends ReactContextBaseJavaModule {
|
|
|
72
75
|
}
|
|
73
76
|
});
|
|
74
77
|
}
|
|
75
|
-
|
|
78
|
+
|
|
79
|
+
@ReactMethod
|
|
80
|
+
public void setLeftBarButtonItem(final String sceneId, @Nullable final ReadableMap readableMap) {
|
|
81
|
+
updateOptions(sceneId, readableMap, "leftBarButtonItem");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@ReactMethod
|
|
85
|
+
public void setRightBarButtonItem(final String sceneId, @Nullable final ReadableMap readableMap) {
|
|
86
|
+
updateOptions(sceneId, readableMap, "rightBarButtonItem");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
public void setLeftBarButtonItems(final String sceneId, @Nullable final ReadableArray readableArray) {
|
|
91
|
+
updateOptions(sceneId, readableArray, "leftBarButtonItems");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@ReactMethod
|
|
95
|
+
public void setRightBarButtonItems(final String sceneId, @Nullable final ReadableArray readableArray) {
|
|
96
|
+
updateOptions(sceneId, readableArray, "rightBarButtonItems");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@ReactMethod
|
|
100
|
+
public void setTitleItem(final String sceneId, final ReadableMap readableMap) {
|
|
101
|
+
updateOptions(sceneId, readableMap, "titleItem");
|
|
102
|
+
}
|
|
103
|
+
|
|
76
104
|
@ReactMethod
|
|
77
105
|
public void updateOptions(final String sceneId, final ReadableMap readableMap) {
|
|
78
106
|
FLog.i(TAG, "update options:" + readableMap);
|
|
@@ -83,7 +111,27 @@ public class GardenModule extends ReactContextBaseJavaModule {
|
|
|
83
111
|
}
|
|
84
112
|
});
|
|
85
113
|
}
|
|
86
|
-
|
|
114
|
+
|
|
115
|
+
private void updateOptions(String sceneId, @Nullable ReadableMap readableMap, String key) {
|
|
116
|
+
WritableMap writableMap = new JavaOnlyMap();
|
|
117
|
+
if (readableMap == null) {
|
|
118
|
+
writableMap.putNull(key);
|
|
119
|
+
} else {
|
|
120
|
+
writableMap.putMap(key, readableMap);
|
|
121
|
+
}
|
|
122
|
+
updateOptions(sceneId, writableMap);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private void updateOptions(String sceneId, @Nullable ReadableArray readableArray, String key) {
|
|
126
|
+
WritableMap writableMap = new JavaOnlyMap();
|
|
127
|
+
if (readableArray == null) {
|
|
128
|
+
writableMap.putNull(key);
|
|
129
|
+
} else {
|
|
130
|
+
writableMap.putArray(key, readableArray);
|
|
131
|
+
}
|
|
132
|
+
updateOptions(sceneId, writableMap);
|
|
133
|
+
}
|
|
134
|
+
|
|
87
135
|
@ReactMethod
|
|
88
136
|
public void updateTabBar(final String sceneId, final ReadableMap readableMap) {
|
|
89
137
|
FLog.i(TAG, "updateTabBar:" + readableMap);
|
|
@@ -72,6 +72,41 @@ RCT_EXPORT_METHOD(setStyle:(NSDictionary *) style) {
|
|
|
72
72
|
[GlobalStyle createWithOptions:style];
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
RCT_EXPORT_METHOD(setTitleItem:(NSString *)sceneId item:(NSDictionary *)item) {
|
|
76
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
77
|
+
if (vc) {
|
|
78
|
+
[vc updateNavigationBarOptions:@{@"titleItem": RCTNullIfNil(item)}];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
RCT_EXPORT_METHOD(setLeftBarButtonItem:(NSString *)sceneId item:(NSDictionary *__nullable)item) {
|
|
83
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
84
|
+
if (vc) {
|
|
85
|
+
[vc updateNavigationBarOptions:@{@"leftBarButtonItem": RCTNullIfNil(item)}];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
RCT_EXPORT_METHOD(setRightBarButtonItem:(NSString *)sceneId item:(NSDictionary *__nullable)item) {
|
|
90
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
91
|
+
if (vc) {
|
|
92
|
+
[vc updateNavigationBarOptions:@{@"rightBarButtonItem": RCTNullIfNil(item)}];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
RCT_EXPORT_METHOD(setLeftBarButtonItems:(NSString *)sceneId item:(NSArray *__nullable)items) {
|
|
97
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
98
|
+
if (vc) {
|
|
99
|
+
[vc updateNavigationBarOptions:@{@"leftBarButtonItems": RCTNullIfNil(items)}];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
RCT_EXPORT_METHOD(setRightBarButtonItems:(NSString *)sceneId item:(NSArray *__nullable)items) {
|
|
104
|
+
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
|
105
|
+
if (vc) {
|
|
106
|
+
[vc updateNavigationBarOptions:@{@"rightBarButtonItems": RCTNullIfNil(items)}];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
75
110
|
RCT_EXPORT_METHOD(updateOptions:(NSString *)sceneId item:(NSDictionary *)options) {
|
|
76
111
|
RCTLogInfo(@"[Navigation] updateNavigationBarOptions: %@", options);
|
|
77
112
|
HBDViewController *vc = [self viewControllerWithSceneId:sceneId];
|
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
|
+
}
|
package/lib/Navigation.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
2
|
import { ComponentProvider } from 'react-native';
|
|
3
|
-
import type { BarButtonItem, DefaultOptions, NavigationOption,
|
|
3
|
+
import type { BarButtonItem, DefaultOptions, NavigationOption, TabBarStyle, TabItemInfo, TitleItem } from './Options';
|
|
4
4
|
import type { BuildInLayout, Layout, Route, RouteGraph, RouteConfig } from './Route';
|
|
5
5
|
import { ResultType } from './handler/ResultEventHandler';
|
|
6
6
|
import { GlobalVisibilityEventListener, VisibilityEventListener } from './handler/VisibilityEventHandler';
|
|
@@ -8,6 +8,9 @@ export type { ResultType } from './handler/ResultEventHandler';
|
|
|
8
8
|
import type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
9
9
|
export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCommandHandler';
|
|
10
10
|
type BarButtonClickEventListener = (sceneId: string, value: Function) => void;
|
|
11
|
+
type Nullable<T> = {
|
|
12
|
+
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
|
|
13
|
+
};
|
|
11
14
|
export declare const RESULT_CANCEL: number, RESULT_OK: number;
|
|
12
15
|
export type NavigationSubscription = {
|
|
13
16
|
remove: () => void;
|
|
@@ -35,25 +38,10 @@ export interface Navigation {
|
|
|
35
38
|
currentRoute(): Promise<Route>;
|
|
36
39
|
routeGraph(): Promise<RouteGraph[]>;
|
|
37
40
|
setDefaultOptions(options: DefaultOptions): void;
|
|
38
|
-
/**
|
|
39
|
-
* @deprecated use `updateOptions` instead
|
|
40
|
-
*/
|
|
41
41
|
setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
|
|
42
|
-
/**
|
|
43
|
-
* @deprecated use `updateOptions` instead
|
|
44
|
-
*/
|
|
45
42
|
setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void;
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated use `updateOptions` instead
|
|
48
|
-
*/
|
|
49
43
|
setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void;
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated use `updateOptions` instead
|
|
52
|
-
*/
|
|
53
44
|
setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void;
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated use `updateOptions` instead
|
|
56
|
-
*/
|
|
57
45
|
setTitleItem(sceneId: string, titleItem: TitleItem): void;
|
|
58
46
|
updateOptions(sceneId: string, options: NavigationOption): void;
|
|
59
47
|
updateTabBar(sceneId: string, options: TabBarStyle): void;
|
package/lib/Navigation.js
CHANGED
|
@@ -119,28 +119,26 @@ class NavigationImpl {
|
|
|
119
119
|
GardenModule.setStyle(options);
|
|
120
120
|
}
|
|
121
121
|
setLeftBarButtonItem(sceneId, buttonItem) {
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
|
|
123
|
+
GardenModule.setLeftBarButtonItem(sceneId, options);
|
|
124
124
|
}
|
|
125
125
|
setRightBarButtonItem(sceneId, buttonItem) {
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItem);
|
|
127
|
+
GardenModule.setRightBarButtonItem(sceneId, options);
|
|
128
128
|
}
|
|
129
129
|
setLeftBarButtonItems(sceneId, buttonItems) {
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
|
|
131
|
+
GardenModule.setLeftBarButtonItems(sceneId, options);
|
|
132
132
|
}
|
|
133
133
|
setRightBarButtonItems(sceneId, buttonItems) {
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems);
|
|
135
|
+
GardenModule.setRightBarButtonItems(sceneId, options);
|
|
136
136
|
}
|
|
137
137
|
setTitleItem(sceneId, titleItem) {
|
|
138
|
-
|
|
139
|
-
this.updateOptions(sceneId, { titleItem });
|
|
138
|
+
GardenModule.setTitleItem(sceneId, titleItem);
|
|
140
139
|
}
|
|
141
140
|
updateOptions(sceneId, options) {
|
|
142
|
-
|
|
143
|
-
GardenModule.updateOptions(sceneId, object);
|
|
141
|
+
GardenModule.updateOptions(sceneId, options);
|
|
144
142
|
}
|
|
145
143
|
updateTabBar(sceneId, options) {
|
|
146
144
|
GardenModule.updateTabBar(sceneId, options);
|
|
@@ -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: {},
|
package/lib/Options.d.ts
CHANGED
|
@@ -22,9 +22,6 @@ export type LayoutFittingExpanded = typeof LayoutFittingExpanded;
|
|
|
22
22
|
export declare const LayoutFittingCompressed = "compressed";
|
|
23
23
|
export type LayoutFittingCompressed = typeof LayoutFittingCompressed;
|
|
24
24
|
export type LayoutFitting = LayoutFittingExpanded | LayoutFittingCompressed;
|
|
25
|
-
export type Nullable<T> = {
|
|
26
|
-
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P];
|
|
27
|
-
};
|
|
28
25
|
export interface NavigationOption {
|
|
29
26
|
screenBackgroundColor?: Color;
|
|
30
27
|
statusBarHidden?: boolean;
|
|
@@ -43,11 +40,6 @@ export interface NavigationOption {
|
|
|
43
40
|
homeIndicatorAutoHiddenIOS?: boolean;
|
|
44
41
|
backButtonHidden?: boolean;
|
|
45
42
|
backInteractive?: boolean;
|
|
46
|
-
titleItem?: TitleItem;
|
|
47
|
-
leftBarButtonItem?: Nullable<BarButtonItem> | null;
|
|
48
|
-
rightBarButtonItem?: Nullable<BarButtonItem> | null;
|
|
49
|
-
leftBarButtonItems?: Nullable<BarButtonItem>[] | null;
|
|
50
|
-
rightBarButtonItems?: Nullable<BarButtonItem>[] | null;
|
|
51
43
|
}
|
|
52
44
|
export interface NavigationItem extends NavigationOption {
|
|
53
45
|
passThroughTouches?: boolean;
|
|
@@ -55,6 +47,11 @@ export interface NavigationItem extends NavigationOption {
|
|
|
55
47
|
topBarHidden?: boolean;
|
|
56
48
|
extendedLayoutIncludesTopBar?: boolean;
|
|
57
49
|
swipeBackEnabled?: boolean;
|
|
50
|
+
titleItem?: TitleItem;
|
|
51
|
+
leftBarButtonItem?: BarButtonItem;
|
|
52
|
+
rightBarButtonItem?: BarButtonItem;
|
|
53
|
+
leftBarButtonItems?: BarButtonItem[];
|
|
54
|
+
rightBarButtonItems?: BarButtonItem[];
|
|
58
55
|
backItemIOS?: BackItem;
|
|
59
56
|
tabItem?: TabItem;
|
|
60
57
|
}
|
|
@@ -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';
|
|
6
|
-
export
|
|
5
|
+
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
6
|
+
export { Navigator } 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
|
@@ -5,7 +5,9 @@ export default Navigation;
|
|
|
5
5
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
6
6
|
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
7
7
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
8
|
-
export
|
|
8
|
+
export { Navigator } 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.8",
|
|
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
|
+
}
|
package/src/Navigation.ts
CHANGED
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
BarButtonItem,
|
|
6
6
|
DefaultOptions,
|
|
7
7
|
NavigationOption,
|
|
8
|
-
Nullable,
|
|
9
8
|
TabBarStyle,
|
|
10
9
|
TabItemInfo,
|
|
11
10
|
TitleItem,
|
|
@@ -31,6 +30,10 @@ export type { DispatchParams, NavigationInterceptor } from './handler/DispatchCo
|
|
|
31
30
|
|
|
32
31
|
type BarButtonClickEventListener = (sceneId: string, value: Function) => void
|
|
33
32
|
|
|
33
|
+
type Nullable<T> = {
|
|
34
|
+
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
|
|
35
|
+
}
|
|
36
|
+
|
|
34
37
|
export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants()
|
|
35
38
|
|
|
36
39
|
export type NavigationSubscription = {
|
|
@@ -69,25 +72,10 @@ export interface Navigation {
|
|
|
69
72
|
currentRoute(): Promise<Route>
|
|
70
73
|
routeGraph(): Promise<RouteGraph[]>
|
|
71
74
|
setDefaultOptions(options: DefaultOptions): void
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated use `updateOptions` instead
|
|
74
|
-
*/
|
|
75
75
|
setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void
|
|
76
|
-
/**
|
|
77
|
-
* @deprecated use `updateOptions` instead
|
|
78
|
-
*/
|
|
79
76
|
setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated use `updateOptions` instead
|
|
82
|
-
*/
|
|
83
77
|
setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void
|
|
84
|
-
/**
|
|
85
|
-
* @deprecated use `updateOptions` instead
|
|
86
|
-
*/
|
|
87
78
|
setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void
|
|
88
|
-
/**
|
|
89
|
-
* @deprecated use `updateOptions` instead
|
|
90
|
-
*/
|
|
91
79
|
setTitleItem(sceneId: string, titleItem: TitleItem): void
|
|
92
80
|
updateOptions(sceneId: string, options: NavigationOption): void
|
|
93
81
|
updateTabBar(sceneId: string, options: TabBarStyle): void
|
|
@@ -251,33 +239,31 @@ class NavigationImpl implements Navigation {
|
|
|
251
239
|
}
|
|
252
240
|
|
|
253
241
|
setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
|
|
254
|
-
|
|
255
|
-
|
|
242
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItem)
|
|
243
|
+
GardenModule.setLeftBarButtonItem(sceneId, options)
|
|
256
244
|
}
|
|
257
245
|
|
|
258
246
|
setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null) {
|
|
259
|
-
|
|
260
|
-
|
|
247
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItem)
|
|
248
|
+
GardenModule.setRightBarButtonItem(sceneId, options)
|
|
261
249
|
}
|
|
262
250
|
|
|
263
251
|
setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
264
|
-
|
|
265
|
-
|
|
252
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems)
|
|
253
|
+
GardenModule.setLeftBarButtonItems(sceneId, options)
|
|
266
254
|
}
|
|
267
255
|
|
|
268
256
|
setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null) {
|
|
269
|
-
|
|
270
|
-
|
|
257
|
+
const options = this.bindBarButtonClickEvent(sceneId, buttonItems)
|
|
258
|
+
GardenModule.setRightBarButtonItems(sceneId, options)
|
|
271
259
|
}
|
|
272
260
|
|
|
273
261
|
setTitleItem(sceneId: string, titleItem: TitleItem) {
|
|
274
|
-
|
|
275
|
-
this.updateOptions(sceneId, { titleItem })
|
|
262
|
+
GardenModule.setTitleItem(sceneId, titleItem)
|
|
276
263
|
}
|
|
277
264
|
|
|
278
265
|
updateOptions(sceneId: string, options: NavigationOption) {
|
|
279
|
-
|
|
280
|
-
GardenModule.updateOptions(sceneId, object)
|
|
266
|
+
GardenModule.updateOptions(sceneId, options)
|
|
281
267
|
}
|
|
282
268
|
|
|
283
269
|
updateTabBar(sceneId: string, options: TabBarStyle) {
|
|
@@ -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 = {
|
package/src/Options.ts
CHANGED
|
@@ -21,9 +21,6 @@ export const LayoutFittingCompressed = 'compressed'
|
|
|
21
21
|
export type LayoutFittingCompressed = typeof LayoutFittingCompressed
|
|
22
22
|
export type LayoutFitting = LayoutFittingExpanded | LayoutFittingCompressed
|
|
23
23
|
|
|
24
|
-
export type Nullable<T> = {
|
|
25
|
-
[P in keyof T]: T[P] extends T[P] | undefined ? T[P] | null : T[P]
|
|
26
|
-
}
|
|
27
24
|
export interface NavigationOption {
|
|
28
25
|
screenBackgroundColor?: Color // 页面背景,默认是白色
|
|
29
26
|
statusBarHidden?: boolean // 是否隐藏状态栏
|
|
@@ -43,12 +40,6 @@ export interface NavigationOption {
|
|
|
43
40
|
|
|
44
41
|
backButtonHidden?: boolean // 是否显示返回按钮
|
|
45
42
|
backInteractive?: boolean // 是否允许侧滑返回或通过返回键返回
|
|
46
|
-
|
|
47
|
-
titleItem?: TitleItem
|
|
48
|
-
leftBarButtonItem?: Nullable<BarButtonItem> | null
|
|
49
|
-
rightBarButtonItem?: Nullable<BarButtonItem> | null
|
|
50
|
-
leftBarButtonItems?: Nullable<BarButtonItem>[] | null
|
|
51
|
-
rightBarButtonItems?: Nullable<BarButtonItem>[] | null
|
|
52
43
|
}
|
|
53
44
|
|
|
54
45
|
export interface NavigationItem extends NavigationOption {
|
|
@@ -57,7 +48,11 @@ export interface NavigationItem extends NavigationOption {
|
|
|
57
48
|
topBarHidden?: boolean // 是否隐藏 TopBar
|
|
58
49
|
extendedLayoutIncludesTopBar?: boolean // 页面内容是否延伸到 TopBar 底下,通常用于需要动态改变 `topBarAlpha` 的场合
|
|
59
50
|
swipeBackEnabled?: boolean // 是否可以通过右滑返回。如果 `backInteractive` 设置为 false, 那么该值无效。Android 下,只有开启了侧滑返回功能,该值才会生效。
|
|
60
|
-
|
|
51
|
+
titleItem?: TitleItem
|
|
52
|
+
leftBarButtonItem?: BarButtonItem
|
|
53
|
+
rightBarButtonItem?: BarButtonItem
|
|
54
|
+
leftBarButtonItems?: BarButtonItem[]
|
|
55
|
+
rightBarButtonItems?: BarButtonItem[]
|
|
61
56
|
backItemIOS?: BackItem
|
|
62
57
|
tabItem?: TabItem
|
|
63
58
|
}
|
|
@@ -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
|
-
export
|
|
11
|
+
export { Navigator } 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'
|