hybrid-navigation 2.9.0 → 2.10.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.
Files changed (72) 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/HybridFragment.java +94 -43
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +134 -117
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +65 -35
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +14 -3
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +133 -92
  12. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +161 -126
  13. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +145 -114
  14. package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +40 -28
  15. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +96 -75
  16. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/Navigator.java +1 -1
  17. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +111 -79
  18. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +187 -117
  19. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +137 -96
  20. package/ios/HybridNavigation/ViewController/HBDModalViewController.m +7 -0
  21. package/lib/Navigator.js +0 -1
  22. package/lib/ReactRegistry.d.ts +3 -3
  23. package/lib/typing.d.ts +1 -2
  24. package/package.json +24 -16
  25. package/src/DeepLink.ts +60 -0
  26. package/src/Garden.ts +171 -0
  27. package/src/NavigationModule.ts +33 -0
  28. package/src/Navigator.ts +403 -0
  29. package/src/ReactRegistry.tsx +138 -0
  30. package/src/hooks.ts +83 -0
  31. package/src/index.ts +9 -0
  32. package/src/router/drawer.ts +34 -0
  33. package/src/router/index.ts +166 -0
  34. package/src/router/screen.ts +12 -0
  35. package/src/router/stack.ts +80 -0
  36. package/src/router/tabs.ts +49 -0
  37. package/src/router/typing.ts +45 -0
  38. package/src/store.ts +49 -0
  39. package/src/typing.ts +148 -0
  40. package/src/utils.ts +83 -0
  41. package/.buckconfig +0 -6
  42. package/.editorconfig +0 -16
  43. package/.eslintignore +0 -5
  44. package/.gitattributes +0 -1
  45. package/.github/workflows/docs.yml +0 -25
  46. package/CHANGELOG.md +0 -429
  47. package/babel.config.js +0 -15
  48. package/docs/README.md +0 -109
  49. package/docs/custom-tabbar.md +0 -138
  50. package/docs/deeplink.md +0 -148
  51. package/docs/integration-native.md +0 -390
  52. package/docs/integration-react.md +0 -194
  53. package/docs/lifecycle.md +0 -85
  54. package/docs/navigation.md +0 -589
  55. package/docs/pass-and-return-value.md +0 -163
  56. package/docs/qa.md +0 -81
  57. package/docs/style.md +0 -533
  58. package/jest.config.js +0 -4
  59. package/metro.config.js +0 -17
  60. package/screenshot/android.png +0 -0
  61. package/screenshot/bulge.jpg +0 -0
  62. package/screenshot/controller-base.jpg +0 -0
  63. package/screenshot/demo-qrcode.png +0 -0
  64. package/screenshot/header-search-paths.jpg +0 -0
  65. package/screenshot/ios-react-script.png +0 -0
  66. package/screenshot/ios-run-script.jpg +0 -0
  67. package/screenshot/statusbar-inperfect.png +0 -0
  68. package/screenshot/statusbar-setup-step-1.png +0 -0
  69. package/screenshot/statusbar-setup-step-2.png +0 -0
  70. package/screenshot/tabbar.jpg +0 -0
  71. package/screenshot/topbar-default.png +0 -0
  72. 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,88 +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
- Toolbar toolbar = getToolbar();
262
- if (toolbar != null) {
263
- toolbar.addView(reactTitleView, layoutParams);
264
- reactTitleView.startReactApplication(getReactInstanceManager(), moduleName, getProps());
265
- }
266
- }
287
+ if (titleItem == null) {
288
+ return;
267
289
  }
268
- }
269
290
 
270
- private boolean shouldCreateReactView(@Nullable Context context, @Nullable ReactRootView reactRootView) {
271
- 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());
272
300
  }
273
301
 
274
- boolean shouldPassThroughTouches() {
275
- 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;
276
308
  }
277
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
+
278
318
  @Override
279
319
  public void postponeEnterTransition() {
280
320
  super.postponeEnterTransition();
281
- if (getActivity() != null) {
282
- getActivity().supportPostponeEnterTransition();
321
+ if (getActivity() == null) {
322
+ return;
283
323
  }
324
+ getActivity().supportPostponeEnterTransition();
284
325
  }
285
326
 
286
327
  @Override
287
328
  public void startPostponedEnterTransition() {
288
329
  super.startPostponedEnterTransition();
289
- if (getActivity() != null) {
290
- getActivity().supportStartPostponedEnterTransition();
330
+ if (getActivity() == null) {
331
+ return;
291
332
  }
333
+ getActivity().supportStartPostponedEnterTransition();
292
334
  }
293
335
 
294
336
  @Override
295
337
  protected int preferredNavigationBarColor() {
296
- if (mStyle.getNavigationBarColor() != Style.INVALID_COLOR) {
297
- return mStyle.getNavigationBarColor();
298
- } else {
338
+ if (mStyle.getNavigationBarColor() == Style.INVALID_COLOR) {
299
339
  return mStyle.getScreenBackgroundColor();
300
340
  }
341
+ return mStyle.getNavigationBarColor();
301
342
  }
302
343
  }