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.
- package/HybridNavigation.podspec +6 -6
- package/LICENSE +1 -1
- package/android/build.gradle +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +27 -40
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +77 -48
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDEventEmitter.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +94 -43
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +134 -117
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +65 -35
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +14 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +133 -89
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +161 -126
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +145 -114
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +40 -28
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +96 -75
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/Navigator.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +111 -79
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +187 -117
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +137 -96
- package/ios/HybridNavigation/ViewController/HBDModalViewController.m +7 -0
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +16 -0
- package/ios/HybridNavigation.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/HybridNavigation.xcodeproj/project.xcworkspace/xcuserdata/listen.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/HybridNavigation.xcodeproj/xcuserdata/listen.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/Navigator.d.ts +6 -6
- package/lib/ReactRegistry.d.ts +3 -3
- package/lib/ReactRegistry.js +14 -10
- package/lib/typing.d.ts +8 -8
- package/package.json +27 -16
- package/src/DeepLink.ts +60 -0
- package/src/Garden.ts +171 -0
- package/src/NavigationModule.ts +33 -0
- package/src/Navigator.ts +404 -0
- package/src/ReactRegistry.tsx +138 -0
- package/src/hooks.ts +83 -0
- package/src/index.ts +9 -0
- package/src/router/drawer.ts +34 -0
- package/src/router/index.ts +166 -0
- package/src/router/screen.ts +12 -0
- package/src/router/stack.ts +80 -0
- package/src/router/tabs.ts +49 -0
- package/src/router/typing.ts +45 -0
- package/src/store.ts +49 -0
- package/src/typing.ts +148 -0
- package/src/utils.ts +83 -0
- package/.buckconfig +0 -6
- package/.editorconfig +0 -16
- package/.eslintignore +0 -5
- package/.gitattributes +0 -1
- package/.github/workflows/docs.yml +0 -25
- package/CHANGELOG.md +0 -399
- package/babel.config.js +0 -15
- package/docs/README.md +0 -109
- package/docs/custom-tabbar.md +0 -138
- package/docs/deeplink.md +0 -148
- package/docs/integration-native.md +0 -390
- package/docs/integration-react.md +0 -194
- package/docs/lifecycle.md +0 -85
- package/docs/navigation.md +0 -589
- package/docs/pass-and-return-value.md +0 -163
- package/docs/qa.md +0 -57
- package/docs/style.md +0 -533
- package/jest.config.js +0 -4
- package/metro.config.js +0 -17
- package/screenshot/android.png +0 -0
- package/screenshot/bulge.jpg +0 -0
- package/screenshot/controller-base.jpg +0 -0
- package/screenshot/demo-qrcode.png +0 -0
- package/screenshot/header-search-paths.jpg +0 -0
- package/screenshot/ios-react-script.png +0 -0
- package/screenshot/ios-run-script.jpg +0 -0
- package/screenshot/statusbar-inperfect.png +0 -0
- package/screenshot/statusbar-setup-step-1.png +0 -0
- package/screenshot/statusbar-setup-step-2.png +0 -0
- package/screenshot/tabbar.jpg +0 -0
- package/screenshot/topbar-default.png +0 -0
- package/screenshot/xcode-linking.png +0 -0
|
@@ -74,21 +74,29 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
74
74
|
|
|
75
75
|
@Override
|
|
76
76
|
protected void setPresentAnimation(AwesomeFragment current, AwesomeFragment previous) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
List<AwesomeFragment> children = getChildFragments();
|
|
80
|
-
if (children.indexOf(current) > children.indexOf(previous)) {
|
|
81
|
-
current.setAnimation(FadeShort);
|
|
82
|
-
previous.setAnimation(DelayShort);
|
|
83
|
-
} else {
|
|
84
|
-
current.setAnimation(TransitionAnimation.None);
|
|
85
|
-
previous.setAnimation(FadeShort);
|
|
86
|
-
}
|
|
77
|
+
if (shouldImproveTransitionForReact(current)) {
|
|
78
|
+
improveTransitionForReact(current, previous);
|
|
87
79
|
return;
|
|
88
80
|
}
|
|
89
81
|
super.setPresentAnimation(current, previous);
|
|
90
82
|
}
|
|
91
83
|
|
|
84
|
+
private boolean shouldImproveTransitionForReact(AwesomeFragment current) {
|
|
85
|
+
ReactFragment reactFragment = Utils.findReactFragment(current);
|
|
86
|
+
return reactFragment != null && !reactFragment.isFirstRenderCompleted();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private void improveTransitionForReact(AwesomeFragment current, AwesomeFragment previous) {
|
|
90
|
+
List<AwesomeFragment> children = getChildFragments();
|
|
91
|
+
if (children.indexOf(current) > children.indexOf(previous)) {
|
|
92
|
+
current.setAnimation(FadeShort);
|
|
93
|
+
previous.setAnimation(DelayShort);
|
|
94
|
+
} else {
|
|
95
|
+
current.setAnimation(TransitionAnimation.None);
|
|
96
|
+
previous.setAnimation(FadeShort);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
92
100
|
@Override
|
|
93
101
|
protected void onCustomStyle(@NonNull Style style) {
|
|
94
102
|
super.onCustomStyle(style);
|
|
@@ -116,23 +124,108 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
|
|
127
|
+
private Bundle options;
|
|
128
|
+
|
|
129
|
+
@NonNull
|
|
130
|
+
public Bundle getOptions() {
|
|
131
|
+
if (options == null) {
|
|
132
|
+
Bundle args = FragmentHelper.getArguments(this);
|
|
133
|
+
options = args.getBundle(ARG_OPTIONS);
|
|
134
|
+
if (options == null) {
|
|
135
|
+
options = new Bundle();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return options;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public void setOptions(@NonNull Bundle options) {
|
|
142
|
+
this.options = options;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public void setIntercepted(boolean intercepted) {
|
|
146
|
+
this.intercepted = intercepted;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private boolean intercepted = true;
|
|
150
|
+
|
|
151
|
+
@Override
|
|
152
|
+
public void setSelectedIndex(int index, @Nullable Runnable completion) {
|
|
153
|
+
if (shouldIntercept()) {
|
|
154
|
+
sendSwitchTabEvent(index);
|
|
155
|
+
restoreTabBarState();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
super.setSelectedIndex(index, completion);
|
|
160
|
+
intercepted = true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private boolean shouldIntercept() {
|
|
164
|
+
return isAdded() && bridgeManager.hasRootLayout() && this.intercepted;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private void restoreTabBarState() {
|
|
168
|
+
TabBarProvider tabBarProvider = getTabBarProvider();
|
|
169
|
+
if (tabBarProvider == null) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
tabBarProvider.setSelectedIndex(getSelectedIndex());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private void sendSwitchTabEvent(int index) {
|
|
176
|
+
Bundle data = new Bundle();
|
|
177
|
+
data.putString(KEY_SCENE_ID, getSceneId());
|
|
178
|
+
data.putString(KEY_INDEX, getSelectedIndex() + "-" + index);
|
|
179
|
+
HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_SWITCH_TAB, Arguments.fromBundle(data));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@Override
|
|
183
|
+
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
|
|
184
|
+
super.onFragmentResult(requestCode, resultCode, data);
|
|
185
|
+
sendResult(requestCode, resultCode, data);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private void sendResult(int requestCode, int resultCode, Bundle data) {
|
|
189
|
+
Bundle options = getOptions();
|
|
190
|
+
String tabBarModuleName = options.getString("tabBarModuleName");
|
|
191
|
+
if (tabBarModuleName == null) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
Bundle result = new Bundle();
|
|
195
|
+
result.putInt(KEY_REQUEST_CODE, requestCode);
|
|
196
|
+
result.putInt(KEY_RESULT_CODE, resultCode);
|
|
197
|
+
result.putBundle(KEY_RESULT_DATA, data);
|
|
198
|
+
result.putString(KEY_SCENE_ID, getSceneId());
|
|
199
|
+
result.putString(KEY_ON, ON_COMPONENT_RESULT);
|
|
200
|
+
HBDEventEmitter.sendEvent(EVENT_NAVIGATION, Arguments.fromBundle(result));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public Style getStyle() {
|
|
204
|
+
return mStyle;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
|
|
119
208
|
@Override
|
|
120
209
|
public void updateTabBar(Bundle options) {
|
|
121
210
|
super.updateTabBar(options);
|
|
122
211
|
if (getTabBarProvider() instanceof DefaultTabBarProvider) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
212
|
+
updateDefaultTabBar(options);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
127
215
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
216
|
+
private void updateDefaultTabBar(Bundle options) {
|
|
217
|
+
String action = options.getString(ARG_ACTION);
|
|
218
|
+
if (action == null) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
switch (action) {
|
|
223
|
+
case ACTION_SET_TAB_ITEM:
|
|
224
|
+
setTabItem(options.getParcelableArrayList(ARG_OPTIONS));
|
|
225
|
+
break;
|
|
226
|
+
case ACTION_UPDATE_TAB_BAR:
|
|
227
|
+
updateTabBarStyle(options.getBundle(ARG_OPTIONS));
|
|
228
|
+
break;
|
|
136
229
|
}
|
|
137
230
|
}
|
|
138
231
|
|
|
@@ -153,41 +246,59 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
153
246
|
continue;
|
|
154
247
|
}
|
|
155
248
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
249
|
+
setTabItemTitle(option, tabBarItem);
|
|
250
|
+
setTabItemIcon(option, tabBarItem);
|
|
251
|
+
setTabItemBadge(option, tabBarItem);
|
|
252
|
+
tabBar.renderTabView(index);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
161
255
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (unselected != null) {
|
|
168
|
-
tabBarItem.unselectedIconUri = unselected.getString("uri");
|
|
169
|
-
}
|
|
170
|
-
tabBarItem.iconUri = selected.getString("uri");
|
|
171
|
-
}
|
|
256
|
+
private void setTabItemBadge(Bundle option, TabBarItem tabBarItem) {
|
|
257
|
+
Bundle badge = option.getBundle("badge");
|
|
258
|
+
if (badge == null) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
172
261
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
boolean hidden = badge.getBoolean("hidden", true);
|
|
177
|
-
String text = !hidden ? badge.getString("text", "") : "";
|
|
178
|
-
boolean dot = !hidden && badge.getBoolean("dot", false);
|
|
262
|
+
boolean hidden = badge.getBoolean("hidden", true);
|
|
263
|
+
String text = !hidden ? badge.getString("text", "") : "";
|
|
264
|
+
boolean dot = !hidden && badge.getBoolean("dot", false);
|
|
179
265
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
266
|
+
tabBarItem.badgeText = text;
|
|
267
|
+
tabBarItem.showDotBadge = dot;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private void setTabItemIcon(Bundle option, TabBarItem tabBarItem) {
|
|
271
|
+
Bundle icon = option.getBundle("icon");
|
|
272
|
+
if (icon == null) {
|
|
273
|
+
return;
|
|
185
274
|
}
|
|
275
|
+
|
|
276
|
+
Bundle selected = icon.getBundle("selected");
|
|
277
|
+
tabBarItem.iconUri = selected.getString("uri");
|
|
278
|
+
|
|
279
|
+
Bundle unselected = icon.getBundle("unselected");
|
|
280
|
+
if (unselected == null) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
tabBarItem.unselectedIconUri = unselected.getString("uri");
|
|
186
284
|
}
|
|
187
285
|
|
|
188
|
-
private void
|
|
286
|
+
private void setTabItemTitle(Bundle option, TabBarItem tabBarItem) {
|
|
287
|
+
String title = option.getString("title");
|
|
288
|
+
if (title == null) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
tabBarItem.title = title;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private void updateTabBarStyle(@Nullable Bundle options) {
|
|
295
|
+
if (options == null) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
setOptions(mergeOptions(getOptions(), options));
|
|
299
|
+
|
|
189
300
|
TabBar tabBar = getTabBar();
|
|
190
|
-
if (
|
|
301
|
+
if (tabBar == null) {
|
|
191
302
|
return;
|
|
192
303
|
}
|
|
193
304
|
|
|
@@ -196,8 +307,6 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
196
307
|
String tabBarItemColor = options.getString("tabBarItemColor");
|
|
197
308
|
String tabBarUnselectedItemColor = options.getString("tabBarUnselectedItemColor");
|
|
198
309
|
|
|
199
|
-
setOptions(mergeOptions(getOptions(), options));
|
|
200
|
-
|
|
201
310
|
if (tabBarColor != null) {
|
|
202
311
|
mStyle.setTabBarBackgroundColor(tabBarColor);
|
|
203
312
|
tabBar.setBarBackgroundColor(tabBarColor);
|
|
@@ -219,78 +328,4 @@ public class ReactTabBarFragment extends TabBarFragment {
|
|
|
219
328
|
tabBar.initialise(tabBar.getCurrentSelectedPosition());
|
|
220
329
|
}
|
|
221
330
|
|
|
222
|
-
private Bundle options;
|
|
223
|
-
|
|
224
|
-
@NonNull
|
|
225
|
-
public Bundle getOptions() {
|
|
226
|
-
if (options == null) {
|
|
227
|
-
Bundle args = FragmentHelper.getArguments(this);
|
|
228
|
-
options = args.getBundle(ARG_OPTIONS);
|
|
229
|
-
if (options == null) {
|
|
230
|
-
options = new Bundle();
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return options;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
public void setOptions(@NonNull Bundle options) {
|
|
237
|
-
this.options = options;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
public void setIntercepted(boolean intercepted) {
|
|
241
|
-
this.intercepted = intercepted;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
private boolean intercepted = true;
|
|
245
|
-
|
|
246
|
-
@Override
|
|
247
|
-
public void setSelectedIndex(int index, @Nullable Runnable completion) {
|
|
248
|
-
if (!isAdded()) {
|
|
249
|
-
super.setSelectedIndex(index, completion);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (shouldIntercept(index)) {
|
|
254
|
-
TabBarProvider tabBarProvider = getTabBarProvider();
|
|
255
|
-
if (tabBarProvider != null) {
|
|
256
|
-
tabBarProvider.setSelectedIndex(getSelectedIndex());
|
|
257
|
-
}
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
super.setSelectedIndex(index, completion);
|
|
262
|
-
intercepted = true;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private boolean shouldIntercept(int index) {
|
|
266
|
-
if (bridgeManager.hasRootLayout() && this.intercepted) {
|
|
267
|
-
Bundle data = new Bundle();
|
|
268
|
-
data.putString(KEY_SCENE_ID, getSceneId());
|
|
269
|
-
data.putString(KEY_INDEX, getSelectedIndex() + "-" + index);
|
|
270
|
-
HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_SWITCH_TAB, Arguments.fromBundle(data));
|
|
271
|
-
return true;
|
|
272
|
-
}
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
@Override
|
|
277
|
-
public void onFragmentResult(int requestCode, int resultCode, Bundle data) {
|
|
278
|
-
super.onFragmentResult(requestCode, resultCode, data);
|
|
279
|
-
Bundle options = getOptions();
|
|
280
|
-
String tabBarModuleName = options.getString("tabBarModuleName");
|
|
281
|
-
if (tabBarModuleName != null) {
|
|
282
|
-
Bundle result = new Bundle();
|
|
283
|
-
result.putInt(KEY_REQUEST_CODE, requestCode);
|
|
284
|
-
result.putInt(KEY_RESULT_CODE, resultCode);
|
|
285
|
-
result.putBundle(KEY_RESULT_DATA, data);
|
|
286
|
-
result.putString(KEY_SCENE_ID, getSceneId());
|
|
287
|
-
result.putString(KEY_ON, ON_COMPONENT_RESULT);
|
|
288
|
-
HBDEventEmitter.sendEvent(EVENT_NAVIGATION, Arguments.fromBundle(result));
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
public Style getStyle() {
|
|
293
|
-
return mStyle;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
331
|
}
|
|
@@ -42,39 +42,53 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
42
42
|
@Override
|
|
43
43
|
public View onCreateTabBar(@NonNull List<TabBarItem> tabBarItems, @NonNull TabBarFragment tabBarFragment, @Nullable Bundle savedInstanceState) {
|
|
44
44
|
if (!(tabBarFragment instanceof ReactTabBarFragment)) {
|
|
45
|
-
throw new IllegalStateException("必须和 ReactTabBarFragment 一起使用");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
ReactTabBarFragment reactTabBarFragment = (ReactTabBarFragment) tabBarFragment;
|
|
49
|
-
Bundle options = reactTabBarFragment.getOptions();
|
|
50
|
-
Context context = reactTabBarFragment.requireContext();
|
|
51
|
-
List<AwesomeFragment> children = tabBarFragment.getChildFragments();
|
|
52
|
-
|
|
53
|
-
ArrayList<Bundle> tabs = options.getParcelableArrayList("tabs");
|
|
54
|
-
if (tabs == null) {
|
|
55
|
-
tabs = new ArrayList<>();
|
|
56
|
-
for (int i = 0, size = tabBarItems.size(); i < size; i++) {
|
|
57
|
-
TabBarItem tabBarItem = tabBarItems.get(i);
|
|
58
|
-
Bundle tab = new Bundle();
|
|
59
|
-
tab.putInt("index", i);
|
|
60
|
-
tab.putString("icon", Utils.getIconUri(context, tabBarItem.iconUri));
|
|
61
|
-
tab.putString("unselectedIcon", Utils.getIconUri(context, tabBarItem.unselectedIconUri));
|
|
62
|
-
tab.putString("title", tabBarItem.title);
|
|
63
|
-
Pair<String, String> pair = extractSceneIdAndModuleName(children.get(i));
|
|
64
|
-
tab.putString("sceneId", pair.first);
|
|
65
|
-
tab.putString("moduleName", pair.second);
|
|
66
|
-
tabs.add(i, tab);
|
|
67
|
-
}
|
|
68
|
-
options.putParcelableArrayList("tabs", tabs);
|
|
45
|
+
throw new IllegalStateException("自定义 TabBar 必须和 ReactTabBarFragment 一起使用");
|
|
69
46
|
}
|
|
47
|
+
this.tabBarFragment = (ReactTabBarFragment) tabBarFragment;
|
|
70
48
|
|
|
49
|
+
Bundle options = this.tabBarFragment.getOptions();
|
|
71
50
|
String tabBarModuleName = options.getString("tabBarModuleName");
|
|
72
|
-
|
|
73
51
|
if (tabBarModuleName == null) {
|
|
74
52
|
throw new IllegalStateException("tabBarModuleName 不能为 null");
|
|
75
53
|
}
|
|
76
54
|
|
|
77
|
-
reactRootView =
|
|
55
|
+
HBDReactRootView reactRootView = createReactRootView();
|
|
56
|
+
this.reactRootView = reactRootView;
|
|
57
|
+
startReactApplication(tabBarItems, tabBarModuleName, reactRootView);
|
|
58
|
+
|
|
59
|
+
this.tabBar = createReactTabBar(reactRootView, options);
|
|
60
|
+
return tabBar;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@NonNull
|
|
64
|
+
private ReactTabBar createReactTabBar(HBDReactRootView reactRootView, Bundle options) {
|
|
65
|
+
boolean sizeIndeterminate = options.getBoolean("sizeIndeterminate");
|
|
66
|
+
ReactTabBar tabBar = new ReactTabBar(tabBarFragment.requireContext(), sizeIndeterminate);
|
|
67
|
+
Style style = tabBarFragment.getStyle();
|
|
68
|
+
tabBar.setTabBarBackground(new ColorDrawable(Color.parseColor(style.getTabBarBackgroundColor())));
|
|
69
|
+
tabBar.setShadow(style.getTabBarShadow());
|
|
70
|
+
tabBar.setRootView(reactRootView);
|
|
71
|
+
return tabBar;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private void startReactApplication(@NonNull List<TabBarItem> tabBarItems, String tabBarModuleName, HBDReactRootView reactRootView) {
|
|
75
|
+
Bundle options = tabBarFragment.getOptions();
|
|
76
|
+
inflateTabsIfNeeded(tabBarItems, options);
|
|
77
|
+
|
|
78
|
+
Bundle props = createProps(options);
|
|
79
|
+
props.putInt("selectedIndex", options.getInt("selectedIndex"));
|
|
80
|
+
|
|
81
|
+
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
82
|
+
bridgeManager.addReactBridgeReloadListener(this);
|
|
83
|
+
ReactInstanceManager reactInstanceManager = bridgeManager.getReactInstanceManager();
|
|
84
|
+
|
|
85
|
+
reactRootView.startReactApplication(reactInstanceManager, tabBarModuleName, props);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@NonNull
|
|
89
|
+
private HBDReactRootView createReactRootView() {
|
|
90
|
+
HBDReactRootView reactRootView = new HBDReactRootView(tabBarFragment.requireContext());
|
|
91
|
+
Bundle options = tabBarFragment.getOptions();
|
|
78
92
|
boolean sizeIndeterminate = options.getBoolean("sizeIndeterminate");
|
|
79
93
|
if (sizeIndeterminate) {
|
|
80
94
|
reactRootView.setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, WRAP_CONTENT, Gravity.BOTTOM));
|
|
@@ -83,55 +97,68 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
83
97
|
reactRootView.setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT, Gravity.BOTTOM));
|
|
84
98
|
}
|
|
85
99
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
this.tabBar = tabBar;
|
|
96
|
-
|
|
97
|
-
getReactBridgeManager().addReactBridgeReloadListener(this);
|
|
98
|
-
return tabBar;
|
|
100
|
+
return reactRootView;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private void inflateTabsIfNeeded(@NonNull List<TabBarItem> tabBarItems, Bundle options) {
|
|
104
|
+
ArrayList<Bundle> tabs = options.getParcelableArrayList("tabs");
|
|
105
|
+
if (tabs != null) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
options.putParcelableArrayList("tabs", createTabs(tabBarItems));
|
|
99
109
|
}
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
@NonNull
|
|
112
|
+
private ArrayList<Bundle> createTabs(@NonNull List<TabBarItem> tabBarItems) {
|
|
113
|
+
ArrayList<Bundle> tabs = new ArrayList<>();
|
|
114
|
+
Context context = tabBarFragment.requireContext();
|
|
115
|
+
List<AwesomeFragment> children = tabBarFragment.getChildFragments();
|
|
116
|
+
for (int i = 0, size = tabBarItems.size(); i < size; i++) {
|
|
117
|
+
TabBarItem tabBarItem = tabBarItems.get(i);
|
|
118
|
+
Bundle tab = new Bundle();
|
|
119
|
+
tab.putInt("index", i);
|
|
120
|
+
tab.putString("icon", Utils.getIconUri(context, tabBarItem.iconUri));
|
|
121
|
+
tab.putString("unselectedIcon", Utils.getIconUri(context, tabBarItem.unselectedIconUri));
|
|
122
|
+
tab.putString("title", tabBarItem.title);
|
|
123
|
+
Pair<String, String> pair = extractSceneIdAndModuleName(children.get(i));
|
|
124
|
+
tab.putString("sceneId", pair.first);
|
|
125
|
+
tab.putString("moduleName", pair.second);
|
|
126
|
+
tabs.add(i, tab);
|
|
108
127
|
}
|
|
128
|
+
return tabs;
|
|
109
129
|
}
|
|
110
130
|
|
|
111
|
-
private Pair<String, String> extractSceneIdAndModuleName(AwesomeFragment
|
|
112
|
-
if (
|
|
113
|
-
StackFragment stackFragment = (StackFragment)
|
|
114
|
-
|
|
131
|
+
private Pair<String, String> extractSceneIdAndModuleName(AwesomeFragment fragment) {
|
|
132
|
+
if (fragment instanceof StackFragment) {
|
|
133
|
+
StackFragment stackFragment = (StackFragment) fragment;
|
|
134
|
+
fragment = stackFragment.getRootFragment();
|
|
115
135
|
}
|
|
116
|
-
if (
|
|
117
|
-
HybridFragment hybridFragment = (HybridFragment)
|
|
136
|
+
if (fragment instanceof HybridFragment) {
|
|
137
|
+
HybridFragment hybridFragment = (HybridFragment) fragment;
|
|
118
138
|
return new Pair<>(hybridFragment.getSceneId(), hybridFragment.getModuleName());
|
|
119
139
|
}
|
|
120
140
|
return null;
|
|
121
141
|
}
|
|
122
142
|
|
|
123
|
-
private void
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
private void unmountReactView() {
|
|
144
|
+
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
145
|
+
bridgeManager.removeReactBridgeReloadListener(this);
|
|
146
|
+
ReactContext reactContext = bridgeManager.getCurrentReactContext();
|
|
147
|
+
|
|
148
|
+
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (reactRootView != null) {
|
|
152
|
+
reactRootView.unmountReactApplication();
|
|
153
|
+
reactRootView = null;
|
|
154
|
+
}
|
|
126
155
|
}
|
|
127
|
-
|
|
156
|
+
|
|
128
157
|
@NonNull
|
|
129
|
-
private Bundle
|
|
130
|
-
|
|
131
|
-
Bundle options = tabBarFragment.getOptions();
|
|
158
|
+
private Bundle createProps(Bundle options) {
|
|
132
159
|
Bundle props = new Bundle();
|
|
133
|
-
|
|
134
|
-
props.putParcelableArrayList("tabs", tabs);
|
|
160
|
+
|
|
161
|
+
props.putParcelableArrayList("tabs", options.getParcelableArrayList("tabs"));
|
|
135
162
|
props.putString("sceneId", tabBarFragment.getSceneId());
|
|
136
163
|
props.putInt("selectedIndex", tabBarFragment.getSelectedIndex());
|
|
137
164
|
|
|
@@ -151,7 +178,6 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
151
178
|
public void onDestroyTabBar() {
|
|
152
179
|
unmountReactView();
|
|
153
180
|
tabBarFragment = null;
|
|
154
|
-
getReactBridgeManager().removeReactBridgeReloadListener(this);
|
|
155
181
|
}
|
|
156
182
|
|
|
157
183
|
@Override
|
|
@@ -167,12 +193,19 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
167
193
|
@Override
|
|
168
194
|
public void setSelectedIndex(int index) {
|
|
169
195
|
if (tabBarFragment != null) {
|
|
170
|
-
Bundle
|
|
171
|
-
|
|
172
|
-
reactRootView.setAppProperties(
|
|
196
|
+
Bundle props = createProps(tabBarFragment.getOptions());
|
|
197
|
+
props.putInt("selectedIndex", index);
|
|
198
|
+
reactRootView.setAppProperties(props);
|
|
173
199
|
}
|
|
174
200
|
}
|
|
175
201
|
|
|
202
|
+
private final ReactBridgeManager bridgeManager = ReactBridgeManager.get();
|
|
203
|
+
|
|
204
|
+
@NonNull
|
|
205
|
+
public ReactBridgeManager getReactBridgeManager() {
|
|
206
|
+
return bridgeManager;
|
|
207
|
+
}
|
|
208
|
+
|
|
176
209
|
@Override
|
|
177
210
|
public void updateTabBar(@NonNull Bundle options) {
|
|
178
211
|
String action = options.getString(ARG_ACTION);
|
|
@@ -185,60 +218,65 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
185
218
|
setTabItem(options.getParcelableArrayList(ARG_OPTIONS));
|
|
186
219
|
break;
|
|
187
220
|
case ACTION_UPDATE_TAB_BAR:
|
|
188
|
-
|
|
221
|
+
updateTabBarStyle(options.getBundle(ARG_OPTIONS));
|
|
189
222
|
break;
|
|
190
223
|
}
|
|
191
224
|
}
|
|
192
|
-
|
|
193
|
-
private void setTabItem(@Nullable ArrayList<Bundle>
|
|
194
|
-
if (
|
|
225
|
+
|
|
226
|
+
private void setTabItem(@Nullable ArrayList<Bundle> tabItems) {
|
|
227
|
+
if (tabItems == null) {
|
|
195
228
|
return;
|
|
196
229
|
}
|
|
197
|
-
|
|
198
|
-
Bundle
|
|
199
|
-
ArrayList<Bundle> tabs = tabBar.getParcelableArrayList("tabs");
|
|
200
|
-
|
|
230
|
+
Bundle options = tabBarFragment.getOptions();
|
|
231
|
+
ArrayList<Bundle> tabs = options.getParcelableArrayList("tabs");
|
|
201
232
|
if (tabs == null) {
|
|
202
233
|
return;
|
|
203
234
|
}
|
|
204
235
|
|
|
205
|
-
for (Bundle
|
|
206
|
-
int index = (int)
|
|
236
|
+
for (Bundle tabItem : tabItems) {
|
|
237
|
+
int index = (int) tabItem.getDouble("index");
|
|
207
238
|
Bundle tab = tabs.get(index);
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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"));
|
|
224
|
-
}
|
|
225
|
-
|
|
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);
|
|
235
|
-
}
|
|
239
|
+
buildTabTitle(tabItem, tab);
|
|
240
|
+
buildTabIcon(tabItem, tab);
|
|
241
|
+
buildTabBadge(tabItem, tab);
|
|
242
|
+
}
|
|
243
|
+
reactRootView.setAppProperties(createProps(options));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private void buildTabBadge(Bundle tabItem, Bundle tab) {
|
|
247
|
+
Bundle badge = tabItem.getBundle("badge");
|
|
248
|
+
if (badge == null) {
|
|
249
|
+
return;
|
|
236
250
|
}
|
|
251
|
+
boolean hidden = badge.getBoolean("hidden", true);
|
|
252
|
+
String text = !hidden ? badge.getString("text", "") : "";
|
|
253
|
+
boolean dot = !hidden && badge.getBoolean("dot", false);
|
|
237
254
|
|
|
238
|
-
|
|
255
|
+
tab.putString("badgeText", text);
|
|
256
|
+
tab.putBoolean("dot", dot);
|
|
239
257
|
}
|
|
240
|
-
|
|
241
|
-
private void
|
|
258
|
+
|
|
259
|
+
private void buildTabIcon(Bundle tabItem, Bundle tab) {
|
|
260
|
+
Bundle icon = tabItem.getBundle("icon");
|
|
261
|
+
if (icon == null) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
Bundle unselected = icon.getBundle("unselected");
|
|
265
|
+
Bundle selected = icon.getBundle("selected");
|
|
266
|
+
if (unselected != null) {
|
|
267
|
+
tab.putString("unselectedIcon", unselected.getString("uri"));
|
|
268
|
+
}
|
|
269
|
+
tab.putString("icon", selected.getString("uri"));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private void buildTabTitle(Bundle titleItem, Bundle tab) {
|
|
273
|
+
String title = titleItem.getString("title");
|
|
274
|
+
if (title != null) {
|
|
275
|
+
tab.putString("title", title);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private void updateTabBarStyle(@Nullable Bundle bundle) {
|
|
242
280
|
if (bundle == null) {
|
|
243
281
|
return;
|
|
244
282
|
}
|
|
@@ -266,16 +304,9 @@ public class ReactTabBarProvider implements TabBarProvider, ReactBridgeManager.R
|
|
|
266
304
|
if (tabBarItemColor != null) {
|
|
267
305
|
options.putString("tabBarItemColor", tabBarItemColor);
|
|
268
306
|
options.putString("tabBarUnselectedItemColor", tabBarUnselectedItemColor);
|
|
269
|
-
Bundle props =
|
|
307
|
+
Bundle props = createProps(options);
|
|
270
308
|
reactRootView.setAppProperties(props);
|
|
271
309
|
}
|
|
272
310
|
}
|
|
273
311
|
|
|
274
|
-
private final ReactBridgeManager bridgeManager = ReactBridgeManager.get();
|
|
275
|
-
|
|
276
|
-
@NonNull
|
|
277
|
-
public ReactBridgeManager getReactBridgeManager() {
|
|
278
|
-
return bridgeManager;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
312
|
}
|