hybrid-navigation 2.15.15 → 2.16.0-beta.2

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.
@@ -33,5 +33,5 @@ dependencies {
33
33
  implementation fileTree(dir: 'libs', include: ['*.jar'])
34
34
  implementation 'com.facebook.react:react-native:+'
35
35
  // api project(':navigation')
36
- api 'io.github.listenzz:AndroidNavigation:13.5.11'
36
+ api 'io.github.listenzz:AndroidNavigation:13.6.0'
37
37
  }
@@ -26,15 +26,14 @@ import androidx.appcompat.widget.Toolbar;
26
26
  import com.facebook.react.bridge.Arguments;
27
27
  import com.facebook.react.bridge.ReactContext;
28
28
  import com.facebook.react.common.LifecycleState;
29
- import com.navigation.androidx.FragmentHelper;
30
29
  import com.navigation.androidx.Style;
31
30
 
32
- public class ReactFragment extends HybridFragment implements ReactRootViewHolder.VisibilityObserver, ReactBridgeManager.ReactBridgeReloadListener {
31
+ public class ReactFragment extends HybridFragment implements ReactBridgeManager.ReactBridgeReloadListener {
33
32
 
34
33
  protected static final String TAG = "Navigation";
35
34
 
36
- private ViewGroup containerLayout;
37
- private ReactRootViewHolder reactRootViewHolder;
35
+ private ViewGroup reactViewHolder;
36
+
38
37
  private HBDReactRootView reactRootView;
39
38
  private HBDReactRootView reactTitleView;
40
39
  private boolean firstRenderCompleted;
@@ -43,16 +42,8 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
43
42
  @Override
44
43
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
45
44
  View view = inflater.inflate(R.layout.nav_fragment_react, container, false);
46
- containerLayout = view.findViewById(R.id.react_content);
47
- if (containerLayout instanceof ReactRootViewHolder) {
48
- reactRootViewHolder = (ReactRootViewHolder) containerLayout;
49
- reactRootViewHolder.setVisibilityObserver(this);
50
- }
51
-
52
- if (!FragmentHelper.isHidden(this) || getShowsDialog()) {
53
- initReactRootView();
54
- }
55
-
45
+ reactViewHolder = view.findViewById(R.id.react_content);
46
+ mountReactView();
56
47
  return view;
57
48
  }
58
49
 
@@ -75,25 +66,9 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
75
66
  }
76
67
  }
77
68
 
78
- @Override
79
- public void inspectVisibility(int visibility) {
80
- if (visibility != View.VISIBLE) {
81
- return;
82
- }
83
- if (reactRootView == null) {
84
- initReactRootView();
85
- initReactTitleView();
86
- }
87
- }
88
-
89
69
  @Override
90
70
  public void onResume() {
91
71
  super.onResume();
92
- if (reactRootView == null) {
93
- initReactRootView();
94
- initReactTitleView();
95
- }
96
-
97
72
  if (isViewReady()) {
98
73
  reactRootView.addOnGlobalLayoutListener();
99
74
  sendViewAppearEvent(true);
@@ -141,21 +116,9 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
141
116
  HBDEventEmitter.sendEvent(EVENT_NAVIGATION, Arguments.fromBundle(bundle));
142
117
  }
143
118
 
144
- @Override
145
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
146
- super.onViewCreated(view, savedInstanceState);
147
- if (!FragmentHelper.isHidden(this)) {
148
- initReactTitleView();
149
- }
150
- getReactBridgeManager().addReactBridgeReloadListener(this);
151
- }
152
-
153
119
  @Override
154
120
  public void onDestroyView() {
155
121
  super.onDestroyView();
156
- if (reactRootViewHolder != null) {
157
- reactRootViewHolder.setVisibilityObserver(null);
158
- }
159
122
  unmountReactView();
160
123
  }
161
124
 
@@ -164,6 +127,12 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
164
127
  unmountReactView();
165
128
  }
166
129
 
130
+ private void mountReactView() {
131
+ initReactRootView();
132
+ initReactTitleView();
133
+ getReactBridgeManager().addReactBridgeReloadListener(this);
134
+ }
135
+
167
136
  private void unmountReactView() {
168
137
  getReactBridgeManager().removeReactBridgeReloadListener(this);
169
138
 
@@ -174,11 +143,15 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
174
143
 
175
144
  if (reactRootView != null) {
176
145
  reactRootView.unmountReactApplication();
146
+ ViewGroup parent = (ViewGroup) reactRootView.getParent();
147
+ parent.removeView(reactRootView);
177
148
  reactRootView = null;
178
149
  }
179
150
 
180
151
  if (reactTitleView != null) {
181
152
  reactTitleView.unmountReactApplication();
153
+ ViewGroup parent = (ViewGroup) reactTitleView.getParent();
154
+ parent.removeView(reactTitleView);
182
155
  reactTitleView = null;
183
156
  }
184
157
  }
@@ -233,14 +206,12 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
233
206
  }
234
207
 
235
208
  private void initReactRootView() {
236
- if (reactRootView != null) {
237
- return;
209
+ if (!isReactModuleRegisterCompleted()) {
210
+ throw new IllegalStateException("[Navigation] React Component 还没有注册完毕。");
238
211
  }
239
212
 
240
- if (isReactModuleRegisterCompleted()) {
241
- reactRootView = createReactRootView();
242
- reactRootView.startReactApplication(getReactInstanceManager(), getModuleName(), getProps());
243
- }
213
+ reactRootView = createReactRootView();
214
+ reactRootView.startReactApplication(getReactInstanceManager(), getModuleName(), getProps());
244
215
  }
245
216
 
246
217
  @NonNull
@@ -248,19 +219,11 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
248
219
  HBDReactRootView reactRootView = new HBDReactRootView(getContext());
249
220
  reactRootView.setShouldConsumeTouchEvent(!shouldPassThroughTouches());
250
221
  ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT);
251
- containerLayout.addView(reactRootView, layoutParams);
222
+ reactViewHolder.addView(reactRootView, layoutParams);
252
223
  return reactRootView;
253
224
  }
254
225
 
255
226
  private void initReactTitleView() {
256
- if (reactTitleView != null) {
257
- return;
258
- }
259
-
260
- if (!isReactModuleRegisterCompleted()) {
261
- return;
262
- }
263
-
264
227
  if (getToolbar() == null) {
265
228
  return;
266
229
  }
@@ -275,6 +238,10 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
275
238
  return;
276
239
  }
277
240
 
241
+ if (!isReactModuleRegisterCompleted()) {
242
+ throw new IllegalStateException("[Navigation] React Component 还没有注册完毕。");
243
+ }
244
+
278
245
  String fitting = titleItem.getString("layoutFitting");
279
246
  boolean expanded = "expanded".equals(fitting);
280
247
  reactTitleView = createReactTitleView(expanded);
@@ -1,8 +1,7 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
- <com.reactnative.hybridnavigation.ReactFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
3
  android:id="@+id/react_content"
4
4
  android:layout_width="match_parent"
5
- android:layout_height="match_parent"
6
- android:orientation="vertical">
5
+ android:layout_height="match_parent">
7
6
 
8
- </com.reactnative.hybridnavigation.ReactFrameLayout>
7
+ </FrameLayout>
@@ -31,10 +31,6 @@
31
31
  [self.view addSubview:self.contentController.view];
32
32
  [self.contentController didMoveToParentViewController:self];
33
33
 
34
- [self addChildViewController:self.menuController];
35
- self.menuController.view.frame = CGRectZero;
36
- [self.menuController didMoveToParentViewController:self];
37
-
38
34
  UIScreenEdgePanGestureRecognizer *edgePanGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleEdgePanGestureRecognizer:)];
39
35
  edgePanGestureRecognizer.edges = UIRectEdgeLeft;
40
36
  edgePanGestureRecognizer.delegate = self;
@@ -184,6 +180,11 @@
184
180
  UIViewController *menu = self.menuController;
185
181
  CGFloat menuWidth = [self menuWidth];
186
182
  menu.view.frame = CGRectMake(-menuWidth, 0, menuWidth, CGRectGetHeight(self.view.bounds));
183
+ if (!menu.parentViewController) {
184
+ [self addChildViewController:menu];
185
+ [menu didMoveToParentViewController:self];
186
+ }
187
+
187
188
  UIView *menuHolderView = [[UIView alloc] initWithFrame:self.view.bounds];
188
189
  self.menuHolderView = menuHolderView;
189
190
  UIView *dimmingView = [[UIView alloc] initWithFrame:self.view.bounds];
@@ -17,28 +17,14 @@ export type NavigationSubscription = {
17
17
  };
18
18
  export type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
19
19
  export interface Navigation {
20
- }
21
- export declare class Navigation implements Navigation {
22
- private dispatchHandler;
23
- private resultHandler;
24
- private buttonHandler;
25
- private layoutHandler;
26
- private visibilityHandler;
27
- constructor();
28
- private wrap?;
29
- private hoc?;
30
- private registerEnded;
31
20
  startRegisterComponent(hoc?: HOC): void;
32
21
  endRegisterComponent(): void;
33
22
  registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
34
- private _routeConfigs;
35
- private registerRoute;
36
23
  routeConfigs(): Map<string, RouteConfig>;
37
24
  setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void;
38
25
  addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription;
39
26
  addVisibilityEventListener(sceneId: string, listener: VisibilityEventListener): NavigationSubscription;
40
27
  dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>;
41
- private handleTabSwitch;
42
28
  setInterceptor(interceptor: NavigationInterceptor): void;
43
29
  setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void;
44
30
  result<T extends ResultType>(sceneId: string, resultCode: number): Promise<[number, T]>;
@@ -62,7 +48,6 @@ export declare class Navigation implements Navigation {
62
48
  setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void;
63
49
  setMenuInteractive(sceneId: string, enabled: boolean): void;
64
50
  setBarButtonClickEventListener(listener: BarButtonClickEventListener): void;
65
- private bindBarButtonClickEvent;
66
51
  }
67
52
  declare const _default: Navigation;
68
53
  export default _default;
package/lib/Navigation.js CHANGED
@@ -8,7 +8,7 @@ import Event from './Event';
8
8
  import GardenModule from './GardenModule';
9
9
  import NavigationModule from './NavigationModule';
10
10
  export const { RESULT_CANCEL, RESULT_OK } = NavigationModule.getConstants();
11
- export class Navigation {
11
+ class NavigationImpl {
12
12
  dispatchHandler = new DispatchCommandHandler();
13
13
  resultHandler = new ResultEventHandler();
14
14
  buttonHandler = new BarButtonEventHandler();
@@ -159,4 +159,4 @@ export class Navigation {
159
159
  return this.buttonHandler.bindBarButtonClickEvent(sceneId, item);
160
160
  }
161
161
  }
162
- export default new Navigation();
162
+ export default new NavigationImpl();
@@ -1,16 +1,10 @@
1
1
  import React from 'react';
2
- import type { Garden } from './Garden';
3
2
  import type { NavigationItem } from './Options';
4
3
  import { Navigator } from './Navigator';
5
4
  export interface NavigationProps {
6
5
  navigator: Navigator;
7
- garden: Garden;
8
6
  sceneId: string;
9
7
  }
10
- /**
11
- * @deprecated Use NavigationProps instead.
12
- */
13
- export type InjectedProps = NavigationProps;
14
8
  interface NativeProps {
15
9
  sceneId: string;
16
10
  }
@@ -12,19 +12,14 @@ export function withNavigation(moduleName) {
12
12
  if (navigator.moduleName === undefined) {
13
13
  navigator.moduleName = moduleName;
14
14
  }
15
- const garden = navigator.garden;
16
15
  useEffect(() => {
17
16
  Navigation.signalFirstRenderComplete(navigator.sceneId);
18
17
  return () => {
19
18
  navigator.unmount();
20
19
  };
21
20
  }, [navigator]);
22
- const injected = {
23
- garden,
24
- navigator,
25
- };
26
21
  return (<NavigationContext.Provider value={navigator}>
27
- <WrappedComponent ref={ref} {...props} {...injected}/>
22
+ <WrappedComponent ref={ref} {...props} navigator={navigator}/>
28
23
  </NavigationContext.Provider>);
29
24
  });
30
25
  FC.displayName = `withNavigation(${getDisplayName(WrappedComponent)})`;
@@ -1,8 +1,7 @@
1
1
  /// <reference types="react" />
2
- import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route';
2
+ import type { Visibility, Layout, BuildInLayout } from './Route';
3
3
  import type { NavigationItem } from './Options';
4
- import { Garden } from './Garden';
5
- import { NavigationInterceptor, DispatchParams, ResultType } from './Navigation';
4
+ import { ResultType } from './Navigation';
6
5
  export declare const NavigationContext: import("react").Context<any>;
7
6
  interface NavigationState {
8
7
  params: {
@@ -20,47 +19,7 @@ export declare class Navigator implements Navigator {
20
19
  static of(sceneId: string): Navigator;
21
20
  static find(moduleName: string): Promise<Navigator | undefined>;
22
21
  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;
58
22
  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;
64
23
  visibility: Visibility;
65
24
  readonly state: NavigationState;
66
25
  setParams: (params: {
package/lib/Navigator.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { createContext } from 'react';
2
2
  import store from './store';
3
- import { Garden } from './Garden';
4
- import Navigation, { RESULT_CANCEL, } from './Navigation';
3
+ import Navigation, { RESULT_CANCEL } from './Navigation';
5
4
  export const NavigationContext = createContext(null);
6
5
  let tagGenerator = 0;
7
6
  Navigation.addGlobalVisibilityEventListener((sceneId, visibility) => {
@@ -35,67 +34,10 @@ export class Navigator {
35
34
  const route = await Navigation.currentRoute();
36
35
  return Navigator.of(route.sceneId);
37
36
  }
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
- }
85
37
  constructor(sceneId, moduleName) {
86
38
  this.sceneId = sceneId;
87
39
  this.moduleName = moduleName;
88
40
  }
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
- }
99
41
  visibility = 'pending';
100
42
  state = {
101
43
  params: {},
package/lib/hooks.d.ts CHANGED
@@ -4,8 +4,3 @@ 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,11 +42,3 @@ 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,10 +2,8 @@ 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, InjectedProps } from './NavigationComponentWrap';
5
+ export { withNavigationItem, NavigationProps } from './NavigationComponentWrap';
6
6
  export * from './Navigator';
7
- export * from './Garden';
8
- export * from './ReactRegistry';
9
7
  export * from './hooks';
10
8
  export * from './router';
11
9
  export * from './DeepLink';
package/lib/index.js CHANGED
@@ -6,8 +6,6 @@ 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';
11
9
  export * from './hooks';
12
10
  export * from './router';
13
11
  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.15.15",
4
+ "version": "2.16.0-beta.2",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
package/src/Navigation.ts CHANGED
@@ -42,9 +42,49 @@ export type NavigationSubscription = {
42
42
 
43
43
  export type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>
44
44
 
45
- export interface Navigation {}
45
+ export interface Navigation {
46
+ startRegisterComponent(hoc?: HOC): void
47
+ endRegisterComponent(): void
48
+ registerComponent(
49
+ appKey: string,
50
+ getComponentFunc: ComponentProvider,
51
+ routeConfig?: RouteConfig,
52
+ ): void
53
+
54
+ routeConfigs(): Map<string, RouteConfig>
55
+ setNavigationComponentWrap(wrap: (moduleName: string) => HOC): void
56
+ addGlobalVisibilityEventListener(listener: GlobalVisibilityEventListener): NavigationSubscription
57
+ addVisibilityEventListener(
58
+ sceneId: string,
59
+ listener: VisibilityEventListener,
60
+ ): NavigationSubscription
61
+ dispatch(sceneId: string, action: string, params?: DispatchParams): Promise<boolean>
62
+ setInterceptor(interceptor: NavigationInterceptor): void
63
+ setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void
64
+ result<T extends ResultType>(sceneId: string, resultCode: number): Promise<[number, T]>
65
+ unmount(sceneId: string): void
66
+ setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>
67
+ setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void
68
+ currentTab(sceneId: string): Promise<number>
69
+ findSceneIdByModuleName(moduleName: string): Promise<string | null>
70
+ isStackRoot(sceneId: string): Promise<boolean>
71
+ signalFirstRenderComplete(sceneId: string): void
72
+ currentRoute(): Promise<Route>
73
+ routeGraph(): Promise<RouteGraph[]>
74
+ setDefaultOptions(options: DefaultOptions): void
75
+ setLeftBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void
76
+ setRightBarButtonItem(sceneId: string, buttonItem: Nullable<BarButtonItem> | null): void
77
+ setLeftBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void
78
+ setRightBarButtonItems(sceneId: string, buttonItems: Array<Nullable<BarButtonItem>> | null): void
79
+ setTitleItem(sceneId: string, titleItem: TitleItem): void
80
+ updateOptions(sceneId: string, options: NavigationOption): void
81
+ updateTabBar(sceneId: string, options: TabBarStyle): void
82
+ setTabItem(sceneId: string, item: TabItemInfo | TabItemInfo[]): void
83
+ setMenuInteractive(sceneId: string, enabled: boolean): void
84
+ setBarButtonClickEventListener(listener: BarButtonClickEventListener): void
85
+ }
46
86
 
47
- export class Navigation implements Navigation {
87
+ class NavigationImpl implements Navigation {
48
88
  private dispatchHandler = new DispatchCommandHandler()
49
89
  private resultHandler = new ResultEventHandler()
50
90
  private buttonHandler = new BarButtonEventHandler()
@@ -250,4 +290,4 @@ export class Navigation implements Navigation {
250
290
  }
251
291
  }
252
292
 
253
- export default new Navigation()
293
+ export default new NavigationImpl() as Navigation
@@ -1,20 +1,13 @@
1
1
  import React, { useEffect } from 'react'
2
- import type { Garden } from './Garden'
3
2
  import type { NavigationItem } from './Options'
4
3
  import { Navigator, NavigationContext } from './Navigator'
5
4
  import Navigation from './Navigation'
6
5
 
7
6
  export interface NavigationProps {
8
7
  navigator: Navigator
9
- garden: Garden
10
8
  sceneId: string
11
9
  }
12
10
 
13
- /**
14
- * @deprecated Use NavigationProps instead.
15
- */
16
- export type InjectedProps = NavigationProps
17
-
18
11
  interface NativeProps {
19
12
  sceneId: string
20
13
  }
@@ -33,8 +26,6 @@ export function withNavigation(moduleName: string) {
33
26
  navigator.moduleName = moduleName
34
27
  }
35
28
 
36
- const garden = navigator.garden
37
-
38
29
  useEffect(() => {
39
30
  Navigation.signalFirstRenderComplete(navigator.sceneId)
40
31
  return () => {
@@ -42,14 +33,9 @@ export function withNavigation(moduleName: string) {
42
33
  }
43
34
  }, [navigator])
44
35
 
45
- const injected = {
46
- garden,
47
- navigator,
48
- }
49
-
50
36
  return (
51
37
  <NavigationContext.Provider value={navigator}>
52
- <WrappedComponent ref={ref} {...props} {...injected} />
38
+ <WrappedComponent ref={ref} {...props} navigator={navigator} />
53
39
  </NavigationContext.Provider>
54
40
  )
55
41
  })
package/src/Navigator.ts CHANGED
@@ -1,15 +1,9 @@
1
1
  import { createContext } from 'react'
2
2
 
3
3
  import store from './store'
4
- import type { Visibility, Layout, BuildInLayout, Route, RouteGraph } from './Route'
4
+ import type { Visibility, Layout, BuildInLayout } from './Route'
5
5
  import type { NavigationItem } from './Options'
6
- import { Garden } from './Garden'
7
- import Navigation, {
8
- NavigationInterceptor,
9
- DispatchParams,
10
- ResultType,
11
- RESULT_CANCEL,
12
- } from './Navigation'
6
+ import Navigation, { ResultType, RESULT_CANCEL } from './Navigation'
13
7
 
14
8
  export const NavigationContext = createContext<any>(null)
15
9
 
@@ -59,77 +53,8 @@ export class Navigator implements Navigator {
59
53
  return Navigator.of(route.sceneId)
60
54
  }
61
55
 
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
-
119
56
  constructor(public sceneId: string, public moduleName?: string) {}
120
57
 
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
-
133
58
  visibility: Visibility = 'pending'
134
59
 
135
60
  readonly state: NavigationState = {
package/src/hooks.ts CHANGED
@@ -50,12 +50,3 @@ 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,11 +6,9 @@ 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, InjectedProps } from './NavigationComponentWrap'
9
+ export { withNavigationItem, NavigationProps } from './NavigationComponentWrap'
10
10
 
11
11
  export * from './Navigator'
12
- export * from './Garden'
13
- export * from './ReactRegistry'
14
12
  export * from './hooks'
15
13
  export * from './router'
16
14
  export * from './DeepLink'
@@ -1,58 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- import android.content.Context;
4
- import android.util.AttributeSet;
5
- import android.view.View;
6
- import android.widget.FrameLayout;
7
-
8
- public class ReactFrameLayout extends FrameLayout implements ReactRootViewHolder {
9
- protected static final String TAG = "Navigation";
10
-
11
- private HBDReactRootView mReactRootView;
12
- private VisibilityObserver mVisibilityObserver;
13
-
14
- public ReactFrameLayout(Context context) {
15
- super(context);
16
- }
17
-
18
- public ReactFrameLayout(Context context, AttributeSet attrs) {
19
- super(context, attrs);
20
- }
21
-
22
- public ReactFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
23
- super(context, attrs, defStyleAttr);
24
- }
25
-
26
- public ReactFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
27
- super(context, attrs, defStyleAttr, defStyleRes);
28
- }
29
-
30
- @Override
31
- public void onViewAdded(View child) {
32
- super.onViewAdded(child);
33
- if (child instanceof HBDReactRootView) {
34
- mReactRootView = (HBDReactRootView) child;
35
- }
36
- }
37
-
38
- @Override
39
- protected void onDetachedFromWindow() {
40
- super.onDetachedFromWindow();
41
- if (mReactRootView != null) {
42
- removeView(mReactRootView);
43
- }
44
- }
45
-
46
- @Override
47
- public void setVisibility(int visibility) {
48
- super.setVisibility(visibility);
49
- if (mVisibilityObserver != null) {
50
- mVisibilityObserver.inspectVisibility(visibility);
51
- }
52
- }
53
-
54
- @Override
55
- public void setVisibilityObserver(VisibilityObserver observer) {
56
- mVisibilityObserver = observer;
57
- }
58
- }
@@ -1,11 +0,0 @@
1
- package com.reactnative.hybridnavigation;
2
-
3
- public interface ReactRootViewHolder {
4
-
5
- interface VisibilityObserver {
6
- void inspectVisibility(int visibility);
7
- }
8
-
9
- void setVisibilityObserver(VisibilityObserver observer);
10
-
11
- }
package/lib/Garden.d.ts DELETED
@@ -1,65 +0,0 @@
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 DELETED
@@ -1,81 +0,0 @@
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,25 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
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/src/Garden.ts DELETED
@@ -1,103 +0,0 @@
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,39 +0,0 @@
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
- }