hybrid-navigation 2.8.3 → 2.10.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 (79) hide show
  1. package/HybridNavigation.podspec +6 -6
  2. package/LICENSE +1 -1
  3. package/android/build.gradle +4 -4
  4. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +27 -40
  5. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +77 -48
  6. package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +4 -4
  7. package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -8
  8. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +94 -43
  9. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +134 -117
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +65 -35
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +14 -3
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +133 -89
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +161 -126
  14. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +145 -114
  15. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +40 -28
  16. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +96 -75
  17. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/Navigator.java +1 -1
  18. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +111 -79
  19. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +187 -117
  20. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +137 -96
  21. package/ios/HybridNavigation/ViewController/HBDModalViewController.m +7 -0
  22. package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +16 -0
  23. package/ios/HybridNavigation.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  24. package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  25. package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcuserdata/listen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  26. package/ios/HybridNavigation.xcodeproj/xcuserdata/listen.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  27. package/lib/Navigator.d.ts +6 -6
  28. package/lib/ReactRegistry.d.ts +3 -3
  29. package/lib/ReactRegistry.js +14 -10
  30. package/lib/typing.d.ts +8 -8
  31. package/package.json +27 -16
  32. package/src/DeepLink.ts +60 -0
  33. package/src/Garden.ts +171 -0
  34. package/src/NavigationModule.ts +33 -0
  35. package/src/Navigator.ts +404 -0
  36. package/src/ReactRegistry.tsx +138 -0
  37. package/src/hooks.ts +83 -0
  38. package/src/index.ts +9 -0
  39. package/src/router/drawer.ts +34 -0
  40. package/src/router/index.ts +166 -0
  41. package/src/router/screen.ts +12 -0
  42. package/src/router/stack.ts +80 -0
  43. package/src/router/tabs.ts +49 -0
  44. package/src/router/typing.ts +45 -0
  45. package/src/store.ts +49 -0
  46. package/src/typing.ts +148 -0
  47. package/src/utils.ts +83 -0
  48. package/.buckconfig +0 -6
  49. package/.editorconfig +0 -16
  50. package/.eslintignore +0 -5
  51. package/.gitattributes +0 -1
  52. package/.github/workflows/docs.yml +0 -25
  53. package/CHANGELOG.md +0 -399
  54. package/babel.config.js +0 -15
  55. package/docs/README.md +0 -109
  56. package/docs/custom-tabbar.md +0 -138
  57. package/docs/deeplink.md +0 -148
  58. package/docs/integration-native.md +0 -390
  59. package/docs/integration-react.md +0 -194
  60. package/docs/lifecycle.md +0 -85
  61. package/docs/navigation.md +0 -589
  62. package/docs/pass-and-return-value.md +0 -163
  63. package/docs/qa.md +0 -57
  64. package/docs/style.md +0 -533
  65. package/jest.config.js +0 -4
  66. package/metro.config.js +0 -17
  67. package/screenshot/android.png +0 -0
  68. package/screenshot/bulge.jpg +0 -0
  69. package/screenshot/controller-base.jpg +0 -0
  70. package/screenshot/demo-qrcode.png +0 -0
  71. package/screenshot/header-search-paths.jpg +0 -0
  72. package/screenshot/ios-react-script.png +0 -0
  73. package/screenshot/ios-run-script.jpg +0 -0
  74. package/screenshot/statusbar-inperfect.png +0 -0
  75. package/screenshot/statusbar-setup-step-1.png +0 -0
  76. package/screenshot/statusbar-setup-step-2.png +0 -0
  77. package/screenshot/tabbar.jpg +0 -0
  78. package/screenshot/topbar-default.png +0 -0
  79. package/screenshot/xcode-linking.png +0 -0
@@ -1,6 +1,17 @@
1
1
  package com.reactnative.hybridnavigation;
2
2
 
3
- import android.content.Context;
3
+ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
4
+ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
5
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
6
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
7
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
8
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
9
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
10
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
11
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_APPEAR;
12
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
13
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
14
+
4
15
  import android.graphics.Color;
5
16
  import android.os.Bundle;
6
17
  import android.view.Gravity;
@@ -12,7 +23,6 @@ import androidx.annotation.NonNull;
12
23
  import androidx.annotation.Nullable;
13
24
  import androidx.appcompat.widget.Toolbar;
14
25
 
15
- import com.facebook.react.ReactRootView;
16
26
  import com.facebook.react.bridge.Arguments;
17
27
  import com.facebook.react.bridge.ReactContext;
18
28
  import com.facebook.react.common.LifecycleState;
@@ -20,17 +30,6 @@ import com.navigation.androidx.FragmentHelper;
20
30
  import com.navigation.androidx.Style;
21
31
  import com.navigation.androidx.TransitionAnimation;
22
32
 
23
- import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
24
- import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
25
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
26
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
27
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
28
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
29
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
30
- import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_APPEAR;
31
- import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_DISAPPEAR;
32
- import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
33
-
34
33
  /**
35
34
  * Created by Listen on 2018/1/15.
36
35
  */
@@ -58,7 +57,7 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
58
57
  if (getAnimation() != TransitionAnimation.None) {
59
58
  postponeEnterTransition();
60
59
  }
61
- initReactNative();
60
+ initReactRootView();
62
61
  }
63
62
 
64
63
  return view;
@@ -70,24 +69,27 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
70
69
  float alpha = mStyle.getToolbarAlpha();
71
70
  Garden garden = getGarden();
72
71
  return Color.alpha(color) < 255
73
- || alpha < 1.0
74
- || garden.toolbarHidden
75
- || garden.extendedLayoutIncludesTopBar;
72
+ || alpha < 1.0
73
+ || garden.toolbarHidden
74
+ || garden.extendedLayoutIncludesTopBar;
76
75
  }
77
76
 
78
77
  @Override
79
78
  protected void onCustomStyle(@NonNull Style style) {
79
+ super.onCustomStyle(style);
80
80
  if (shouldPassThroughTouches()) {
81
81
  style.setScrimAlpha(0);
82
82
  }
83
- super.onCustomStyle(style);
84
83
  }
85
84
 
86
85
  @Override
87
86
  public void inspectVisibility(int visibility) {
88
- if (visibility == View.VISIBLE && reactRootView == null) {
89
- initReactNative();
90
- initTitleViewIfNeeded();
87
+ if (visibility != View.VISIBLE) {
88
+ return;
89
+ }
90
+ if (reactRootView == null) {
91
+ initReactRootView();
92
+ initReactTitleView();
91
93
  }
92
94
  }
93
95
 
@@ -95,11 +97,11 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
95
97
  public void onResume() {
96
98
  super.onResume();
97
99
  if (reactRootView == null) {
98
- initReactNative();
99
- initTitleViewIfNeeded();
100
+ initReactRootView();
101
+ initReactTitleView();
100
102
  }
101
103
 
102
- if (reactRootView != null && firstRenderCompleted) {
104
+ if (isViewReady()) {
103
105
  reactRootView.addOnGlobalLayoutListener();
104
106
  sendViewAppearEvent(true);
105
107
  }
@@ -108,40 +110,53 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
108
110
  @Override
109
111
  public void onPause() {
110
112
  super.onPause();
111
- if (reactRootView != null && firstRenderCompleted) {
113
+ if (isViewReady()) {
112
114
  sendViewAppearEvent(false);
113
115
  reactRootView.removeOnGlobalLayoutListener();
114
116
  }
115
117
  }
116
118
 
119
+ private boolean isViewReady() {
120
+ if (reactRootView == null) {
121
+ return false;
122
+ }
123
+ return firstRenderCompleted;
124
+ }
125
+
117
126
  private boolean reactViewAppeared = false;
118
127
 
119
128
  private void sendViewAppearEvent(boolean appear) {
129
+ if (!isReactModuleRegisterCompleted()) {
130
+ return;
131
+ }
132
+
120
133
  // 当从前台进入后台时,不会触发 disappear, 这和 iOS 保持一致
121
134
  ReactContext reactContext = getCurrentReactContext();
122
135
  boolean isResumed = reactContext != null && reactContext.getLifecycleState() == LifecycleState.RESUMED;
123
- if (isResumed && isReactModuleRegisterCompleted()) {
124
- if (reactViewAppeared == appear) {
125
- return;
126
- }
127
- reactViewAppeared = appear;
136
+ if (!isResumed) {
137
+ return;
138
+ }
128
139
 
129
- Bundle bundle = new Bundle();
130
- bundle.putString(KEY_SCENE_ID, getSceneId());
131
- bundle.putString(KEY_ON, appear ? ON_COMPONENT_APPEAR : ON_COMPONENT_DISAPPEAR);
132
- HBDEventEmitter.sendEvent(EVENT_NAVIGATION, Arguments.fromBundle(bundle));
140
+ if (reactViewAppeared == appear) {
141
+ return;
133
142
  }
143
+ reactViewAppeared = appear;
144
+
145
+ Bundle bundle = new Bundle();
146
+ bundle.putString(KEY_SCENE_ID, getSceneId());
147
+ bundle.putString(KEY_ON, appear ? ON_COMPONENT_APPEAR : ON_COMPONENT_DISAPPEAR);
148
+ HBDEventEmitter.sendEvent(EVENT_NAVIGATION, Arguments.fromBundle(bundle));
134
149
  }
135
150
 
136
151
  @Override
137
152
  public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
138
153
  super.onViewCreated(view, savedInstanceState);
139
154
  if (!FragmentHelper.isHidden(this)) {
140
- initTitleViewIfNeeded();
155
+ initReactTitleView();
141
156
  }
142
157
  getReactBridgeManager().addReactBridgeReloadListener(this);
143
158
  }
144
-
159
+
145
160
  @Override
146
161
  public void onDestroyView() {
147
162
  super.onDestroyView();
@@ -150,7 +165,7 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
150
165
  }
151
166
  unmountReactView();
152
167
  }
153
-
168
+
154
169
  @Override
155
170
  public void onReload() {
156
171
  unmountReactView();
@@ -160,16 +175,18 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
160
175
  getReactBridgeManager().removeReactBridgeReloadListener(this);
161
176
 
162
177
  ReactContext reactContext = getCurrentReactContext();
163
- if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
164
- if (reactRootView != null) {
165
- reactRootView.unmountReactApplication();
166
- reactRootView = null;
167
- }
178
+ if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
179
+ return;
180
+ }
168
181
 
169
- if (reactTitleView != null) {
170
- reactTitleView.unmountReactApplication();
171
- reactTitleView = null;
172
- }
182
+ if (reactRootView != null) {
183
+ reactRootView.unmountReactApplication();
184
+ reactRootView = null;
185
+ }
186
+
187
+ if (reactTitleView != null) {
188
+ reactTitleView.unmountReactApplication();
189
+ reactTitleView = null;
173
190
  }
174
191
  }
175
192
 
@@ -186,11 +203,10 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
186
203
  if (firstRenderCompleted) {
187
204
  return;
188
205
  }
189
-
190
206
  firstRenderCompleted = true;
191
207
  startPostponedEnterTransition();
192
208
 
193
- if (reactRootView != null && isResumed()) {
209
+ if (isViewReady() && isResumed()) {
194
210
  sendViewAppearEvent(true);
195
211
  reactRootView.addOnGlobalLayoutListener();
196
212
  }
@@ -215,85 +231,113 @@ public class ReactFragment extends HybridFragment implements ReactRootViewHolder
215
231
  @Override
216
232
  public void setAppProperties(@NonNull Bundle props) {
217
233
  super.setAppProperties(props);
218
- if (reactRootView != null && isReactModuleRegisterCompleted()) {
234
+ if (reactRootView == null) {
235
+ return;
236
+ }
237
+
238
+ if (isReactModuleRegisterCompleted()) {
219
239
  this.reactRootView.setAppProperties(getProps());
220
240
  }
221
241
  }
222
242
 
223
- private void initReactNative() {
224
- Context context = getContext();
225
-
226
- if (!shouldCreateReactView(context, reactRootView)) {
243
+ private void initReactRootView() {
244
+ if (reactRootView != null) {
227
245
  return;
228
246
  }
247
+
248
+ if (getContext() == null) {
249
+ return;
250
+ }
251
+
252
+ if (!isReactModuleRegisterCompleted()) {
253
+ return;
254
+ }
255
+
256
+ reactRootView = createReactRootView();
257
+ reactRootView.startReactApplication(getReactInstanceManager(), getModuleName(), getProps());
258
+ }
229
259
 
230
- final HBDReactRootView reactRootView = new HBDReactRootView(context);
260
+ @NonNull
261
+ private HBDReactRootView createReactRootView() {
262
+ HBDReactRootView reactRootView = new HBDReactRootView(getContext());
231
263
  reactRootView.setShouldConsumeTouchEvent(!shouldPassThroughTouches());
232
- this.reactRootView = reactRootView;
233
-
234
264
  ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT);
235
265
  containerLayout.addView(reactRootView, layoutParams);
236
- String moduleName = getModuleName();
237
-
238
- reactRootView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
266
+ return reactRootView;
239
267
  }
240
268
 
241
- private void initTitleViewIfNeeded() {
242
- Context context = getContext();
269
+ private void initReactTitleView() {
270
+ if (reactTitleView != null) {
271
+ return;
272
+ }
273
+
274
+ if (getContext() == null) {
275
+ return;
276
+ }
243
277
 
244
- if (!shouldCreateReactView(context, reactTitleView)) {
278
+ if (!isReactModuleRegisterCompleted()) {
279
+ return;
280
+ }
281
+
282
+ if (getToolbar() == null) {
245
283
  return;
246
284
  }
247
285
 
248
286
  Bundle titleItem = getOptions().getBundle("titleItem");
249
- if (titleItem != null) {
250
- String moduleName = titleItem.getString("moduleName");
251
- if (moduleName != null) {
252
- String fitting = titleItem.getString("layoutFitting");
253
- boolean expanded = "expanded".equals(fitting);
254
- reactTitleView = new HBDReactRootView(context);
255
- Toolbar.LayoutParams layoutParams;
256
- if (expanded) {
257
- layoutParams = new Toolbar.LayoutParams(-1, -1, Gravity.CENTER);
258
- } else {
259
- layoutParams = new Toolbar.LayoutParams(-2, -2, Gravity.CENTER);
260
- }
261
- getToolbar().addView(reactTitleView, layoutParams);
262
- reactTitleView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
263
- }
287
+ if (titleItem == null) {
288
+ return;
264
289
  }
265
- }
266
290
 
267
- private boolean shouldCreateReactView(@Nullable Context context, @Nullable ReactRootView reactRootView) {
268
- return (context != null && reactRootView == null && isReactModuleRegisterCompleted());
291
+ String moduleName = titleItem.getString("moduleName");
292
+ if (moduleName == null) {
293
+ return;
294
+ }
295
+
296
+ String fitting = titleItem.getString("layoutFitting");
297
+ boolean expanded = "expanded".equals(fitting);
298
+ reactTitleView = createReactTitleView(expanded);
299
+ reactTitleView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
269
300
  }
270
301
 
271
- boolean shouldPassThroughTouches() {
272
- return getOptions().getBoolean("passThroughTouches", false);
302
+ private HBDReactRootView createReactTitleView( boolean expanded) {
303
+ Toolbar.LayoutParams layoutParams = createTitleLayoutParams(expanded);
304
+ HBDReactRootView reactTitleView = new HBDReactRootView(getContext());
305
+ Toolbar toolbar = getToolbar();
306
+ toolbar.addView(reactTitleView, layoutParams);
307
+ return reactTitleView;
273
308
  }
274
309
 
310
+ @NonNull
311
+ private Toolbar.LayoutParams createTitleLayoutParams(boolean expanded) {
312
+ if (expanded) {
313
+ return new Toolbar.LayoutParams(MATCH_PARENT, MATCH_PARENT, Gravity.CENTER);
314
+ }
315
+ return new Toolbar.LayoutParams(WRAP_CONTENT, WRAP_CONTENT, Gravity.CENTER);
316
+ }
317
+
275
318
  @Override
276
319
  public void postponeEnterTransition() {
277
320
  super.postponeEnterTransition();
278
- if (getActivity() != null) {
279
- getActivity().supportPostponeEnterTransition();
321
+ if (getActivity() == null) {
322
+ return;
280
323
  }
324
+ getActivity().supportPostponeEnterTransition();
281
325
  }
282
326
 
283
327
  @Override
284
328
  public void startPostponedEnterTransition() {
285
329
  super.startPostponedEnterTransition();
286
- if (getActivity() != null) {
287
- getActivity().supportStartPostponedEnterTransition();
330
+ if (getActivity() == null) {
331
+ return;
288
332
  }
333
+ getActivity().supportStartPostponedEnterTransition();
289
334
  }
290
335
 
291
336
  @Override
292
337
  protected int preferredNavigationBarColor() {
293
- if (mStyle.getNavigationBarColor() != Style.INVALID_COLOR) {
294
- return mStyle.getNavigationBarColor();
295
- } else {
338
+ if (mStyle.getNavigationBarColor() == Style.INVALID_COLOR) {
296
339
  return mStyle.getScreenBackgroundColor();
297
340
  }
341
+ return mStyle.getNavigationBarColor();
298
342
  }
299
343
  }