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.
- 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/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 -92
- 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/lib/Navigator.js +0 -1
- package/lib/ReactRegistry.d.ts +3 -3
- package/lib/typing.d.ts +1 -2
- package/package.json +24 -16
- package/src/DeepLink.ts +60 -0
- package/src/Garden.ts +171 -0
- package/src/NavigationModule.ts +33 -0
- package/src/Navigator.ts +403 -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 -429
- 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 -81
- 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
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java
CHANGED
|
@@ -43,59 +43,76 @@ public class StackNavigator implements Navigator {
|
|
|
43
43
|
@Override
|
|
44
44
|
@Nullable
|
|
45
45
|
public AwesomeFragment createFragment(@NonNull ReadableMap layout) {
|
|
46
|
-
if (layout.hasKey(name())) {
|
|
47
|
-
|
|
48
|
-
if (stack == null) {
|
|
49
|
-
throw new IllegalArgumentException("stack should be an object.");
|
|
50
|
-
}
|
|
51
|
-
ReadableArray children = stack.getArray("children");
|
|
52
|
-
if (children == null) {
|
|
53
|
-
throw new IllegalArgumentException("children is required, and it is an array.");
|
|
54
|
-
}
|
|
55
|
-
ReadableMap root = children.getMap(0);
|
|
56
|
-
AwesomeFragment rootFragment = getReactBridgeManager().createFragment(root);
|
|
57
|
-
if (rootFragment != null) {
|
|
58
|
-
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
59
|
-
stackFragment.setRootFragment(rootFragment);
|
|
60
|
-
return stackFragment;
|
|
61
|
-
} else {
|
|
62
|
-
throw new IllegalArgumentException("can't create stack component with " + layout);
|
|
63
|
-
}
|
|
46
|
+
if (!layout.hasKey(name())) {
|
|
47
|
+
return null;
|
|
64
48
|
}
|
|
65
|
-
|
|
49
|
+
|
|
50
|
+
ReadableMap stack = layout.getMap(name());
|
|
51
|
+
if (stack == null) {
|
|
52
|
+
throw new IllegalArgumentException("stack should be an object.");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ReadableArray children = stack.getArray("children");
|
|
56
|
+
if (children == null) {
|
|
57
|
+
throw new IllegalArgumentException("children is required, and it is an array.");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ReadableMap root = children.getMap(0);
|
|
61
|
+
AwesomeFragment rootFragment = getReactBridgeManager().createFragment(root);
|
|
62
|
+
if (rootFragment == null) {
|
|
63
|
+
throw new IllegalArgumentException("can't create stack component with " + layout);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
67
|
+
stackFragment.setRootFragment(rootFragment);
|
|
68
|
+
return stackFragment;
|
|
66
69
|
}
|
|
67
70
|
|
|
68
71
|
@Nullable
|
|
69
72
|
@Override
|
|
70
73
|
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
71
|
-
if (fragment instanceof StackFragment
|
|
72
|
-
|
|
73
|
-
ArrayList<Bundle> children = new ArrayList<>();
|
|
74
|
-
List<AwesomeFragment> fragments = stack.getChildFragments();
|
|
75
|
-
for (int i = 0; i < fragments.size(); i++) {
|
|
76
|
-
AwesomeFragment child = fragments.get(i);
|
|
77
|
-
Bundle r = getReactBridgeManager().buildRouteGraph(child);
|
|
78
|
-
if (r != null) {
|
|
79
|
-
children.add(r);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
Bundle graph = new Bundle();
|
|
83
|
-
graph.putString("layout", name());
|
|
84
|
-
graph.putString("sceneId", stack.getSceneId());
|
|
85
|
-
graph.putParcelableArrayList("children", children);
|
|
86
|
-
graph.putString("mode", Navigator.Util.getMode(fragment));
|
|
87
|
-
return graph;
|
|
74
|
+
if (!(fragment instanceof StackFragment)) {
|
|
75
|
+
return null;
|
|
88
76
|
}
|
|
89
|
-
|
|
77
|
+
|
|
78
|
+
if (!fragment.isAdded()) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
StackFragment stack = (StackFragment) fragment;
|
|
83
|
+
ArrayList<Bundle> children = buildChildrenGraph(stack);
|
|
84
|
+
Bundle graph = new Bundle();
|
|
85
|
+
graph.putString("layout", name());
|
|
86
|
+
graph.putString("sceneId", stack.getSceneId());
|
|
87
|
+
graph.putParcelableArrayList("children", children);
|
|
88
|
+
graph.putString("mode", Navigator.Util.getMode(fragment));
|
|
89
|
+
return graph;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
@NonNull
|
|
93
|
+
private ArrayList<Bundle> buildChildrenGraph(StackFragment stack) {
|
|
94
|
+
ArrayList<Bundle> children = new ArrayList<>();
|
|
95
|
+
List<AwesomeFragment> fragments = stack.getChildFragments();
|
|
96
|
+
for (int i = 0; i < fragments.size(); i++) {
|
|
97
|
+
AwesomeFragment child = fragments.get(i);
|
|
98
|
+
Bundle graph = getReactBridgeManager().buildRouteGraph(child);
|
|
99
|
+
if (graph != null) {
|
|
100
|
+
children.add(graph);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return children;
|
|
104
|
+
}
|
|
105
|
+
|
|
92
106
|
@Override
|
|
93
107
|
public HybridFragment primaryFragment(@NonNull AwesomeFragment fragment) {
|
|
94
|
-
if (fragment instanceof StackFragment
|
|
95
|
-
|
|
96
|
-
return getReactBridgeManager().primaryFragment(stack.getTopFragment());
|
|
108
|
+
if (!(fragment instanceof StackFragment)) {
|
|
109
|
+
return null;
|
|
97
110
|
}
|
|
98
|
-
|
|
111
|
+
if (!fragment.isAdded()) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
StackFragment stack = (StackFragment) fragment;
|
|
115
|
+
return getReactBridgeManager().primaryFragment(stack.getTopFragment());
|
|
99
116
|
}
|
|
100
117
|
|
|
101
118
|
@Override
|
|
@@ -106,109 +123,162 @@ public class StackNavigator implements Navigator {
|
|
|
106
123
|
return;
|
|
107
124
|
}
|
|
108
125
|
|
|
109
|
-
AwesomeFragment fragment = null;
|
|
110
|
-
|
|
111
126
|
switch (action) {
|
|
112
127
|
case "push":
|
|
113
|
-
|
|
114
|
-
if (fragment != null) {
|
|
115
|
-
stackFragment.pushFragment(fragment, true, () -> promise.resolve(true));
|
|
116
|
-
} else {
|
|
117
|
-
promise.resolve(false);
|
|
118
|
-
}
|
|
128
|
+
handlePush(extras, promise, stackFragment);
|
|
119
129
|
break;
|
|
120
130
|
case "pop":
|
|
121
131
|
stackFragment.popFragment(true, () -> promise.resolve(true));
|
|
122
132
|
break;
|
|
123
133
|
case "popTo":
|
|
124
|
-
|
|
125
|
-
boolean inclusive = extras.getBoolean("inclusive");
|
|
126
|
-
FragmentManager fragmentManager = stackFragment.getChildFragmentManager();
|
|
127
|
-
int count = fragmentManager.getBackStackEntryCount();
|
|
128
|
-
for (int i = count - 1; i > -1; i--) {
|
|
129
|
-
FragmentManager.BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
|
|
130
|
-
if (!TextUtils.isEmpty(entry.getName())) {
|
|
131
|
-
Fragment f = fragmentManager.findFragmentByTag(entry.getName());
|
|
132
|
-
if (f instanceof HybridFragment) {
|
|
133
|
-
HybridFragment hybridFragment = (HybridFragment) f;
|
|
134
|
-
if (moduleName != null
|
|
135
|
-
&& (moduleName.equals(hybridFragment.getModuleName()) || moduleName.equals(hybridFragment.getSceneId()))) {
|
|
136
|
-
fragment = hybridFragment;
|
|
137
|
-
if (inclusive && i - 1 > -1) {
|
|
138
|
-
FragmentManager.BackStackEntry e = fragmentManager.getBackStackEntryAt(i - 1);
|
|
139
|
-
fragment = (AwesomeFragment) fragmentManager.findFragmentByTag(e.getName());
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (fragment != null) {
|
|
148
|
-
stackFragment.popToFragment(fragment, true, () -> promise.resolve(true));
|
|
149
|
-
} else {
|
|
150
|
-
promise.resolve(false);
|
|
151
|
-
}
|
|
134
|
+
handlePopTo(extras, promise, stackFragment);
|
|
152
135
|
break;
|
|
153
136
|
case "popToRoot":
|
|
154
137
|
stackFragment.popToRootFragment(true, () -> promise.resolve(true));
|
|
155
138
|
break;
|
|
156
139
|
case "redirectTo":
|
|
157
|
-
|
|
158
|
-
if (fragment != null) {
|
|
159
|
-
stackFragment.redirectToFragment(fragment, true, () -> promise.resolve(true), target);
|
|
160
|
-
} else {
|
|
161
|
-
promise.resolve(false);
|
|
162
|
-
}
|
|
140
|
+
handleRedirectTo(target, extras, promise, stackFragment);
|
|
163
141
|
break;
|
|
164
142
|
case "pushLayout":
|
|
165
|
-
|
|
166
|
-
fragment = getReactBridgeManager().createFragment(layout);
|
|
167
|
-
if (fragment != null) {
|
|
168
|
-
stackFragment.pushFragment(fragment, true, () -> promise.resolve(true));
|
|
169
|
-
} else {
|
|
170
|
-
promise.resolve(false);
|
|
171
|
-
}
|
|
143
|
+
handlePushLayout(extras, promise, stackFragment);
|
|
172
144
|
break;
|
|
173
145
|
}
|
|
174
146
|
}
|
|
175
147
|
|
|
176
|
-
private
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
148
|
+
private void handlePushLayout(@NonNull ReadableMap extras, @NonNull Promise promise, StackFragment stackFragment) {
|
|
149
|
+
ReadableMap layout = extras.getMap("layout");
|
|
150
|
+
AwesomeFragment fragment = getReactBridgeManager().createFragment(layout);
|
|
151
|
+
if (fragment == null) {
|
|
152
|
+
promise.resolve(false);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
stackFragment.pushFragment(fragment, true, () -> promise.resolve(true));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private void handleRedirectTo(@NonNull AwesomeFragment target, @NonNull ReadableMap extras, @NonNull Promise promise, StackFragment stackFragment) {
|
|
159
|
+
AwesomeFragment fragment = createFragmentWithExtras(extras);
|
|
160
|
+
if (fragment == null) {
|
|
161
|
+
promise.resolve(false);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
stackFragment.redirectToFragment(fragment, true, () -> promise.resolve(true), target);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private void handlePopTo(@NonNull ReadableMap extras, @NonNull Promise promise, StackFragment stackFragment) {
|
|
168
|
+
String moduleName = extras.getString("moduleName");
|
|
169
|
+
if (moduleName == null) {
|
|
170
|
+
promise.resolve(false);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
boolean inclusive = extras.getBoolean("inclusive");
|
|
175
|
+
FragmentManager fragmentManager = stackFragment.getChildFragmentManager();
|
|
176
|
+
AwesomeFragment fragment = findFragmentForPopTo(moduleName, inclusive, fragmentManager);
|
|
177
|
+
if (fragment == null) {
|
|
178
|
+
promise.resolve(false);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
stackFragment.popToFragment(fragment, true, () -> promise.resolve(true));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@Nullable
|
|
186
|
+
private AwesomeFragment findFragmentForPopTo(String moduleName, boolean inclusive, FragmentManager fragmentManager) {
|
|
187
|
+
int count = fragmentManager.getBackStackEntryCount();
|
|
188
|
+
for (int i = count - 1; i > -1; i--) {
|
|
189
|
+
FragmentManager.BackStackEntry entry = fragmentManager.getBackStackEntryAt(i);
|
|
190
|
+
if (TextUtils.isEmpty(entry.getName())) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Fragment fragment = fragmentManager.findFragmentByTag(entry.getName());
|
|
195
|
+
if (!(fragment instanceof HybridFragment)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
HybridFragment hybridFragment = (HybridFragment) fragment;
|
|
200
|
+
boolean match = moduleName.equals(hybridFragment.getModuleName()) || moduleName.equals(hybridFragment.getSceneId());
|
|
201
|
+
if (!match) {
|
|
202
|
+
continue;
|
|
190
203
|
}
|
|
204
|
+
|
|
205
|
+
if (inclusive && i - 1 > -1) {
|
|
206
|
+
FragmentManager.BackStackEntry e = fragmentManager.getBackStackEntryAt(i - 1);
|
|
207
|
+
return (AwesomeFragment) fragmentManager.findFragmentByTag(e.getName());
|
|
208
|
+
}
|
|
209
|
+
return hybridFragment;
|
|
191
210
|
}
|
|
192
|
-
|
|
211
|
+
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private void handlePush(@NonNull ReadableMap extras, @NonNull Promise promise, StackFragment stackFragment) {
|
|
216
|
+
AwesomeFragment fragment = createFragmentWithExtras(extras);
|
|
217
|
+
if (fragment == null) {
|
|
218
|
+
promise.resolve(false);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
stackFragment.pushFragment(fragment, true, () -> promise.resolve(true));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private AwesomeFragment createFragmentWithExtras(@NonNull ReadableMap extras) {
|
|
225
|
+
if (!extras.hasKey("moduleName")) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
String moduleName = extras.getString("moduleName");
|
|
230
|
+
if (moduleName == null) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
Bundle props = buildProps(extras);
|
|
235
|
+
Bundle options = buildOptions(extras);
|
|
236
|
+
return getReactBridgeManager().createFragment(moduleName, props, options);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
@Nullable
|
|
240
|
+
private Bundle buildOptions(@NonNull ReadableMap extras) {
|
|
241
|
+
if (!extras.hasKey("options")) {
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return Arguments.toBundle(extras.getMap("options"));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@Nullable
|
|
248
|
+
private Bundle buildProps(@NonNull ReadableMap extras) {
|
|
249
|
+
if (!extras.hasKey("props")) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
return Arguments.toBundle(extras.getMap("props"));
|
|
193
253
|
}
|
|
194
254
|
|
|
195
255
|
private StackFragment getStackFragment(AwesomeFragment fragment) {
|
|
196
|
-
if (fragment
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
stackFragment = tabBarFragment.getSelectedFragment().getStackFragment();
|
|
203
|
-
} else {
|
|
204
|
-
stackFragment = drawerFragment.getContentFragment().getStackFragment();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
256
|
+
if (fragment == null) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
StackFragment stackFragment = fragment.getStackFragment();
|
|
261
|
+
if (stackFragment != null) {
|
|
207
262
|
return stackFragment;
|
|
208
263
|
}
|
|
209
|
-
|
|
264
|
+
|
|
265
|
+
return stackFragmentFromDrawerIfExist(fragment);
|
|
210
266
|
}
|
|
211
267
|
|
|
268
|
+
@Nullable
|
|
269
|
+
private StackFragment stackFragmentFromDrawerIfExist(AwesomeFragment fragment) {
|
|
270
|
+
DrawerFragment drawerFragment = fragment.getDrawerFragment();
|
|
271
|
+
if (drawerFragment == null) {
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
TabBarFragment tabBarFragment = drawerFragment.getContentFragment().getTabBarFragment();
|
|
276
|
+
if (tabBarFragment != null) {
|
|
277
|
+
return tabBarFragment.getSelectedFragment().getStackFragment();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return drawerFragment.getContentFragment().getStackFragment();
|
|
281
|
+
}
|
|
212
282
|
|
|
213
283
|
private ReactBridgeManager getReactBridgeManager() {
|
|
214
284
|
return ReactBridgeManager.get();
|
|
@@ -40,96 +40,121 @@ public class TabNavigator implements Navigator {
|
|
|
40
40
|
@Override
|
|
41
41
|
@Nullable
|
|
42
42
|
public AwesomeFragment createFragment(@NonNull ReadableMap layout) {
|
|
43
|
-
if (layout.hasKey(name())) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
throw new IllegalArgumentException("tabs should be an object");
|
|
47
|
-
}
|
|
48
|
-
ReadableArray children = tabs.getArray("children");
|
|
43
|
+
if (!layout.hasKey(name())) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
ReadableMap tabs = layout.getMap(name());
|
|
48
|
+
if (tabs == null) {
|
|
49
|
+
throw new IllegalArgumentException("tabs should be an object");
|
|
50
|
+
}
|
|
53
51
|
|
|
54
|
-
|
|
52
|
+
ReadableArray children = tabs.getArray("children");
|
|
53
|
+
if (children == null) {
|
|
54
|
+
throw new IllegalArgumentException("children is required and it is an array");
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
List<AwesomeFragment> fragments = createChildrenFragment(children);
|
|
58
|
+
|
|
59
|
+
if (fragments.size() == 0) {
|
|
60
|
+
throw new IllegalArgumentException("tabs layout should has a child at least");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ReactTabBarFragment tabBarFragment = new ReactTabBarFragment();
|
|
64
|
+
tabBarFragment.setChildFragments(fragments);
|
|
65
|
+
if (tabs.hasKey("options")) {
|
|
66
|
+
setTabsOptions(tabs, tabBarFragment);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return tabBarFragment;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private void setTabsOptions(ReadableMap tabs, ReactTabBarFragment tabBarFragment) {
|
|
73
|
+
ReadableMap options = tabs.getMap("options");
|
|
74
|
+
if (options == null) {
|
|
75
|
+
throw new IllegalArgumentException("options should be an object");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Bundle bundle = new Bundle();
|
|
79
|
+
if (options.hasKey("selectedIndex")) {
|
|
80
|
+
int selectedIndex = options.getInt("selectedIndex");
|
|
81
|
+
tabBarFragment.setSelectedIndex(selectedIndex);
|
|
82
|
+
bundle.putInt("selectedIndex", selectedIndex);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (options.hasKey("tabBarModuleName")) {
|
|
86
|
+
String tabBarModuleName = options.getString("tabBarModuleName");
|
|
87
|
+
bundle.putString("tabBarModuleName", tabBarModuleName);
|
|
88
|
+
tabBarFragment.setTabBarProvider(new ReactTabBarProvider());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (options.hasKey("sizeIndeterminate")) {
|
|
92
|
+
boolean sizeIndeterminate = options.getBoolean("sizeIndeterminate");
|
|
93
|
+
bundle.putBoolean("sizeIndeterminate", sizeIndeterminate);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
tabBarFragment.setOptions(bundle);
|
|
97
|
+
}
|
|
63
98
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (options.hasKey("selectedIndex")) {
|
|
75
|
-
int selectedIndex = options.getInt("selectedIndex");
|
|
76
|
-
tabBarFragment.setSelectedIndex(selectedIndex);
|
|
77
|
-
bundle.putInt("selectedIndex", selectedIndex);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (options.hasKey("tabBarModuleName")) {
|
|
81
|
-
String tabBarModuleName = options.getString("tabBarModuleName");
|
|
82
|
-
bundle.putString("tabBarModuleName", tabBarModuleName);
|
|
83
|
-
tabBarFragment.setTabBarProvider(new ReactTabBarProvider());
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (options.hasKey("sizeIndeterminate")) {
|
|
87
|
-
boolean sizeIndeterminate = options.getBoolean("sizeIndeterminate");
|
|
88
|
-
bundle.putBoolean("sizeIndeterminate", sizeIndeterminate);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
tabBarFragment.setOptions(bundle);
|
|
93
|
-
return tabBarFragment;
|
|
94
|
-
} else {
|
|
95
|
-
throw new IllegalArgumentException("tabs layout should has a child at least");
|
|
99
|
+
@NonNull
|
|
100
|
+
private List<AwesomeFragment> createChildrenFragment(ReadableArray children) {
|
|
101
|
+
List<AwesomeFragment> fragments = new ArrayList<>();
|
|
102
|
+
for (int i = 0, size = children.size(); i < size; i++) {
|
|
103
|
+
ReadableMap child = children.getMap(i);
|
|
104
|
+
AwesomeFragment awesomeFragment = getReactBridgeManager().createFragment(child);
|
|
105
|
+
if (awesomeFragment != null) {
|
|
106
|
+
fragments.add(awesomeFragment);
|
|
96
107
|
}
|
|
97
108
|
}
|
|
98
|
-
return
|
|
109
|
+
return fragments;
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
@Nullable
|
|
102
113
|
@Override
|
|
103
114
|
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
104
|
-
if (fragment instanceof TabBarFragment
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
if (!(fragment instanceof TabBarFragment)) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (!fragment.isAdded()) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
TabBarFragment tabs = (TabBarFragment) fragment;
|
|
123
|
+
ArrayList<Bundle> children = buildChildrenGraph(tabs);
|
|
124
|
+
Bundle graph = new Bundle();
|
|
125
|
+
graph.putString("layout", name());
|
|
126
|
+
graph.putString("sceneId", fragment.getSceneId());
|
|
127
|
+
graph.putParcelableArrayList("children", children);
|
|
128
|
+
graph.putString("mode", Navigator.Util.getMode(fragment));
|
|
129
|
+
graph.putInt("selectedIndex", tabs.getSelectedIndex());
|
|
130
|
+
return graph;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@NonNull
|
|
134
|
+
private ArrayList<Bundle> buildChildrenGraph(TabBarFragment tabs) {
|
|
135
|
+
ArrayList<Bundle> children = new ArrayList<>();
|
|
136
|
+
List<AwesomeFragment> fragments = tabs.getChildFragments();
|
|
137
|
+
for (int i = 0; i < fragments.size(); i++) {
|
|
138
|
+
AwesomeFragment child = fragments.get(i);
|
|
139
|
+
Bundle graph = getReactBridgeManager().buildRouteGraph(child);
|
|
140
|
+
if (graph != null) {
|
|
141
|
+
children.add(graph);
|
|
114
142
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
graph.putString("sceneId", fragment.getSceneId());
|
|
118
|
-
graph.putParcelableArrayList("children", children);
|
|
119
|
-
graph.putString("mode", Navigator.Util.getMode(fragment));
|
|
120
|
-
graph.putInt("selectedIndex", tabs.getSelectedIndex());
|
|
121
|
-
return graph;
|
|
122
|
-
}
|
|
123
|
-
return null;
|
|
143
|
+
}
|
|
144
|
+
return children;
|
|
124
145
|
}
|
|
125
146
|
|
|
126
147
|
@Override
|
|
127
148
|
public HybridFragment primaryFragment(@NonNull AwesomeFragment fragment) {
|
|
128
|
-
if (fragment instanceof TabBarFragment
|
|
129
|
-
|
|
130
|
-
return getReactBridgeManager().primaryFragment(tabs.getSelectedFragment());
|
|
149
|
+
if (!(fragment instanceof TabBarFragment)) {
|
|
150
|
+
return null;
|
|
131
151
|
}
|
|
132
|
-
|
|
152
|
+
if (!fragment.isAdded()) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
TabBarFragment tabs = (TabBarFragment) fragment;
|
|
157
|
+
return getReactBridgeManager().primaryFragment(tabs.getSelectedFragment());
|
|
133
158
|
}
|
|
134
159
|
|
|
135
160
|
@Override
|
|
@@ -141,31 +166,47 @@ public class TabNavigator implements Navigator {
|
|
|
141
166
|
}
|
|
142
167
|
|
|
143
168
|
if ("switchTab".equals(action)) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (from == to) {
|
|
148
|
-
promise.resolve(true);
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
169
|
+
handleSwitchTab(extras, promise, tabBarFragment);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
152
172
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
173
|
+
private void handleSwitchTab(@NonNull ReadableMap extras, @NonNull Promise promise, TabBarFragment tabBarFragment) {
|
|
174
|
+
int to = extras.getInt("to");
|
|
175
|
+
if (isSameTab(to, extras)) {
|
|
176
|
+
promise.resolve(true);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
160
179
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
180
|
+
popToStackRootIfNeeded(extras, tabBarFragment);
|
|
181
|
+
|
|
182
|
+
if (!(tabBarFragment instanceof ReactTabBarFragment)) {
|
|
183
|
+
tabBarFragment.setSelectedIndex(to, () -> promise.resolve(true));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
ReactTabBarFragment reactTabBarFragment = (ReactTabBarFragment) tabBarFragment;
|
|
188
|
+
reactTabBarFragment.setIntercepted(false);
|
|
189
|
+
reactTabBarFragment.setSelectedIndex(to, () -> promise.resolve(true));
|
|
190
|
+
reactTabBarFragment.setIntercepted(true);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
private boolean isSameTab(int to, @NonNull ReadableMap extras) {
|
|
194
|
+
if (!extras.hasKey("from")) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
int from = extras.getInt("from");
|
|
198
|
+
return from == to;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private void popToStackRootIfNeeded(@NonNull ReadableMap extras, TabBarFragment tabBarFragment) {
|
|
202
|
+
boolean popToRoot = extras.hasKey("popToRoot") && extras.getBoolean("popToRoot");
|
|
203
|
+
if (!popToRoot) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
StackFragment stackFragment = tabBarFragment.getSelectedFragment().getStackFragment();
|
|
208
|
+
if (stackFragment != null && stackFragment.getChildFragments().size() > 1) {
|
|
209
|
+
stackFragment.popToRootFragment(false);
|
|
169
210
|
}
|
|
170
211
|
}
|
|
171
212
|
|
|
@@ -451,6 +451,13 @@
|
|
|
451
451
|
modalViewController.contentViewController = vc;
|
|
452
452
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
453
453
|
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
454
|
+
NSString *screenColor = hbdvc.options[@"screenBackgroundColor"];
|
|
455
|
+
if (screenColor) {
|
|
456
|
+
UIColor *color = [HBDUtils colorWithHexString:screenColor];
|
|
457
|
+
if (colorHasAlphaComponent(color)) {
|
|
458
|
+
modalViewController.dimmingView.backgroundColor = color;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
454
461
|
if (hbdvc.forceTransparentDialogWindow) {
|
|
455
462
|
modalViewController.dimmingView.backgroundColor = UIColor.clearColor;
|
|
456
463
|
}
|
package/lib/Navigator.js
CHANGED
package/lib/ReactRegistry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentProvider } from 'react-native';
|
|
2
|
-
import React
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { Navigator } from './Navigator';
|
|
4
4
|
import { Garden } from './Garden';
|
|
5
5
|
import { RouteConfig } from './router';
|
|
@@ -10,11 +10,11 @@ export interface InjectedProps {
|
|
|
10
10
|
sceneId: string;
|
|
11
11
|
}
|
|
12
12
|
export declare const NavigationContext: React.Context<any>;
|
|
13
|
-
export declare type HOC = (WrappedComponent: ComponentType<any>) => ComponentType<any>;
|
|
13
|
+
export declare type HOC = (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
|
|
14
14
|
export declare class ReactRegistry {
|
|
15
15
|
static registerEnded: boolean;
|
|
16
16
|
static startRegisterComponent(hoc?: HOC): void;
|
|
17
17
|
static endRegisterComponent(): void;
|
|
18
18
|
static registerComponent(appKey: string, getComponentFunc: ComponentProvider, routeConfig?: RouteConfig): void;
|
|
19
19
|
}
|
|
20
|
-
export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: ComponentType<any>) => React.ComponentType<any>;
|
|
20
|
+
export declare function withNavigationItem(item: NavigationItem): (WrappedComponent: React.ComponentType<any>) => React.ComponentType<any>;
|