hybrid-navigation 2.8.3 → 2.9.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/CHANGELOG.md +30 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +5 -2
- package/docs/qa.md +24 -0
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +16 -0
- package/lib/Navigator.d.ts +6 -6
- package/lib/ReactRegistry.js +14 -10
- package/lib/typing.d.ts +7 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
## 2.9.0 (2022-05-11)
|
|
2
|
+
|
|
3
|
+
- 调整传递给 `ReactRegistry.startRegisterComponent` 的 [HOC](https://zh-hans.reactjs.org/docs/higher-order-components.html) 的使用顺序,现在可以通过以下方式全局设置页面特定属性:
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
ReactRegistry.startRegisterComponent(withNavigationItem({ topBarHidden: true }))
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
⚠️ 实现 HOC 时,注意传递 props 给被包裹的组件,以及注意复制 `navigationItem` 这个静态属性,如
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
export function withRedux(WrappedComponent: ComponentType<any>) {
|
|
13
|
+
return class ReduxProvider extends React.Component {
|
|
14
|
+
// 注意复制 navigationItem
|
|
15
|
+
static navigationItem = (WrappedComponent as any).navigationItem
|
|
16
|
+
|
|
17
|
+
static displayName = `withRedux(${WrappedComponent.displayName})`
|
|
18
|
+
|
|
19
|
+
render() {
|
|
20
|
+
return (
|
|
21
|
+
<Provider store={store}>
|
|
22
|
+
// 注意传递 props 属性
|
|
23
|
+
<WrappedComponent {...this.props} />
|
|
24
|
+
</Provider>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
1
31
|
## 2.8.3 (2022-05-05)
|
|
2
32
|
|
|
3
33
|
### Android
|
|
@@ -2,9 +2,7 @@ package com.reactnative.hybridnavigation;
|
|
|
2
2
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.os.Bundle;
|
|
5
|
-
import android.os.SystemClock;
|
|
6
5
|
import android.util.AttributeSet;
|
|
7
|
-
import android.view.InputDevice;
|
|
8
6
|
import android.view.MotionEvent;
|
|
9
7
|
import android.view.ViewTreeObserver;
|
|
10
8
|
|
|
@@ -13,7 +11,6 @@ import androidx.annotation.Nullable;
|
|
|
13
11
|
import com.facebook.react.ReactInstanceManager;
|
|
14
12
|
import com.facebook.react.ReactRootView;
|
|
15
13
|
|
|
16
|
-
import java.lang.reflect.InvocationTargetException;
|
|
17
14
|
import java.lang.reflect.Method;
|
|
18
15
|
|
|
19
16
|
|
|
@@ -97,11 +94,7 @@ public class HBDReactRootView extends ReactRootView {
|
|
|
97
94
|
Method method = ReactRootView.class.getDeclaredMethod("getCustomGlobalLayoutListener");
|
|
98
95
|
method.setAccessible(true);
|
|
99
96
|
mGlobalLayoutListener = (ViewTreeObserver.OnGlobalLayoutListener) method.invoke(this);
|
|
100
|
-
} catch (
|
|
101
|
-
e.printStackTrace();
|
|
102
|
-
} catch (IllegalAccessException e) {
|
|
103
|
-
e.printStackTrace();
|
|
104
|
-
} catch (InvocationTargetException e) {
|
|
97
|
+
} catch (Exception e) {
|
|
105
98
|
e.printStackTrace();
|
|
106
99
|
}
|
|
107
100
|
}
|
|
@@ -258,8 +258,11 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
|
|
|
258
258
|
} else {
|
|
259
259
|
layoutParams = new Toolbar.LayoutParams(-2, -2, Gravity.CENTER);
|
|
260
260
|
}
|
|
261
|
-
getToolbar()
|
|
262
|
-
|
|
261
|
+
Toolbar toolbar = getToolbar();
|
|
262
|
+
if (toolbar != null) {
|
|
263
|
+
toolbar.addView(reactTitleView, layoutParams);
|
|
264
|
+
reactTitleView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
|
|
265
|
+
}
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
268
|
}
|
package/docs/qa.md
CHANGED
|
@@ -55,3 +55,27 @@ useVisibleEffect(
|
|
|
55
55
|
}, []),
|
|
56
56
|
)
|
|
57
57
|
```
|
|
58
|
+
|
|
59
|
+
## 如何实现 HOC
|
|
60
|
+
|
|
61
|
+
⚠️ 实现 [HOC](https://zh-hans.reactjs.org/docs/higher-order-components.html) 时,注意传递 props 给被包裹的组件,以及注意复制 `navigationItem` 这个静态属性,如
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
export function withRedux(WrappedComponent: ComponentType<any>) {
|
|
65
|
+
return class ReduxProvider extends React.Component {
|
|
66
|
+
// 注意复制 navigationItem
|
|
67
|
+
static navigationItem = (WrappedComponent as any).navigationItem
|
|
68
|
+
|
|
69
|
+
static displayName = `withRedux(${WrappedComponent.displayName})`
|
|
70
|
+
|
|
71
|
+
render() {
|
|
72
|
+
return (
|
|
73
|
+
<Provider store={store}>
|
|
74
|
+
// 注意传递 props 属性
|
|
75
|
+
<WrappedComponent {...this.props} />
|
|
76
|
+
</Provider>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
- (void)setLeftBarButtonItem:(NSDictionary *)item {
|
|
22
|
+
if (self.hbd_barHidden) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
22
26
|
if (item) {
|
|
23
27
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
|
24
28
|
if (@available(iOS 11.0, *)) {
|
|
@@ -43,6 +47,10 @@
|
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
- (void)setRightBarButtonItem:(NSDictionary *)item {
|
|
50
|
+
if (self.hbd_barHidden) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
46
54
|
if (item) {
|
|
47
55
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
|
48
56
|
if (@available(iOS 11.0, *)) {
|
|
@@ -67,6 +75,10 @@
|
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
- (void)setLeftBarButtonItems:(NSArray *)items {
|
|
78
|
+
if (self.hbd_barHidden) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
if (items) {
|
|
71
83
|
NSArray *barButtonItems = [self createBarButtonItems:items];
|
|
72
84
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
|
@@ -93,6 +105,10 @@
|
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
- (void)setRightBarButtonItems:(NSArray *)items {
|
|
108
|
+
if (self.hbd_barHidden) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
96
112
|
if (items) {
|
|
97
113
|
NSArray *barButtonItems = [self createBarButtonItems:items];
|
|
98
114
|
NSMutableArray *array = [[NSMutableArray alloc] init];
|
package/lib/Navigator.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RouteGraph, Route } from './router';
|
|
2
2
|
import { Visibility } from './hooks';
|
|
3
|
-
import { IndexType, ResultType, NavigationInterceptor, Layout, NavigationItem, PropsType } from './typing';
|
|
3
|
+
import { IndexType, ResultType, NavigationInterceptor, Layout, BuildInLayout, NavigationItem, PropsType } from './typing';
|
|
4
4
|
import { Garden } from './Garden';
|
|
5
5
|
interface Params {
|
|
6
6
|
animated?: boolean;
|
|
7
7
|
moduleName?: string;
|
|
8
|
-
layout?: Layout;
|
|
8
|
+
layout?: BuildInLayout | Layout;
|
|
9
9
|
popToRoot?: boolean;
|
|
10
10
|
requestCode?: number;
|
|
11
11
|
props?: IndexType;
|
|
@@ -25,7 +25,7 @@ export declare class Navigator {
|
|
|
25
25
|
static current(): Promise<Navigator>;
|
|
26
26
|
static currentRoute(): Promise<Route>;
|
|
27
27
|
static routeGraph(): Promise<RouteGraph[]>;
|
|
28
|
-
static setRoot(layout: Layout, sticky?: boolean): Promise<void>;
|
|
28
|
+
static setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<void>;
|
|
29
29
|
static setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
|
|
30
30
|
static dispatch(sceneId: string, action: string, params?: Params): Promise<boolean>;
|
|
31
31
|
static setInterceptor(interceptFn: NavigationInterceptor): void;
|
|
@@ -43,17 +43,17 @@ export declare class Navigator {
|
|
|
43
43
|
private resultListener;
|
|
44
44
|
private waitResult;
|
|
45
45
|
push<T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<[number, T]>;
|
|
46
|
-
pushLayout<T extends ResultType>(layout: Layout): Promise<[number, T]>;
|
|
46
|
+
pushLayout<T extends ResultType>(layout: BuildInLayout | Layout): Promise<[number, T]>;
|
|
47
47
|
pop(): Promise<boolean>;
|
|
48
48
|
popTo(moduleName: string, inclusive?: boolean): Promise<boolean>;
|
|
49
49
|
popToRoot(): Promise<boolean>;
|
|
50
50
|
redirectTo<P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<boolean>;
|
|
51
51
|
isStackRoot(): Promise<boolean>;
|
|
52
52
|
present<T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<[number, T]>;
|
|
53
|
-
presentLayout<T extends ResultType>(layout: Layout): Promise<[number, T]>;
|
|
53
|
+
presentLayout<T extends ResultType>(layout: BuildInLayout | Layout): Promise<[number, T]>;
|
|
54
54
|
dismiss(): Promise<boolean>;
|
|
55
55
|
showModal<T extends ResultType, P extends PropsType = PropsType>(moduleName: string, props?: P, options?: NavigationItem): Promise<[number, T]>;
|
|
56
|
-
showModalLayout<T extends ResultType>(layout: Layout): Promise<[number, T]>;
|
|
56
|
+
showModalLayout<T extends ResultType>(layout: BuildInLayout | Layout): Promise<[number, T]>;
|
|
57
57
|
hideModal(): Promise<boolean>;
|
|
58
58
|
setResult<T extends ResultType>(resultCode: number, data?: T): void;
|
|
59
59
|
switchTab(index: number, popToRoot?: boolean): Promise<boolean>;
|
package/lib/ReactRegistry.js
CHANGED
|
@@ -74,24 +74,28 @@ export class ReactRegistry {
|
|
|
74
74
|
if (routeConfig) {
|
|
75
75
|
router.registerRoute(appKey, routeConfig);
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
let WrappedComponent = getComponentFunc();
|
|
78
|
+
if (wrap) {
|
|
79
|
+
WrappedComponent = wrap(WrappedComponent);
|
|
80
|
+
}
|
|
78
81
|
// build static options
|
|
79
82
|
let options = bindBarButtonItemClickEvent(WrappedComponent.navigationItem) || {};
|
|
80
83
|
NavigationModule.registerReactComponent(appKey, options);
|
|
81
|
-
let RootComponent;
|
|
82
|
-
if (wrap) {
|
|
83
|
-
RootComponent = wrap(withNavigator(appKey)(WrappedComponent));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
RootComponent = withNavigator(appKey)(WrappedComponent);
|
|
87
|
-
}
|
|
84
|
+
let RootComponent = withNavigator(appKey)(WrappedComponent);
|
|
88
85
|
AppRegistry.registerComponent(appKey, () => RootComponent);
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
export function withNavigationItem(item) {
|
|
92
89
|
return function (WrappedComponent) {
|
|
93
|
-
;
|
|
94
|
-
|
|
90
|
+
let navigationItem = WrappedComponent.navigationItem;
|
|
91
|
+
if (navigationItem) {
|
|
92
|
+
;
|
|
93
|
+
WrappedComponent.navigationItem = { ...navigationItem, ...item };
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
;
|
|
97
|
+
WrappedComponent.navigationItem = item;
|
|
98
|
+
}
|
|
95
99
|
return WrappedComponent;
|
|
96
100
|
};
|
|
97
101
|
}
|
package/lib/typing.d.ts
CHANGED
|
@@ -94,9 +94,6 @@ export interface TabItem {
|
|
|
94
94
|
unselectedIcon?: ImageSource;
|
|
95
95
|
hideTabBarWhenPush?: boolean;
|
|
96
96
|
}
|
|
97
|
-
export interface Layout {
|
|
98
|
-
[index: string]: {};
|
|
99
|
-
}
|
|
100
97
|
export interface Screen extends Layout {
|
|
101
98
|
screen: {
|
|
102
99
|
moduleName: string;
|
|
@@ -106,13 +103,13 @@ export interface Screen extends Layout {
|
|
|
106
103
|
}
|
|
107
104
|
export interface Stack extends Layout {
|
|
108
105
|
stack: {
|
|
109
|
-
children: Layout
|
|
106
|
+
children: Array<BuildInLayout | Layout>;
|
|
110
107
|
options?: {};
|
|
111
108
|
};
|
|
112
109
|
}
|
|
113
110
|
export interface Tabs extends Layout {
|
|
114
111
|
tabs: {
|
|
115
|
-
children: Layout
|
|
112
|
+
children: Array<BuildInLayout | Layout>;
|
|
116
113
|
options?: {
|
|
117
114
|
selectedIndex?: number;
|
|
118
115
|
tabBarModuleName?: string;
|
|
@@ -122,7 +119,7 @@ export interface Tabs extends Layout {
|
|
|
122
119
|
}
|
|
123
120
|
export interface Drawer extends Layout {
|
|
124
121
|
drawer: {
|
|
125
|
-
children: [Layout, Layout];
|
|
122
|
+
children: [BuildInLayout | Layout, BuildInLayout | Layout];
|
|
126
123
|
options?: {
|
|
127
124
|
maxDrawerWidth?: number;
|
|
128
125
|
minDrawerMargin?: number;
|
|
@@ -130,4 +127,8 @@ export interface Drawer extends Layout {
|
|
|
130
127
|
};
|
|
131
128
|
};
|
|
132
129
|
}
|
|
130
|
+
export declare type BuildInLayout = Screen | Stack | Tabs | Drawer;
|
|
131
|
+
export interface Layout {
|
|
132
|
+
[index: string]: {};
|
|
133
|
+
}
|
|
133
134
|
export {};
|