hybrid-navigation 2.4.2 → 2.6.0

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 (131) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -2
  4. package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +13 -2
  5. package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +12 -29
  6. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -3
  7. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +47 -49
  8. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +35 -55
  9. package/docs/README.md +3 -3
  10. package/docs/custom-tabbar.md +1 -1
  11. package/docs/deeplink.md +1 -1
  12. package/docs/integration-native.md +2 -2
  13. package/docs/integration-react.md +1 -1
  14. package/docs/qa.md +17 -0
  15. package/docs/style.md +52 -67
  16. package/ios/HybridNavigation/Bridge/HBDGardenModule.m +3 -13
  17. package/ios/HybridNavigation/HBDUtils.m +0 -8
  18. package/ios/HybridNavigation/View/HBDNavigationBar.h +1 -0
  19. package/ios/HybridNavigation/View/HBDNavigationBar.m +4 -0
  20. package/ios/HybridNavigation/ViewController/HBDNavigationController.m +27 -14
  21. package/ios/HybridNavigation/ViewController/HBDTabBarController.h +1 -3
  22. package/ios/HybridNavigation/ViewController/HBDTabBarController.m +34 -33
  23. package/ios/HybridNavigation/ViewController/HBDViewController.m +5 -0
  24. package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +49 -18
  25. package/lib/Garden.d.ts +14 -0
  26. package/lib/Garden.js +33 -2
  27. package/lib/typing.d.ts +1 -0
  28. package/package.json +7 -7
  29. package/docs/.vuepress/.cache/default-development/0.pack +0 -0
  30. package/docs/.vuepress/.cache/default-development/1.pack +0 -0
  31. package/docs/.vuepress/.cache/default-development/10.pack +0 -0
  32. package/docs/.vuepress/.cache/default-development/11.pack +0 -0
  33. package/docs/.vuepress/.cache/default-development/12.pack +0 -0
  34. package/docs/.vuepress/.cache/default-development/13.pack +0 -0
  35. package/docs/.vuepress/.cache/default-development/14.pack +0 -0
  36. package/docs/.vuepress/.cache/default-development/15.pack +0 -0
  37. package/docs/.vuepress/.cache/default-development/16.pack +0 -0
  38. package/docs/.vuepress/.cache/default-development/17.pack +0 -0
  39. package/docs/.vuepress/.cache/default-development/18.pack +0 -0
  40. package/docs/.vuepress/.cache/default-development/19.pack +0 -0
  41. package/docs/.vuepress/.cache/default-development/2.pack +0 -0
  42. package/docs/.vuepress/.cache/default-development/20.pack +0 -0
  43. package/docs/.vuepress/.cache/default-development/21.pack +0 -0
  44. package/docs/.vuepress/.cache/default-development/3.pack +0 -0
  45. package/docs/.vuepress/.cache/default-development/4.pack +0 -0
  46. package/docs/.vuepress/.cache/default-development/5.pack +0 -0
  47. package/docs/.vuepress/.cache/default-development/6.pack +0 -0
  48. package/docs/.vuepress/.cache/default-development/7.pack +0 -0
  49. package/docs/.vuepress/.cache/default-development/8.pack +0 -0
  50. package/docs/.vuepress/.cache/default-development/9.pack +0 -0
  51. package/docs/.vuepress/.cache/default-development/index.pack +0 -0
  52. package/docs/.vuepress/.cache/default-development/index.pack.old +0 -0
  53. package/docs/.vuepress/.cache/default-production/0.pack +0 -0
  54. package/docs/.vuepress/.cache/default-production/1.pack +0 -0
  55. package/docs/.vuepress/.cache/default-production/2.pack +0 -0
  56. package/docs/.vuepress/.cache/default-production/index.pack +0 -0
  57. package/docs/.vuepress/.cache/default-production/index.pack.old +0 -0
  58. package/docs/.vuepress/.temp/internal/clientAppEnhances.js +0 -9
  59. package/docs/.vuepress/.temp/internal/clientAppRootComponents.js +0 -5
  60. package/docs/.vuepress/.temp/internal/clientAppSetups.js +0 -9
  61. package/docs/.vuepress/.temp/internal/layoutComponents.js +0 -6
  62. package/docs/.vuepress/.temp/internal/pagesComponents.js +0 -26
  63. package/docs/.vuepress/.temp/internal/pagesData.js +0 -24
  64. package/docs/.vuepress/.temp/internal/pagesRoutes.js +0 -40
  65. package/docs/.vuepress/.temp/internal/siteData.js +0 -8
  66. package/docs/.vuepress/.temp/internal/themeData.js +0 -75
  67. package/docs/.vuepress/.temp/pages/404.html.js +0 -13
  68. package/docs/.vuepress/.temp/pages/404.html.vue +0 -1
  69. package/docs/.vuepress/.temp/pages/custom-tabbar.html.js +0 -32
  70. package/docs/.vuepress/.temp/pages/custom-tabbar.html.vue +0 -107
  71. package/docs/.vuepress/.temp/pages/deeplink.html.js +0 -50
  72. package/docs/.vuepress/.temp/pages/deeplink.html.vue +0 -93
  73. package/docs/.vuepress/.temp/pages/index.html.js +0 -51
  74. package/docs/.vuepress/.temp/pages/index.html.vue +0 -95
  75. package/docs/.vuepress/.temp/pages/integration-native.html.js +0 -38
  76. package/docs/.vuepress/.temp/pages/integration-native.html.vue +0 -292
  77. package/docs/.vuepress/.temp/pages/integration-react.html.js +0 -57
  78. package/docs/.vuepress/.temp/pages/integration-react.html.vue +0 -133
  79. package/docs/.vuepress/.temp/pages/lifecycle.html.js +0 -26
  80. package/docs/.vuepress/.temp/pages/lifecycle.html.vue +0 -69
  81. package/docs/.vuepress/.temp/pages/navigation.html.js +0 -50
  82. package/docs/.vuepress/.temp/pages/navigation.html.vue +0 -406
  83. package/docs/.vuepress/.temp/pages/pass-and-return-value.html.js +0 -51
  84. package/docs/.vuepress/.temp/pages/pass-and-return-value.html.vue +0 -94
  85. package/docs/.vuepress/.temp/pages/qa.html.js +0 -26
  86. package/docs/.vuepress/.temp/pages/qa.html.vue +0 -27
  87. package/docs/.vuepress/.temp/pages/style.html.js +0 -45
  88. package/docs/.vuepress/.temp/pages/style.html.vue +0 -452
  89. package/docs/.vuepress/.temp/styles/index.scss +0 -0
  90. package/docs/.vuepress/.temp/styles/palette.scss +0 -0
  91. package/docs/.vuepress/config.js +0 -51
  92. package/docs/.vuepress/dist/404.html +0 -15
  93. package/docs/.vuepress/dist/assets/css/styles.701e6109.css +0 -8
  94. package/docs/.vuepress/dist/assets/img/android.e350dcdd.png +0 -0
  95. package/docs/.vuepress/dist/assets/img/back-to-top.8b37f773.svg +0 -1
  96. package/docs/.vuepress/dist/assets/img/controller-base.96c0200f.jpg +0 -0
  97. package/docs/.vuepress/dist/assets/img/ios-react-script.6692a449.png +0 -0
  98. package/docs/.vuepress/dist/assets/img/ios-run-script.67339d42.jpg +0 -0
  99. package/docs/.vuepress/dist/assets/img/statusbar-inperfect.f32cfca0.png +0 -0
  100. package/docs/.vuepress/dist/assets/img/statusbar-setup-step-1.2669257d.png +0 -0
  101. package/docs/.vuepress/dist/assets/img/statusbar-setup-step-2.b18151ed.png +0 -0
  102. package/docs/.vuepress/dist/assets/img/tabbar.73212e13.jpg +0 -0
  103. package/docs/.vuepress/dist/assets/img/topbar-default.65d36143.png +0 -0
  104. package/docs/.vuepress/dist/assets/img/xcode-linking.685ce6ea.png +0 -0
  105. package/docs/.vuepress/dist/assets/js/293.071a173a.js +0 -1
  106. package/docs/.vuepress/dist/assets/js/491.4e0b3b61.js +0 -1
  107. package/docs/.vuepress/dist/assets/js/812.0c9a2f53.js +0 -2
  108. package/docs/.vuepress/dist/assets/js/812.0c9a2f53.js.LICENSE.txt +0 -8
  109. package/docs/.vuepress/dist/assets/js/app.a66f731a.js +0 -1
  110. package/docs/.vuepress/dist/assets/js/runtime~app.19128f21.js +0 -1
  111. package/docs/.vuepress/dist/assets/js/v-123dff2c.47243fa1.js +0 -1
  112. package/docs/.vuepress/dist/assets/js/v-3706649a.6536ff4d.js +0 -1
  113. package/docs/.vuepress/dist/assets/js/v-384da568.667de1bc.js +0 -1
  114. package/docs/.vuepress/dist/assets/js/v-44439230.8b89f9cb.js +0 -1
  115. package/docs/.vuepress/dist/assets/js/v-548f4cfe.61f40391.js +0 -1
  116. package/docs/.vuepress/dist/assets/js/v-6be4efb0.ec3640c3.js +0 -1
  117. package/docs/.vuepress/dist/assets/js/v-77faca8c.ee876cd7.js +0 -1
  118. package/docs/.vuepress/dist/assets/js/v-7900994c.059cfff8.js +0 -1
  119. package/docs/.vuepress/dist/assets/js/v-7d5b94d0.b90251d7.js +0 -1
  120. package/docs/.vuepress/dist/assets/js/v-8daa1a0e.eced6c93.js +0 -1
  121. package/docs/.vuepress/dist/assets/js/v-d11cd4e0.ca9b65ee.js +0 -1
  122. package/docs/.vuepress/dist/custom-tabbar.html +0 -105
  123. package/docs/.vuepress/dist/deeplink.html +0 -69
  124. package/docs/.vuepress/dist/index.html +0 -44
  125. package/docs/.vuepress/dist/integration-native.html +0 -258
  126. package/docs/.vuepress/dist/integration-react.html +0 -109
  127. package/docs/.vuepress/dist/lifecycle.html +0 -74
  128. package/docs/.vuepress/dist/navigation.html +0 -208
  129. package/docs/.vuepress/dist/pass-and-return-value.html +0 -74
  130. package/docs/.vuepress/dist/qa.html +0 -31
  131. package/docs/.vuepress/dist/style.html +0 -306
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## 2.6.0 (2021-11-29)
2
+
3
+ - 支持动态设置 `screenBackgroundColor`
4
+
5
+ ## 2.5.1 (2021-11-09)
6
+
7
+ ### Android specific
8
+
9
+ - 修复导致键盘 `adjustResize` 模式无效的问题
10
+
11
+ ## 2.5.0 (2021-11-04)
12
+
13
+ - 添加 `Garden#setTabItem`,可以动态修改 tab 图标,标题,徽章。
14
+
15
+ - 弃用 `Garden#setTabIcon`
16
+
17
+ - 弃用 `Garden#setTabBadge`
18
+
19
+ ## 2.4.3 (2021-11-03)
20
+
21
+ ### iOS specific
22
+
23
+ - 优化导航栏实现
24
+
25
+ - 移除对 CallKit 的依赖,避免应用商店审核问题
26
+
1
27
  ## 2.4.2 (2021-10-08)
2
28
 
3
29
  ### iOS specific
@@ -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:11.2.1'
36
+ api 'io.github.listenzz:AndroidNavigation:11.3.1'
37
37
  }
@@ -12,8 +12,7 @@ public class Constants {
12
12
  public static final String ARG_ACTION = "action";
13
13
  public static final String ARG_OPTIONS = "options";
14
14
 
15
- public static final String ACTION_SET_TAB_ICON = "SET_TAB_ICON";
16
- public static final String ACTION_SET_TAB_BADGE = "SET_TAB_BADGE";
15
+ public static final String ACTION_SET_TAB_ITEM = "SET_TAB_ITEM";
17
16
  public static final String ACTION_UPDATE_TAB_BAR = "UPDATE_TAB_BAR";
18
17
 
19
18
  }
@@ -2,6 +2,7 @@ package com.reactnative.hybridnavigation;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.graphics.Color;
5
+ import android.graphics.drawable.ColorDrawable;
5
6
  import android.os.Bundle;
6
7
  import android.text.TextUtils;
7
8
  import android.view.View;
@@ -107,6 +108,7 @@ public class Garden {
107
108
  } else if (rightBarButtonItem != null) {
108
109
  setRightBarButtonItem(rightBarButtonItem);
109
110
  }
111
+
110
112
  Bundle leftBarButtonItem = options.getBundle("leftBarButtonItem");
111
113
  ArrayList<Bundle> leftBarButtonItems = options.getParcelableArrayList("leftBarButtonItems");
112
114
  if (leftBarButtonItems != null) {
@@ -265,6 +267,15 @@ public class Garden {
265
267
 
266
268
  applyOptions(patches);
267
269
 
270
+ if (readableMap.hasKey("screenBackgroundColor")) {
271
+ String color = readableMap.getString("screenBackgroundColor");
272
+ style.setScreenBackgroundColor(Color.parseColor(color));
273
+ View root = fragment.getView();
274
+ if (root != null) {
275
+ root.setBackground(new ColorDrawable(Color.parseColor(color)));
276
+ }
277
+ }
278
+
268
279
  if (shouldUpdateStatusBar(readableMap)) {
269
280
  fragment.setNeedsStatusBarAppearanceUpdate();
270
281
  }
@@ -281,7 +292,7 @@ public class Garden {
281
292
  boolean passThroughTouches = readableMap.getBoolean("passThroughTouches");
282
293
  setPassThroughTouches(passThroughTouches);
283
294
  }
284
-
295
+
285
296
  Bundle options = mergeOptions(fragment.getOptions(), patches);
286
297
 
287
298
  if (readableMap.hasKey("leftBarButtonItem")) {
@@ -338,7 +349,7 @@ public class Garden {
338
349
  }
339
350
 
340
351
  private boolean shouldUpdateNavigationBar(@NonNull ReadableMap readableMap) {
341
- String[] keys = new String[]{"navigationBarColorAndroid", "navigationBarHiddenAndroid"};
352
+ String[] keys = new String[]{"navigationBarColorAndroid", "navigationBarHiddenAndroid", "screenBackgroundColor"};
342
353
  for (String key : keys) {
343
354
  if (readableMap.hasKey(key)) {
344
355
  return true;
@@ -1,7 +1,13 @@
1
1
  package com.reactnative.hybridnavigation;
2
2
 
3
+ import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ITEM;
4
+ import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
5
+ import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
6
+ import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
7
+ import static com.reactnative.hybridnavigation.Parameters.toBundle;
8
+ import static com.reactnative.hybridnavigation.Parameters.toList;
9
+
3
10
  import android.app.Activity;
4
- import android.os.Build;
5
11
  import android.os.Bundle;
6
12
  import android.os.Handler;
7
13
 
@@ -31,14 +37,6 @@ import com.navigation.androidx.TabBarFragment;
31
37
  import java.util.HashMap;
32
38
  import java.util.Map;
33
39
 
34
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_BADGE;
35
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ICON;
36
- import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
37
- import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
38
- import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
39
- import static com.reactnative.hybridnavigation.Parameters.toBundle;
40
- import static com.reactnative.hybridnavigation.Parameters.toList;
41
-
42
40
  /**
43
41
  * Created by Listen on 2017/11/22.
44
42
  */
@@ -99,7 +97,7 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
99
97
  @Override
100
98
  public Map<String, Object> getConstants() {
101
99
  final Map<String, Object> constants = new HashMap<>();
102
- constants.put("TOOLBAR_HEIGHT", Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 56 : 48);
100
+ constants.put("TOOLBAR_HEIGHT", 56);
103
101
  return constants;
104
102
  }
105
103
 
@@ -193,37 +191,22 @@ public class GardenModule extends ReactContextBaseJavaModule implements Lifecycl
193
191
  }
194
192
 
195
193
  @ReactMethod
196
- public void setTabIcon(@NonNull final String sceneId, @NonNull final ReadableArray options) {
194
+ public void setTabItem(final String sceneId, @NonNull final ReadableArray options) {
195
+ FLog.i(TAG, "setTabItem:" + options);
197
196
  uiTaskExecutor.submit(() -> {
198
197
  AwesomeFragment fragment = findFragmentBySceneId(sceneId);
199
198
  if (fragment != null && fragment.getView() != null) {
200
199
  TabBarFragment tabBarFragment = fragment.getTabBarFragment();
201
200
  if (tabBarFragment != null) {
202
201
  Bundle bundle = new Bundle();
203
- bundle.putString(ARG_ACTION, ACTION_SET_TAB_ICON);
204
- bundle.putSerializable(ARG_OPTIONS, toList(options));
205
- tabBarFragment.updateTabBar(bundle);
206
- }
207
- }
208
- });
209
- }
210
-
211
- @ReactMethod
212
- public void setTabBadge(@NonNull final String sceneId, @NonNull final ReadableArray options) {
213
- uiTaskExecutor.submit(() -> {
214
- AwesomeFragment fragment = findFragmentBySceneId(sceneId);
215
- if (fragment != null) {
216
- TabBarFragment tabBarFragment = fragment.getTabBarFragment();
217
- if (tabBarFragment != null) {
218
- Bundle bundle = new Bundle();
219
- bundle.putString(ARG_ACTION, ACTION_SET_TAB_BADGE);
202
+ bundle.putString(ARG_ACTION, ACTION_SET_TAB_ITEM);
220
203
  bundle.putSerializable(ARG_OPTIONS, toList(options));
221
204
  tabBarFragment.updateTabBar(bundle);
222
205
  }
223
206
  }
224
207
  });
225
208
  }
226
-
209
+
227
210
  @ReactMethod
228
211
  public void setMenuInteractive(final String sceneId, final boolean enabled) {
229
212
  uiTaskExecutor.submit(() -> {
@@ -1,11 +1,9 @@
1
1
  package com.reactnative.hybridnavigation;
2
2
 
3
- import android.annotation.TargetApi;
4
3
  import android.content.Context;
5
4
  import android.graphics.Color;
6
5
  import android.graphics.drawable.ColorDrawable;
7
6
  import android.graphics.drawable.Drawable;
8
- import android.os.Build;
9
7
  import android.util.AttributeSet;
10
8
  import android.view.LayoutInflater;
11
9
  import android.view.View;
@@ -46,7 +44,6 @@ public class ReactTabBar extends FrameLayout {
46
44
  init();
47
45
  }
48
46
 
49
- @TargetApi(Build.VERSION_CODES.LOLLIPOP)
50
47
  public ReactTabBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
51
48
  super(context, attrs, defStyleAttr, defStyleRes);
52
49
  init();
@@ -1,5 +1,19 @@
1
1
  package com.reactnative.hybridnavigation;
2
2
 
3
+ import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ITEM;
4
+ import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
5
+ import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
6
+ import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
7
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
8
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_INDEX;
9
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
10
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
11
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
12
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
13
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
14
+ import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
15
+ import static com.reactnative.hybridnavigation.Parameters.mergeOptions;
16
+
3
17
  import android.os.Bundle;
4
18
 
5
19
  import androidx.annotation.NonNull;
@@ -12,27 +26,13 @@ import com.navigation.androidx.FragmentHelper;
12
26
  import com.navigation.androidx.Style;
13
27
  import com.navigation.androidx.TabBar;
14
28
  import com.navigation.androidx.TabBarFragment;
29
+ import com.navigation.androidx.TabBarItem;
15
30
  import com.navigation.androidx.TabBarProvider;
16
31
  import com.navigation.androidx.TransitionAnimation;
17
32
 
18
33
  import java.util.ArrayList;
19
34
  import java.util.List;
20
35
 
21
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_BADGE;
22
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ICON;
23
- import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
24
- import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
25
- import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
26
- import static com.reactnative.hybridnavigation.HBDEventEmitter.EVENT_NAVIGATION;
27
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_INDEX;
28
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_ON;
29
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_REQUEST_CODE;
30
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_CODE;
31
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_RESULT_DATA;
32
- import static com.reactnative.hybridnavigation.HBDEventEmitter.KEY_SCENE_ID;
33
- import static com.reactnative.hybridnavigation.HBDEventEmitter.ON_COMPONENT_RESULT;
34
- import static com.reactnative.hybridnavigation.Parameters.mergeOptions;
35
-
36
36
 
37
37
  /**
38
38
  * Created by listen on 2018/1/15.
@@ -126,21 +126,17 @@ public class ReactTabBarFragment extends TabBarFragment {
126
126
  }
127
127
 
128
128
  switch (action) {
129
- case ACTION_SET_TAB_BADGE:
130
- setTabBadge(options.getParcelableArrayList(ARG_OPTIONS));
131
- break;
132
- case ACTION_SET_TAB_ICON:
133
- setTabIcon(options.getParcelableArrayList(ARG_OPTIONS));
129
+ case ACTION_SET_TAB_ITEM:
130
+ setTabItem(options.getParcelableArrayList(ARG_OPTIONS));
134
131
  break;
135
132
  case ACTION_UPDATE_TAB_BAR:
136
133
  updateTabBarAppearance(options.getBundle(ARG_OPTIONS));
137
134
  break;
138
135
  }
139
-
140
136
  }
141
137
  }
142
138
 
143
- private void setTabBadge(@Nullable ArrayList<Bundle> options) {
139
+ private void setTabItem(@Nullable ArrayList<Bundle> options) {
144
140
  if (options == null) {
145
141
  return;
146
142
  }
@@ -149,42 +145,44 @@ public class ReactTabBarFragment extends TabBarFragment {
149
145
  if (tabBar == null) {
150
146
  return;
151
147
  }
148
+
152
149
  for (Bundle option : options) {
153
150
  int index = (int) option.getDouble("index");
154
- boolean hidden = option.getBoolean("hidden", true);
155
- String text = !hidden ? option.getString("text", "") : "";
156
- boolean dot = !hidden && option.getBoolean("dot", false);
157
- tabBar.hideBadgeAtIndex(index);
158
- tabBar.showTextBadgeAtIndex(index, text);
159
- if (dot) {
160
- tabBar.showDotBadgeAtIndex(index);
151
+ TabBarItem tabBarItem = tabBar.getTabBarItem(index);
152
+ if (tabBarItem == null) {
153
+ continue;
161
154
  }
162
- }
163
- }
164
155
 
165
- private void setTabIcon(@Nullable ArrayList<Bundle> options) {
166
- TabBar tabBar = getTabBar();
167
- if (options == null || tabBar == null) {
168
- return;
169
- }
156
+ // title
157
+ String title = option.getString("title");
158
+ if (title != null) {
159
+ tabBarItem.title = title;
160
+ }
170
161
 
171
- for (Bundle option : options) {
172
- int index = (int) option.getDouble("index");
162
+ // icon
173
163
  Bundle icon = option.getBundle("icon");
174
- Bundle unselectedIcon = option.getBundle("unselectedIcon");
175
- if (icon != null && icon.getString("uri") != null) {
176
- String iconUri = icon.getString("uri");
177
- if (iconUri != null) {
178
- if (unselectedIcon != null) {
179
- tabBar.updateTabIcon(index, iconUri, unselectedIcon.getString("uri"));
180
- } else {
181
- tabBar.updateTabIcon(index, iconUri, null);
182
- }
164
+ if (icon != null) {
165
+ Bundle unselected = icon.getBundle("unselected");
166
+ Bundle selected = icon.getBundle("selected");
167
+ if (unselected != null) {
168
+ tabBarItem.unselectedIconUri = unselected.getString("uri");
183
169
  }
170
+ tabBarItem.iconUri = selected.getString("uri");
184
171
  }
185
- }
186
172
 
187
- tabBar.initialise(tabBar.getCurrentSelectedPosition());
173
+ // badge
174
+ Bundle badge = option.getBundle("badge");
175
+ if (badge != null) {
176
+ boolean hidden = badge.getBoolean("hidden", true);
177
+ String text = !hidden ? badge.getString("text", "") : "";
178
+ boolean dot = !hidden && badge.getBoolean("dot", false);
179
+
180
+ tabBarItem.badgeText = text;
181
+ tabBarItem.showDotBadge = dot;
182
+ }
183
+
184
+ tabBar.renderTabView(index);
185
+ }
188
186
  }
189
187
 
190
188
  private void updateTabBarAppearance(@Nullable Bundle options) {
@@ -1,5 +1,12 @@
1
1
  package com.reactnative.hybridnavigation;
2
2
 
3
+ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
4
+ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
5
+ import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ITEM;
6
+ import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
7
+ import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
8
+ import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
9
+
3
10
  import android.content.Context;
4
11
  import android.graphics.Color;
5
12
  import android.graphics.drawable.ColorDrawable;
@@ -24,14 +31,6 @@ import com.navigation.androidx.TabBarProvider;
24
31
  import java.util.ArrayList;
25
32
  import java.util.List;
26
33
 
27
- import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
28
- import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
29
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_BADGE;
30
- import static com.reactnative.hybridnavigation.Constants.ACTION_SET_TAB_ICON;
31
- import static com.reactnative.hybridnavigation.Constants.ACTION_UPDATE_TAB_BAR;
32
- import static com.reactnative.hybridnavigation.Constants.ARG_ACTION;
33
- import static com.reactnative.hybridnavigation.Constants.ARG_OPTIONS;
34
-
35
34
  public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.ReactBridgeReloadListener {
36
35
 
37
36
  private static final String TAG = "Navigator";
@@ -152,8 +151,6 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
152
151
  public void onDestroyTabBar() {
153
152
  unmountReactView();
154
153
  tabBarFragment = null;
155
-
156
-
157
154
  getReactBridgeManager().removeReactBridgeReloadListener(this);
158
155
  }
159
156
 
@@ -184,20 +181,16 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
184
181
  }
185
182
 
186
183
  switch (action) {
187
- case ACTION_SET_TAB_BADGE:
188
- setTabBadge(options.getParcelableArrayList(ARG_OPTIONS));
189
- break;
190
- case ACTION_SET_TAB_ICON:
191
- setTabIcon(options.getParcelableArrayList(ARG_OPTIONS));
184
+ case ACTION_SET_TAB_ITEM:
185
+ setTabItem(options.getParcelableArrayList(ARG_OPTIONS));
192
186
  break;
193
187
  case ACTION_UPDATE_TAB_BAR:
194
188
  updateTabBarAppearance(options.getBundle(ARG_OPTIONS));
195
189
  break;
196
190
  }
197
191
  }
198
-
199
-
200
- private void setTabBadge(@Nullable ArrayList<Bundle> options) {
192
+
193
+ private void setTabItem(@Nullable ArrayList<Bundle> options) {
201
194
  if (options == null) {
202
195
  return;
203
196
  }
@@ -211,53 +204,40 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
211
204
 
212
205
  for (Bundle option : options) {
213
206
  int index = (int) option.getDouble("index");
214
- boolean hidden = option.getBoolean("hidden", true);
215
-
216
- String text = !hidden ? option.getString("text", null) : null;
217
- boolean dot = !hidden && option.getBoolean("dot", false);
218
-
219
207
  Bundle tab = tabs.get(index);
220
- tab.putString("badgeText", text);
221
- tab.putBoolean("dot", dot);
222
- }
223
-
224
- reactRootView.setAppProperties(getProps(tabBarFragment));
225
- }
226
-
227
- private void setTabIcon(@Nullable ArrayList<Bundle> options) {
228
- if (options == null) {
229
- return;
230
- }
231
-
232
- Bundle tabBar = tabBarFragment.getOptions();
233
- ArrayList<Bundle> tabs = tabBar.getParcelableArrayList("tabs");
234
-
235
- if (tabs == null) {
236
- return;
237
- }
238
-
239
- for (Bundle option : options) {
240
- int index = (int) option.getDouble("index");
208
+
209
+ // title
210
+ String title = option.getString("title");
211
+ if (title != null) {
212
+ tab.putString("title", title);
213
+ }
214
+
215
+ // icon
241
216
  Bundle icon = option.getBundle("icon");
242
- Bundle unselectedIcon = option.getBundle("unselectedIcon");
243
- Context context = tabBarFragment.requireContext();
244
- Bundle tab = tabs.get(index);
245
217
  if (icon != null) {
246
- String uri = Utils.getIconUri(context, icon.getString("uri"));
247
- tab.putString("icon", uri);
248
- tab.putString("unselectedIcon", null);
218
+ Bundle unselected = icon.getBundle("unselected");
219
+ Bundle selected = icon.getBundle("selected");
220
+ if (unselected != null) {
221
+ tab.putString("unselectedIcon", unselected.getString("uri"));
222
+ }
223
+ tab.putString("icon", selected.getString("uri"));
249
224
  }
250
225
 
251
- if (unselectedIcon != null) {
252
- String uri = Utils.getIconUri(context, unselectedIcon.getString("uri"));
253
- tab.putString("unselectedIcon", uri);
226
+ // badge
227
+ Bundle badge = option.getBundle("badge");
228
+ if (badge != null) {
229
+ boolean hidden = badge.getBoolean("hidden", true);
230
+ String text = !hidden ? badge.getString("text", "") : "";
231
+ boolean dot = !hidden && badge.getBoolean("dot", false);
232
+
233
+ tab.putString("badgeText", text);
234
+ tab.putBoolean("dot", dot);
254
235
  }
255
236
  }
256
237
 
257
238
  reactRootView.setAppProperties(getProps(tabBarFragment));
258
239
  }
259
-
260
-
240
+
261
241
  private void updateTabBarAppearance(@Nullable Bundle bundle) {
262
242
  if (bundle == null) {
263
243
  return;
package/docs/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  - 内置 drawer, tabs, stack 标准容器,同时支持自定义容器和导航
10
10
  - 支持 deep link
11
11
 
12
- ![navigation-android](../screenshot/android.png)
12
+ ![README-2021-10-19-15-39-45](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/README-2021-10-19-15-39-45.png)
13
13
 
14
14
  ## Support
15
15
 
@@ -66,11 +66,11 @@ Then, in another CLI window:
66
66
  npm run run:android
67
67
  ```
68
68
 
69
- [**Download demo apk**](https://raw.githubusercontent.com/listenzz/hybrid-navigation/master/screenshot/app-release.apk)
69
+ [**Download demo apk**](https://todoit.oss-cn-shanghai.aliyuncs.com/app-release.apk)
70
70
 
71
71
  或通过扫描二维码安装 demo
72
72
 
73
- ![demo-qrcode](../screenshot/demo-qrcode.png)
73
+ ![README-2021-10-19-15-58-19](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/README-2021-10-19-15-58-19.png)
74
74
 
75
75
  ### run on iOS
76
76
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  tabs 容器有一个默认的 TabBar, 支持未读消息数,小红点提示等功能。它是由原生组件实现的,性能优越,满足 80% 常用场景。如果你希望对 TabBar 有更多的控制权,譬如实现如下效果:
4
4
 
5
- ![](../screenshot/tabbar.jpg)
5
+ ![custom-tabbar-2021-10-19-15-36-24](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/custom-tabbar-2021-10-19-15-36-24.jpg)
6
6
 
7
7
  那么你需要使用 `tabBarModuleName` 选项来指定你的 TabBar 组件。
8
8
 
package/docs/deeplink.md CHANGED
@@ -110,7 +110,7 @@ In SimpleApp/ios/SimpleApp/AppDelegate.m:
110
110
 
111
111
  In Xcode, open the project at SimpleApp/ios/SimpleApp.xcodeproj. Select the project in sidebar and navigate to the info tab. Scroll down to "URL Types" and add one. In the new URL type, set the identifier and the url scheme to your desired url scheme.
112
112
 
113
- ![xcode-linking](../screenshot/xcode-linking.png)
113
+ ![deeplink-2021-10-19-15-37-05](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/deeplink-2021-10-19-15-37-05.png)
114
114
 
115
115
  ## Android 配置
116
116
 
@@ -327,7 +327,7 @@ end
327
327
 
328
328
  在 Build Phases 中新建一个 Run Script
329
329
 
330
- ![ios-run-script](../screenshot/ios-run-script.jpg)
330
+ ![integration-native-2021-10-19-15-38-04](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/integration-native-2021-10-19-15-38-04.jpg)
331
331
 
332
332
  双击标题,将其更名为 Bundle React Native code and images
333
333
 
@@ -339,7 +339,7 @@ export NODE_BINARY=node ../ReactNativeProject/node_modules/react-native/scripts/
339
339
 
340
340
  注意将 ReactNativeProject 替换成你的 RN 项目名
341
341
 
342
- ![ios-run-script](../screenshot/ios-react-script.png)
342
+ ![integration-native-2021-10-19-15-38-21](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/integration-native-2021-10-19-15-38-21.png)
343
343
 
344
344
  像下面那样更改 AppDelegate.m 文件
345
345
 
@@ -175,7 +175,7 @@ cd ios & pod install
175
175
 
176
176
  修改 Info.plist 文件
177
177
 
178
- ![controller-base](../screenshot/controller-base.jpg)
178
+ ![integration-react-2021-10-19-15-38-49](https://todoit.oss-cn-shanghai.aliyuncs.com/todoit/integration-react-2021-10-19-15-38-49.jpg)
179
179
 
180
180
  ## 关于闪屏
181
181
 
package/docs/qa.md CHANGED
@@ -36,3 +36,20 @@ module.exports = {
36
36
  },
37
37
  }
38
38
  ```
39
+
40
+ ## 如何拦截 Android 物理返回键
41
+
42
+ ```ts
43
+ useVisibleEffect(
44
+ useCallback(() => {
45
+ const handleBackPress = () => {
46
+ console.log('---------------')
47
+ // true 表示拦截,false 表示不拦截
48
+ return false
49
+ }
50
+
51
+ BackHandler.addEventListener('hardwareBackPress', handleBackPress)
52
+ return () => BackHandler.removeEventListener('hardwareBackPress', handleBackPress)
53
+ }, []),
54
+ )
55
+ ```