hybrid-navigation 2.8.1 → 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 CHANGED
@@ -1,3 +1,45 @@
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
+
31
+ ## 2.8.3 (2022-05-05)
32
+
33
+ ### Android
34
+
35
+ - 修复 reload 时,会重复 run application 的问题
36
+
37
+ ## 2.8.2 (2022-04-27)
38
+
39
+ ### iOS specific
40
+
41
+ - 修复由于隐藏 back title 而导致 back icon 在转场时表现异常的问题
42
+
1
43
  ## 2.8.1 (2022-04-25)
2
44
 
3
45
  ### iOS specific
@@ -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
 
@@ -65,6 +62,23 @@ public class HBDReactRootView extends ReactRootView {
65
62
  super.startReactApplication(reactInstanceManager, moduleName, initialProperties);
66
63
  removeOnGlobalLayoutListener();
67
64
  }
65
+
66
+ // 避免 reload 时,重复 run 的问题
67
+ private boolean shouldRunApplication = true;
68
+
69
+ @Override
70
+ public void runApplication() {
71
+ if (shouldRunApplication) {
72
+ shouldRunApplication = false;
73
+ super.runApplication();
74
+ }
75
+ }
76
+
77
+ @Override
78
+ public void setAppProperties(@Nullable Bundle appProperties) {
79
+ shouldRunApplication = true;
80
+ super.setAppProperties(appProperties);
81
+ }
68
82
 
69
83
  @Override
70
84
  public void unmountReactApplication() {
@@ -80,11 +94,7 @@ public class HBDReactRootView extends ReactRootView {
80
94
  Method method = ReactRootView.class.getDeclaredMethod("getCustomGlobalLayoutListener");
81
95
  method.setAccessible(true);
82
96
  mGlobalLayoutListener = (ViewTreeObserver.OnGlobalLayoutListener) method.invoke(this);
83
- } catch (NoSuchMethodException e) {
84
- e.printStackTrace();
85
- } catch (IllegalAccessException e) {
86
- e.printStackTrace();
87
- } catch (InvocationTargetException e) {
97
+ } catch (Exception e) {
88
98
  e.printStackTrace();
89
99
  }
90
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().addView(reactTitleView, layoutParams);
262
- reactTitleView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
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];
@@ -174,7 +174,7 @@
174
174
  }
175
175
 
176
176
  if ([GlobalStyle globalStyle].isBackTitleHidden) {
177
- UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] init];
177
+ UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
178
178
  self.navigationItem.backBarButtonItem = buttonItem;
179
179
  }
180
180
 
@@ -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>;
@@ -74,24 +74,28 @@ export class ReactRegistry {
74
74
  if (routeConfig) {
75
75
  router.registerRoute(appKey, routeConfig);
76
76
  }
77
- const WrappedComponent = getComponentFunc();
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
- WrappedComponent.navigationItem = item;
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 {};
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.8.1",
4
+ "version": "2.9.0",
5
5
  "keywords": [
6
6
  "react-native",
7
7
  "navigation",