hybrid-navigation 2.13.6 → 2.13.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -85,6 +85,10 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
85
85
  @Override
86
86
  public void onReactModuleRegisterCompleted() {
87
87
  FLog.i(TAG, "ReactAppCompatActivity#onReactModuleRegisterCompleted");
88
+ if (!isFirstCallResume) {
89
+ isFirstCallResume = true;
90
+ activityDelegate.onResume();
91
+ }
88
92
  createMainComponent();
89
93
  }
90
94
 
@@ -163,19 +167,28 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
163
167
 
164
168
  @Override
165
169
  protected void onPause() {
166
- activityDelegate.onPause();
170
+ ReactContext reactContext = getCurrentReactContext();
171
+ if (reactContext != null) {
172
+ activityDelegate.onPause();
173
+ }
167
174
  super.onPause();
168
175
  }
169
176
 
177
+ private boolean isFirstCallResume;
178
+
170
179
  @Override
171
180
  protected void onResume() {
172
181
  super.onResume();
182
+ if (getReactInstanceManager().hasStartedCreatingInitialContext()) {
183
+ isFirstCallResume = true;
184
+ activityDelegate.onResume();
185
+ }
186
+
173
187
  ReactBridgeManager bridgeManager = getReactBridgeManager();
174
188
  if (bridgeManager.hasPendingLayout()) {
175
189
  FLog.i(TAG, "Set root Fragment from pending layout when resume.");
176
190
  setActivityRootFragment(bridgeManager.getPendingLayout());
177
191
  }
178
- activityDelegate.onResume();
179
192
  }
180
193
 
181
194
  @Override
@@ -60,11 +60,15 @@ public class ReactBridgeManager {
60
60
  private ReactNativeHost reactNativeHost;
61
61
 
62
62
  public void install(@NonNull ReactNativeHost reactNativeHost) {
63
+ this.setReactNativeHost(reactNativeHost);
64
+ this.initialize();
65
+ }
66
+
67
+ public void setReactNativeHost(@NonNull ReactNativeHost reactNativeHost) {
63
68
  this.reactNativeHost = reactNativeHost;
64
- this.setup();
65
69
  }
66
70
 
67
- private void setup() {
71
+ public void initialize() {
68
72
  final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
69
73
  reactInstanceManager.addReactInstanceEventListener(context -> {
70
74
  FLog.i(TAG, "React instance context initialized.");
@@ -248,13 +252,13 @@ public class ReactBridgeManager {
248
252
  AwesomeFragment fragment = fragments.get(i);
249
253
  Bundle bundle = buildRouteGraph(fragment);
250
254
  if (bundle == null) {
251
- continue;
255
+ continue;
252
256
  }
253
257
  root.add(bundle);
254
258
  }
255
259
  return root;
256
260
  }
257
-
261
+
258
262
  @Nullable
259
263
  public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
260
264
  String layout = navigatorRegistry.layoutForFragment(fragment);
@@ -366,7 +370,7 @@ public class ReactBridgeManager {
366
370
  args.putBundle(Constants.ARG_PROPS, notNull(props));
367
371
  args.putBundle(Constants.ARG_OPTIONS, mergeOptions(moduleName, notNull(options)));
368
372
  args.putString(Constants.ARG_MODULE_NAME, moduleName);
369
-
373
+
370
374
  fragment.setArguments(args);
371
375
 
372
376
  return fragment;
@@ -383,7 +387,7 @@ public class ReactBridgeManager {
383
387
  if (!hasReactModule(moduleName)) {
384
388
  return options;
385
389
  }
386
-
390
+
387
391
  ReadableMap readableMap = reactModuleOptionsForKey(moduleName);
388
392
  WritableMap writableMap = Arguments.createMap();
389
393
  writableMap.merge(readableMap);
@@ -165,10 +165,9 @@ public class StackNavigator implements Navigator {
165
165
  callback.invoke(null, false);
166
166
  return;
167
167
  }
168
-
169
- boolean inclusive = extras.getBoolean("inclusive");
168
+
170
169
  FragmentManager fragmentManager = stackFragment.getChildFragmentManager();
171
- AwesomeFragment fragment = findFragmentForPopTo(moduleName, inclusive, fragmentManager);
170
+ AwesomeFragment fragment = findFragmentForPopTo(moduleName, inclusive(extras), fragmentManager);
172
171
  if (fragment == null) {
173
172
  callback.invoke(null, false);
174
173
  return;
@@ -176,6 +175,13 @@ public class StackNavigator implements Navigator {
176
175
 
177
176
  stackFragment.popToFragment(fragment, () -> callback.invoke(null, true));
178
177
  }
178
+
179
+ private boolean inclusive(@NonNull ReadableMap extras) {
180
+ if (extras.hasKey("inclusive")) {
181
+ return extras.getBoolean("inclusive");
182
+ }
183
+ return false;
184
+ }
179
185
 
180
186
  @Nullable
181
187
  private AwesomeFragment findFragmentForPopTo(String moduleName, boolean inclusive, FragmentManager fragmentManager) {
@@ -5,6 +5,8 @@
5
5
  #import "UINavigationController+HBD.h"
6
6
  #import "HBDAnimationObserver.h"
7
7
 
8
+ #import <React/RCTLog.h>
9
+
8
10
  @implementation HBDStackNavigator
9
11
 
10
12
  - (NSString *)name {
@@ -72,7 +74,10 @@
72
74
  [nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
73
75
  // empty
74
76
  } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
75
- [self handleNavigationWithViewController:vc action:action extras:extras callback:callback];
77
+ // 确保最后执行
78
+ dispatch_async(dispatch_get_main_queue(), ^{
79
+ [self handleNavigationWithViewController:vc action:action extras:extras callback:callback];
80
+ });
76
81
  }];
77
82
  return;
78
83
  }
@@ -124,7 +129,7 @@
124
129
  callback(@[NSNull.null, @NO]);
125
130
  return;
126
131
  }
127
-
132
+
128
133
  vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
129
134
  [[HBDAnimationObserver sharedObserver] beginAnimation];
130
135
  [nav pushViewController:vc animated:YES];
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { Navigator, NavigationContext } from './Navigator';
3
+ import Navigation from './Navigation';
3
4
  function getDisplayName(WrappedComponent) {
4
5
  return WrappedComponent.displayName || WrappedComponent.name || 'Component';
5
6
  }
@@ -13,7 +14,7 @@ export function withNavigation(moduleName) {
13
14
  }
14
15
  const garden = navigator.garden;
15
16
  useEffect(() => {
16
- navigator.signalFirstRenderComplete();
17
+ Navigation.signalFirstRenderComplete(navigator.sceneId);
17
18
  return () => {
18
19
  navigator.unmount();
19
20
  };
@@ -18,13 +18,8 @@ export declare class Navigator implements Navigator {
18
18
  sceneId: string;
19
19
  moduleName?: string | undefined;
20
20
  static of(sceneId: string): Navigator;
21
- static current(): Promise<Navigator>;
22
- /**
23
- * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
24
- * @param moduleName
25
- * @returns
26
- */
27
21
  static find(moduleName: string): Promise<Navigator | undefined>;
22
+ static current(): Promise<Navigator>;
28
23
  /**
29
24
  * @deprecated Use Navigation.currentRoute() instead
30
25
  * @returns
@@ -90,6 +85,5 @@ export declare class Navigator implements Navigator {
90
85
  openMenu: () => Promise<boolean>;
91
86
  closeMenu: () => Promise<boolean>;
92
87
  isStackRoot: () => Promise<boolean>;
93
- signalFirstRenderComplete: () => void;
94
88
  }
95
89
  export {};
package/lib/Navigator.js CHANGED
@@ -25,21 +25,16 @@ export class Navigator {
25
25
  }
26
26
  return navigator;
27
27
  }
28
- static async current() {
29
- const route = await Navigation.currentRoute();
30
- return Navigator.of(route.sceneId);
31
- }
32
- /**
33
- * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
34
- * @param moduleName
35
- * @returns
36
- */
37
28
  static async find(moduleName) {
38
29
  const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
39
30
  if (sceneId) {
40
31
  return Navigator.of(sceneId);
41
32
  }
42
33
  }
34
+ static async current() {
35
+ const route = await Navigation.currentRoute();
36
+ return Navigator.of(route.sceneId);
37
+ }
43
38
  /**
44
39
  * @deprecated Use Navigation.currentRoute() instead
45
40
  * @returns
@@ -210,5 +205,4 @@ export class Navigator {
210
205
  openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
211
206
  closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
212
207
  isStackRoot = () => Navigation.isStackRoot(this.sceneId);
213
- signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId);
214
208
  }
@@ -1,9 +1,9 @@
1
1
  import { pathToRegexp, match } from 'path-to-regexp';
2
- import Navigation from '../Navigation';
3
2
  import { StackRouteHandler } from './stack';
4
3
  import { ScreenRouteHandler } from './screen';
5
4
  import { TabsRouteHandler } from './tabs';
6
5
  import { DrawerRouteHandler } from './drawer';
6
+ import Navigation from '../Navigation';
7
7
  function pathParams(path) {
8
8
  const pathMatch = match(path, {
9
9
  encode: encodeURI,
@@ -107,14 +107,14 @@ class Router {
107
107
  }
108
108
  return dependencies.reverse();
109
109
  }
110
- async processRoute(route, graph) {
110
+ async processRoute(graph, target) {
111
111
  const handler = this.handlers.get(graph.layout);
112
112
  if (!handler) {
113
113
  return false;
114
114
  }
115
- const [consumed, childGraph] = await handler.process(graph, route);
115
+ const [consumed, childGraph] = await handler.process(graph, target);
116
116
  if (consumed && childGraph) {
117
- return await this.processRoute(route, childGraph);
117
+ return await this.processRoute(childGraph, target);
118
118
  }
119
119
  return consumed;
120
120
  }
@@ -145,7 +145,7 @@ class Router {
145
145
  }
146
146
  }
147
147
  const routeGraph = graphArray[0];
148
- const consumed = await this.processRoute(route, routeGraph);
148
+ const consumed = await this.processRoute(routeGraph, route);
149
149
  if (consumed) {
150
150
  return;
151
151
  }
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.13.6",
4
+ "version": "2.13.7",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
@@ -2,6 +2,7 @@ import React, { useEffect } from 'react'
2
2
  import type { Garden } from './Garden'
3
3
  import type { NavigationItem } from './Options'
4
4
  import { Navigator, NavigationContext } from './Navigator'
5
+ import Navigation from './Navigation'
5
6
 
6
7
  export interface NavigationProps {
7
8
  navigator: Navigator
@@ -35,7 +36,7 @@ export function withNavigation(moduleName: string) {
35
36
  const garden = navigator.garden
36
37
 
37
38
  useEffect(() => {
38
- navigator.signalFirstRenderComplete()
39
+ Navigation.signalFirstRenderComplete(navigator.sceneId)
39
40
  return () => {
40
41
  navigator.unmount()
41
42
  }
package/src/Navigator.ts CHANGED
@@ -47,16 +47,6 @@ export class Navigator implements Navigator {
47
47
  return navigator
48
48
  }
49
49
 
50
- static async current(): Promise<Navigator> {
51
- const route = await Navigation.currentRoute()
52
- return Navigator.of(route.sceneId)
53
- }
54
-
55
- /**
56
- * @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
57
- * @param moduleName
58
- * @returns
59
- */
60
50
  static async find(moduleName: string) {
61
51
  const sceneId = await Navigation.findSceneIdByModuleName(moduleName)
62
52
  if (sceneId) {
@@ -64,6 +54,11 @@ export class Navigator implements Navigator {
64
54
  }
65
55
  }
66
56
 
57
+ static async current(): Promise<Navigator> {
58
+ const route = await Navigation.currentRoute()
59
+ return Navigator.of(route.sceneId)
60
+ }
61
+
67
62
  /**
68
63
  * @deprecated Use Navigation.currentRoute() instead
69
64
  * @returns
@@ -284,6 +279,4 @@ export class Navigator implements Navigator {
284
279
  closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName })
285
280
 
286
281
  isStackRoot = () => Navigation.isStackRoot(this.sceneId)
287
-
288
- signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId)
289
282
  }
@@ -8,12 +8,13 @@ import {
8
8
  RouteInterceptor,
9
9
  } from '../Route'
10
10
  import { NavigationItem } from '../Options'
11
- import Navigation from '../Navigation'
12
11
  import { StackRouteHandler } from './stack'
13
12
  import { ScreenRouteHandler } from './screen'
14
13
  import { TabsRouteHandler } from './tabs'
15
14
  import { DrawerRouteHandler } from './drawer'
16
15
 
16
+ import Navigation from '../Navigation'
17
+
17
18
  interface IndexType {
18
19
  [index: string]: any
19
20
  }
@@ -138,15 +139,15 @@ class Router {
138
139
  return dependencies.reverse()
139
140
  }
140
141
 
141
- private async processRoute(route: RouteInfo, graph: RouteGraph): Promise<boolean> {
142
+ private async processRoute(graph: RouteGraph, target: RouteInfo): Promise<boolean> {
142
143
  const handler = this.handlers.get(graph.layout)
143
144
  if (!handler) {
144
145
  return false
145
146
  }
146
147
 
147
- const [consumed, childGraph] = await handler.process(graph, route)
148
+ const [consumed, childGraph] = await handler.process(graph, target)
148
149
  if (consumed && childGraph) {
149
- return await this.processRoute(route, childGraph)
150
+ return await this.processRoute(childGraph, target)
150
151
  }
151
152
  return consumed
152
153
  }
@@ -181,7 +182,7 @@ class Router {
181
182
 
182
183
  const routeGraph = graphArray[0]
183
184
 
184
- const consumed = await this.processRoute(route, routeGraph)
185
+ const consumed = await this.processRoute(routeGraph, route)
185
186
  if (consumed) {
186
187
  return
187
188
  }