hybrid-navigation 4.0.0 → 4.0.1

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.
Files changed (47) hide show
  1. package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +36 -10
  2. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
  3. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +2 -1
  4. package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +54 -0
  5. package/package.json +1 -1
  6. /package/dist/{src/DeepLink.d.ts → DeepLink.d.ts} +0 -0
  7. /package/dist/{src/DeepLink.js → DeepLink.js} +0 -0
  8. /package/dist/{src/NativeEvent.d.ts → NativeEvent.d.ts} +0 -0
  9. /package/dist/{src/NativeEvent.js → NativeEvent.js} +0 -0
  10. /package/dist/{src/NativeGarden.d.ts → NativeGarden.d.ts} +0 -0
  11. /package/dist/{src/NativeGarden.js → NativeGarden.js} +0 -0
  12. /package/dist/{src/NativeNavigation.d.ts → NativeNavigation.d.ts} +0 -0
  13. /package/dist/{src/NativeNavigation.js → NativeNavigation.js} +0 -0
  14. /package/dist/{src/Navigation.d.ts → Navigation.d.ts} +0 -0
  15. /package/dist/{src/Navigation.js → Navigation.js} +0 -0
  16. /package/dist/{src/NavigationComponentWrap.d.ts → NavigationComponentWrap.d.ts} +0 -0
  17. /package/dist/{src/NavigationComponentWrap.js → NavigationComponentWrap.js} +0 -0
  18. /package/dist/{src/Navigator.d.ts → Navigator.d.ts} +0 -0
  19. /package/dist/{src/Navigator.js → Navigator.js} +0 -0
  20. /package/dist/{src/Options.d.ts → Options.d.ts} +0 -0
  21. /package/dist/{src/Options.js → Options.js} +0 -0
  22. /package/dist/{src/Route.d.ts → Route.d.ts} +0 -0
  23. /package/dist/{src/Route.js → Route.js} +0 -0
  24. /package/dist/{src/handler → handler}/DispatchCommandHandler.d.ts +0 -0
  25. /package/dist/{src/handler → handler}/DispatchCommandHandler.js +0 -0
  26. /package/dist/{src/handler → handler}/LayoutCommandHandler.d.ts +0 -0
  27. /package/dist/{src/handler → handler}/LayoutCommandHandler.js +0 -0
  28. /package/dist/{src/handler → handler}/ResultEventHandler.d.ts +0 -0
  29. /package/dist/{src/handler → handler}/ResultEventHandler.js +0 -0
  30. /package/dist/{src/handler → handler}/VisibilityEventHandler.d.ts +0 -0
  31. /package/dist/{src/handler → handler}/VisibilityEventHandler.js +0 -0
  32. /package/dist/{src/hooks.d.ts → hooks.d.ts} +0 -0
  33. /package/dist/{src/hooks.js → hooks.js} +0 -0
  34. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  35. /package/dist/{src/index.js → index.js} +0 -0
  36. /package/dist/{src/router → router}/drawer.d.ts +0 -0
  37. /package/dist/{src/router → router}/drawer.js +0 -0
  38. /package/dist/{src/router → router}/index.d.ts +0 -0
  39. /package/dist/{src/router → router}/index.js +0 -0
  40. /package/dist/{src/router → router}/screen.d.ts +0 -0
  41. /package/dist/{src/router → router}/screen.js +0 -0
  42. /package/dist/{src/router → router}/stack.d.ts +0 -0
  43. /package/dist/{src/router → router}/stack.js +0 -0
  44. /package/dist/{src/router → router}/tabs.d.ts +0 -0
  45. /package/dist/{src/router → router}/tabs.js +0 -0
  46. /package/dist/{src/store.d.ts → store.d.ts} +0 -0
  47. /package/dist/{src/store.js → store.js} +0 -0
@@ -12,6 +12,7 @@ import android.widget.FrameLayout;
12
12
  import androidx.annotation.NonNull;
13
13
  import androidx.annotation.Nullable;
14
14
 
15
+ import com.facebook.react.interfaces.TaskInterface;
15
16
  import com.facebook.react.interfaces.fabric.ReactSurface;
16
17
  import com.facebook.react.runtime.ReactSurfaceView;
17
18
 
@@ -27,6 +28,9 @@ public class HBDRootView extends FrameLayout {
27
28
  @Nullable
28
29
  private ReactSurfaceView reactSurfaceView;
29
30
 
31
+ @Nullable
32
+ private TaskInterface<Void> startTask;
33
+
30
34
  @Nullable
31
35
  private Bundle appProperties;
32
36
 
@@ -75,7 +79,7 @@ public class HBDRootView extends FrameLayout {
75
79
  applyAppProperties(appProperties);
76
80
  }
77
81
 
78
- reactSurface.start();
82
+ startTask = reactSurface.start();
79
83
  }
80
84
 
81
85
  public void clearSurface() {
@@ -83,18 +87,30 @@ public class HBDRootView extends FrameLayout {
83
87
  }
84
88
 
85
89
  public void clearSurface(boolean stopSurface) {
86
- if (surface != null && stopSurface) {
87
- try {
88
- surface.stop();
89
- } catch (RuntimeException ignored) {
90
- }
91
- }
92
- if (reactSurfaceView != null) {
93
- reactSurfaceView.setOnTouchListener(null);
90
+ ReactSurface oldSurface = surface;
91
+ ReactSurfaceView oldReactSurfaceView = reactSurfaceView;
92
+ TaskInterface<Void> oldStartTask = startTask;
93
+ View oldSurfaceRootView = oldReactSurfaceView;
94
+
95
+ if (oldSurfaceRootView == null && oldSurface != null) {
96
+ oldSurfaceRootView = oldSurface.getView();
94
97
  }
98
+
95
99
  surface = null;
96
100
  reactSurfaceView = null;
97
- removeAllViews();
101
+ startTask = null;
102
+
103
+ if (oldReactSurfaceView != null) {
104
+ oldReactSurfaceView.setOnTouchListener(null);
105
+ }
106
+
107
+ View surfaceRootView = oldSurfaceRootView;
108
+ if (oldSurface != null && stopSurface) {
109
+ ReactSurfaceCleanup.stopThenRun(oldSurface, oldStartTask, () -> removeSurfaceRootView(surfaceRootView));
110
+ return;
111
+ }
112
+
113
+ removeSurfaceRootView(surfaceRootView);
98
114
  }
99
115
 
100
116
  public void setAppProperties(@Nullable Bundle appProperties) {
@@ -133,4 +149,14 @@ public class HBDRootView extends FrameLayout {
133
149
  InvocationTargetException ignored) {
134
150
  }
135
151
  }
152
+
153
+ private void removeSurfaceRootView(@Nullable View oldSurfaceRootView) {
154
+ if (oldSurfaceRootView == null) {
155
+ return;
156
+ }
157
+
158
+ if (oldSurfaceRootView.getParent() == this) {
159
+ removeView(oldSurfaceRootView);
160
+ }
161
+ }
136
162
  }
@@ -133,7 +133,7 @@ public class ReactAppCompatActivityDelegate {
133
133
  }
134
134
 
135
135
  public void onConfigurationChanged(Configuration newConfig) {
136
- DisplayMetricsHolder.initDisplayMetrics(getPlainActivity());
136
+ DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(getPlainActivity());
137
137
  ReactHost reactHost = mReactManager.getReactHost();
138
138
  reactHost.onConfigurationChanged(getPlainActivity());
139
139
  }
@@ -16,6 +16,7 @@ import com.facebook.react.bridge.Arguments;
16
16
  import com.facebook.react.bridge.ReactContext;
17
17
  import com.facebook.react.common.LifecycleState;
18
18
  import com.facebook.react.interfaces.fabric.ReactSurface;
19
+ import com.navigation.androidx.FragmentHelper;
19
20
 
20
21
  public class ReactFragment extends HybridFragment implements ReactManager.ReactBridgeReloadListener {
21
22
 
@@ -47,7 +48,7 @@ public class ReactFragment extends HybridFragment implements ReactManager.ReactB
47
48
  @Override
48
49
  public void onStop() {
49
50
  super.onStop();
50
- if (isRemoving() && forceScreenLandscape()) {
51
+ if (FragmentHelper.isRemoving(this) && forceScreenLandscape()) {
51
52
  unmountReactView();
52
53
  }
53
54
  }
@@ -0,0 +1,54 @@
1
+ package com.reactnative.hybridnavigation;
2
+
3
+ import android.os.Handler;
4
+ import android.os.Looper;
5
+
6
+ import androidx.annotation.NonNull;
7
+ import androidx.annotation.Nullable;
8
+
9
+ import com.facebook.react.interfaces.TaskInterface;
10
+ import com.facebook.react.interfaces.fabric.ReactSurface;
11
+
12
+ import java.util.concurrent.ExecutorService;
13
+ import java.util.concurrent.Executors;
14
+
15
+ final class ReactSurfaceCleanup {
16
+
17
+ private static final Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
18
+ private static final ExecutorService EXECUTOR = Executors.newSingleThreadExecutor(runnable -> {
19
+ Thread thread = new Thread(runnable, "ReactSurfaceCleanup");
20
+ thread.setDaemon(true);
21
+ return thread;
22
+ });
23
+
24
+ private ReactSurfaceCleanup() {
25
+ }
26
+
27
+ static void stopThenRun(
28
+ @NonNull ReactSurface surface,
29
+ @Nullable TaskInterface<Void> startTask,
30
+ @NonNull Runnable completion
31
+ ) {
32
+ EXECUTOR.execute(() -> {
33
+ // RN 0.84/0.85 can ignore stopSurface if it runs before startSurface marks the surface running.
34
+ waitForTask(startTask);
35
+ try {
36
+ waitForTask(surface.stop());
37
+ } catch (RuntimeException ignored) {
38
+ }
39
+ MAIN_HANDLER.post(completion);
40
+ });
41
+ }
42
+
43
+ private static void waitForTask(@Nullable TaskInterface<Void> task) {
44
+ if (task == null) {
45
+ return;
46
+ }
47
+
48
+ try {
49
+ task.waitForCompletion();
50
+ } catch (InterruptedException ignored) {
51
+ Thread.currentThread().interrupt();
52
+ }
53
+ }
54
+ }
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": "4.0.0",
4
+ "version": "4.0.1",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes