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
|
@@ -17,6 +17,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
|
17
17
|
import com.facebook.react.bridge.ReactMethod;
|
|
18
18
|
import com.facebook.react.bridge.ReadableMap;
|
|
19
19
|
import com.facebook.react.bridge.UiThreadUtil;
|
|
20
|
+
import com.navigation.androidx.AwesomeActivity;
|
|
20
21
|
import com.navigation.androidx.AwesomeFragment;
|
|
21
22
|
import com.navigation.androidx.FragmentHelper;
|
|
22
23
|
import com.navigation.androidx.TabBarFragment;
|
|
@@ -35,38 +36,30 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
35
36
|
|
|
36
37
|
static final String TAG = "Navigator";
|
|
37
38
|
private final ReactBridgeManager bridgeManager;
|
|
38
|
-
|
|
39
|
+
|
|
39
40
|
NavigationModule(ReactApplicationContext reactContext, ReactBridgeManager bridgeManager) {
|
|
40
41
|
super(reactContext);
|
|
41
42
|
this.bridgeManager = bridgeManager;
|
|
42
43
|
FLog.i(TAG, "NavigationModule#onCreate");
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
|
|
45
46
|
@Override
|
|
46
47
|
public void onCatalystInstanceDestroy() {
|
|
47
48
|
super.onCatalystInstanceDestroy();
|
|
48
49
|
FLog.i(TAG, "NavigationModule#onCatalystInstanceDestroy");
|
|
49
50
|
UiThreadUtil.runOnUiThread(() -> {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
listener.onReload();
|
|
53
|
-
}
|
|
54
|
-
listeners.clear();
|
|
55
|
-
bridgeManager.setPendingLayout(null, 0);
|
|
56
|
-
bridgeManager.setReactModuleRegisterCompleted(false);
|
|
57
|
-
bridgeManager.setViewHierarchyReady(false);
|
|
58
|
-
|
|
59
|
-
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
60
|
-
if (reactContext != null) {
|
|
61
|
-
Activity activity = reactContext.getCurrentActivity();
|
|
62
|
-
if (activity instanceof ReactAppCompatActivity) {
|
|
63
|
-
ReactAppCompatActivity reactAppCompatActivity = (ReactAppCompatActivity) activity;
|
|
64
|
-
reactAppCompatActivity.clearFragments();
|
|
65
|
-
}
|
|
66
|
-
}
|
|
51
|
+
bridgeManager.handleReload();
|
|
52
|
+
clearFragments();
|
|
67
53
|
});
|
|
68
54
|
}
|
|
69
55
|
|
|
56
|
+
private void clearFragments() {
|
|
57
|
+
AwesomeActivity activity = getActiveActivity();
|
|
58
|
+
if (activity != null) {
|
|
59
|
+
activity.clearFragments();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
70
63
|
@NonNull
|
|
71
64
|
@Override
|
|
72
65
|
public String getName() {
|
|
@@ -120,16 +113,23 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
120
113
|
bridgeManager.setViewHierarchyReady(false);
|
|
121
114
|
bridgeManager.setRootLayout(layout, sticky);
|
|
122
115
|
bridgeManager.setPendingLayout(layout, tag);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
116
|
+
|
|
117
|
+
if (!bridgeManager.isReactModuleRegisterCompleted()) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
AwesomeFragment fragment = bridgeManager.createFragment(layout);
|
|
122
|
+
if (fragment == null) {
|
|
123
|
+
return;
|
|
132
124
|
}
|
|
125
|
+
|
|
126
|
+
ReactAppCompatActivity activity = getActiveActivity();
|
|
127
|
+
if (activity == null) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
FLog.i(TAG, "Have active Activity and React module was registered, set root Fragment immediately.");
|
|
132
|
+
activity.setActivityRootFragment(fragment, tag);
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -137,12 +137,18 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
137
137
|
public void dispatch(final String sceneId, final String action, final ReadableMap extras, Promise promise) {
|
|
138
138
|
UiThreadUtil.runOnUiThread(() -> {
|
|
139
139
|
AwesomeFragment target = findFragmentBySceneId(sceneId);
|
|
140
|
-
if (target
|
|
141
|
-
bridgeManager.handleNavigation(target, action, extras, promise);
|
|
142
|
-
} else {
|
|
140
|
+
if (target == null) {
|
|
143
141
|
promise.resolve(false);
|
|
144
142
|
FLog.w(TAG, "Can't find target scene for action:" + action + ", maybe the scene is gone.\nextras: " + extras);
|
|
143
|
+
return;
|
|
145
144
|
}
|
|
145
|
+
|
|
146
|
+
if (!target.isAdded()) {
|
|
147
|
+
promise.resolve(false);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
bridgeManager.handleNavigation(target, action, extras, promise);
|
|
146
152
|
});
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -150,14 +156,18 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
150
156
|
public void currentTab(final String sceneId, final Promise promise) {
|
|
151
157
|
UiThreadUtil.runOnUiThread(() -> {
|
|
152
158
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
153
|
-
if (fragment
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
if (fragment == null) {
|
|
160
|
+
promise.resolve(-1);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
TabBarFragment tabs = fragment.getTabBarFragment();
|
|
165
|
+
if (tabs == null) {
|
|
166
|
+
promise.resolve(-1);
|
|
167
|
+
return;
|
|
159
168
|
}
|
|
160
|
-
|
|
169
|
+
|
|
170
|
+
promise.resolve(tabs.getSelectedIndex());
|
|
161
171
|
});
|
|
162
172
|
}
|
|
163
173
|
|
|
@@ -165,9 +175,11 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
165
175
|
public void isStackRoot(final String sceneId, final Promise promise) {
|
|
166
176
|
UiThreadUtil.runOnUiThread(() -> {
|
|
167
177
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
168
|
-
if (fragment
|
|
169
|
-
promise.resolve(
|
|
178
|
+
if (fragment == null) {
|
|
179
|
+
promise.resolve(false);
|
|
180
|
+
return;
|
|
170
181
|
}
|
|
182
|
+
promise.resolve(fragment.isStackRoot());
|
|
171
183
|
});
|
|
172
184
|
}
|
|
173
185
|
|
|
@@ -175,67 +187,73 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
175
187
|
public void setResult(final String sceneId, final int resultCode, final ReadableMap result) {
|
|
176
188
|
UiThreadUtil.runOnUiThread(() -> {
|
|
177
189
|
AwesomeFragment fragment = findFragmentBySceneId(sceneId);
|
|
178
|
-
if (fragment
|
|
179
|
-
|
|
190
|
+
if (fragment == null) {
|
|
191
|
+
return;
|
|
180
192
|
}
|
|
193
|
+
fragment.setResult(resultCode, Arguments.toBundle(result));
|
|
181
194
|
});
|
|
182
195
|
}
|
|
183
196
|
|
|
184
197
|
@ReactMethod
|
|
185
198
|
public void findSceneIdByModuleName(@NonNull String moduleName, Promise promise) {
|
|
186
|
-
|
|
199
|
+
final Runnable task = new Runnable() {
|
|
187
200
|
@Override
|
|
188
201
|
public void run() {
|
|
189
|
-
|
|
190
|
-
if (
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
Activity activity = reactContext.getCurrentActivity();
|
|
195
|
-
if (!bridgeManager.isViewHierarchyReady() || !(activity instanceof ReactAppCompatActivity)) {
|
|
202
|
+
AwesomeActivity activity = getActiveActivity();
|
|
203
|
+
if (activity == null || !bridgeManager.isViewHierarchyReady()) {
|
|
196
204
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
197
205
|
return;
|
|
198
206
|
}
|
|
199
207
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
FragmentManager fragmentManager = reactAppCompatActivity.getSupportFragmentManager();
|
|
208
|
+
activity.scheduleTaskAtStarted(() -> {
|
|
209
|
+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
203
210
|
Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
|
|
204
|
-
if (fragment instanceof AwesomeFragment) {
|
|
205
|
-
String sceneId = findSceneIdByModuleName(moduleName, (AwesomeFragment) fragment);
|
|
206
|
-
FLog.i(TAG, "The sceneId found by " + moduleName + " : " + sceneId);
|
|
207
|
-
promise.resolve(sceneId);
|
|
208
|
-
} else {
|
|
211
|
+
if (!(fragment instanceof AwesomeFragment)) {
|
|
209
212
|
promise.resolve(null);
|
|
213
|
+
return;
|
|
210
214
|
}
|
|
215
|
+
|
|
216
|
+
String sceneId = findSceneIdByModuleName(moduleName, (AwesomeFragment) fragment);
|
|
217
|
+
FLog.i(TAG, "The sceneId found by " + moduleName + " : " + sceneId);
|
|
218
|
+
promise.resolve(sceneId);
|
|
211
219
|
});
|
|
212
220
|
}
|
|
213
221
|
};
|
|
214
|
-
|
|
222
|
+
|
|
215
223
|
UiThreadUtil.runOnUiThread(task);
|
|
216
224
|
}
|
|
217
225
|
|
|
218
|
-
private String findSceneIdByModuleName(@NonNull String moduleName, AwesomeFragment
|
|
219
|
-
String sceneId =
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
if (moduleName.equals(hybridFragment.getModuleName())) {
|
|
223
|
-
sceneId = hybridFragment.getSceneId();
|
|
224
|
-
}
|
|
226
|
+
private String findSceneIdByModuleName(@NonNull String moduleName, AwesomeFragment parent) {
|
|
227
|
+
String sceneId = findSceneIdFromParent(moduleName, parent);
|
|
228
|
+
if (sceneId == null) {
|
|
229
|
+
return findSceneIdFromChildren(moduleName, parent.getChildFragments());
|
|
225
230
|
}
|
|
231
|
+
return sceneId;
|
|
232
|
+
}
|
|
226
233
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
sceneId = findSceneIdByModuleName(moduleName, child);
|
|
234
|
-
index++;
|
|
234
|
+
private String findSceneIdFromChildren(@NonNull String moduleName, List<AwesomeFragment> children) {
|
|
235
|
+
for (int i = 0; i < children.size(); i++) {
|
|
236
|
+
AwesomeFragment child = children.get(i);
|
|
237
|
+
String sceneId = findSceneIdByModuleName(moduleName, child);
|
|
238
|
+
if (sceneId != null) {
|
|
239
|
+
return sceneId;
|
|
235
240
|
}
|
|
236
241
|
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
237
244
|
|
|
238
|
-
|
|
245
|
+
@Nullable
|
|
246
|
+
private String findSceneIdFromParent(@NonNull String moduleName, AwesomeFragment fragment) {
|
|
247
|
+
if (!(fragment instanceof HybridFragment)) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
HybridFragment hybridFragment = (HybridFragment) fragment;
|
|
252
|
+
if (!moduleName.equals(hybridFragment.getModuleName())) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return hybridFragment.getSceneId();
|
|
239
257
|
}
|
|
240
258
|
|
|
241
259
|
@ReactMethod
|
|
@@ -243,31 +261,25 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
243
261
|
Runnable task = new Runnable() {
|
|
244
262
|
@Override
|
|
245
263
|
public void run() {
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
Activity activity = reactContext.getCurrentActivity();
|
|
252
|
-
if (!bridgeManager.isViewHierarchyReady() || !(activity instanceof ReactAppCompatActivity)) {
|
|
264
|
+
AwesomeActivity activity = getActiveActivity();
|
|
265
|
+
if (activity == null || !bridgeManager.isViewHierarchyReady()) {
|
|
253
266
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
254
267
|
return;
|
|
255
268
|
}
|
|
256
|
-
|
|
257
|
-
ReactAppCompatActivity reactAppCompatActivity = (ReactAppCompatActivity) activity;
|
|
258
|
-
reactAppCompatActivity.scheduleTaskAtStarted(() -> {
|
|
259
|
-
FragmentManager fragmentManager = reactAppCompatActivity.getSupportFragmentManager();
|
|
260
|
-
HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
|
|
261
269
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
267
|
-
promise.resolve(Arguments.fromBundle(bundle));
|
|
268
|
-
} else {
|
|
270
|
+
activity.scheduleTaskAtStarted(() -> {
|
|
271
|
+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
272
|
+
HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
|
|
273
|
+
if (current == null) {
|
|
269
274
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
275
|
+
return;
|
|
270
276
|
}
|
|
277
|
+
|
|
278
|
+
Bundle bundle = new Bundle();
|
|
279
|
+
bundle.putString("moduleName", current.getModuleName());
|
|
280
|
+
bundle.putString("sceneId", current.getSceneId());
|
|
281
|
+
bundle.putString("mode", Navigator.Util.getMode(current));
|
|
282
|
+
promise.resolve(Arguments.fromBundle(bundle));
|
|
271
283
|
});
|
|
272
284
|
}
|
|
273
285
|
};
|
|
@@ -280,26 +292,21 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
280
292
|
Runnable task = new Runnable() {
|
|
281
293
|
@Override
|
|
282
294
|
public void run() {
|
|
283
|
-
|
|
284
|
-
if (
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
Activity activity = reactContext.getCurrentActivity();
|
|
289
|
-
if (!bridgeManager.isViewHierarchyReady() || !(activity instanceof ReactAppCompatActivity)) {
|
|
295
|
+
AwesomeActivity activity = getActiveActivity();
|
|
296
|
+
if (activity == null || !bridgeManager.isViewHierarchyReady()) {
|
|
290
297
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
291
298
|
return;
|
|
292
299
|
}
|
|
293
300
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
FragmentManager fragmentManager = reactAppCompatActivity.getSupportFragmentManager();
|
|
301
|
+
activity.scheduleTaskAtStarted(() -> {
|
|
302
|
+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
297
303
|
ArrayList<Bundle> graph = bridgeManager.buildRouteGraph(fragmentManager);
|
|
298
|
-
if (graph.size()
|
|
299
|
-
promise.resolve(Arguments.fromList(graph));
|
|
300
|
-
} else {
|
|
304
|
+
if (graph.size() == 0) {
|
|
301
305
|
UiThreadUtil.runOnUiThread(this, 16);
|
|
306
|
+
return;
|
|
302
307
|
}
|
|
308
|
+
|
|
309
|
+
promise.resolve(Arguments.fromList(graph));
|
|
303
310
|
});
|
|
304
311
|
}
|
|
305
312
|
};
|
|
@@ -308,22 +315,32 @@ public class NavigationModule extends ReactContextBaseJavaModule {
|
|
|
308
315
|
}
|
|
309
316
|
|
|
310
317
|
private AwesomeFragment findFragmentBySceneId(String sceneId) {
|
|
311
|
-
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
312
|
-
if (reactContext == null) {
|
|
313
|
-
return null;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
318
|
if (!bridgeManager.isViewHierarchyReady()) {
|
|
317
319
|
FLog.w(TAG, "View hierarchy is not ready now.");
|
|
318
320
|
return null;
|
|
319
321
|
}
|
|
320
322
|
|
|
323
|
+
ReactAppCompatActivity activity = getActiveActivity();
|
|
324
|
+
if (activity == null) {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
|
329
|
+
return FragmentHelper.findAwesomeFragment(fragmentManager, sceneId);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
@Nullable
|
|
333
|
+
private ReactAppCompatActivity getActiveActivity() {
|
|
334
|
+
ReactContext reactContext = getReactApplicationContextIfActiveOrWarn();
|
|
335
|
+
if (reactContext == null) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
|
|
321
339
|
Activity activity = reactContext.getCurrentActivity();
|
|
322
|
-
if (activity instanceof ReactAppCompatActivity) {
|
|
323
|
-
|
|
324
|
-
FragmentManager fragmentManager = reactAppCompatActivity.getSupportFragmentManager();
|
|
325
|
-
return FragmentHelper.findAwesomeFragment(fragmentManager, sceneId);
|
|
340
|
+
if (!(activity instanceof ReactAppCompatActivity)) {
|
|
341
|
+
return null;
|
|
326
342
|
}
|
|
327
|
-
|
|
343
|
+
|
|
344
|
+
return (ReactAppCompatActivity) activity;
|
|
328
345
|
}
|
|
329
346
|
}
|
|
@@ -46,14 +46,21 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
46
46
|
activityDelegate.onCreate(savedInstanceState);
|
|
47
47
|
getReactBridgeManager().addReactModuleRegisterListener(this);
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
ensureViewHierarchy(savedInstanceState);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private void ensureViewHierarchy(Bundle savedInstanceState) {
|
|
53
|
+
if (!isReactModuleRegisterCompleted()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (savedInstanceState == null) {
|
|
58
|
+
createMainComponent();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (getSupportFragmentManager().getFragments().size() > 0) {
|
|
63
|
+
getReactBridgeManager().setViewHierarchyReady(true);
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
@@ -99,24 +106,34 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
99
106
|
ReactStackFragment stackFragment = new ReactStackFragment();
|
|
100
107
|
stackFragment.setRootFragment(fragment);
|
|
101
108
|
setActivityRootFragment(stackFragment);
|
|
102
|
-
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (bridgeManager.hasPendingLayout()) {
|
|
103
113
|
FLog.i(TAG, "Set root Fragment from pending layout when create main component");
|
|
104
114
|
setActivityRootFragment(bridgeManager);
|
|
105
|
-
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (bridgeManager.hasStickyLayout()) {
|
|
106
119
|
FLog.i(TAG, "Set root Fragment from sticky layout when create main component");
|
|
107
120
|
AwesomeFragment fragment = bridgeManager.createFragment(bridgeManager.getStickyLayout());
|
|
108
121
|
if (fragment != null) {
|
|
109
122
|
setActivityRootFragment(fragment);
|
|
110
123
|
}
|
|
111
|
-
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (bridgeManager.hasRootLayout()) {
|
|
112
128
|
FLog.i(TAG, "Set root Fragment from last root layout when create main component");
|
|
113
129
|
AwesomeFragment fragment = bridgeManager.createFragment(bridgeManager.getRootLayout());
|
|
114
130
|
if (fragment != null) {
|
|
115
131
|
setActivityRootFragment(fragment);
|
|
116
132
|
}
|
|
117
|
-
|
|
118
|
-
FLog.w(TAG, "No layout to set when create main component");
|
|
133
|
+
return;
|
|
119
134
|
}
|
|
135
|
+
|
|
136
|
+
FLog.w(TAG, "No layout to set when create main component");
|
|
120
137
|
}
|
|
121
138
|
|
|
122
139
|
protected String getMainComponentName() {
|
|
@@ -131,26 +148,31 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
131
148
|
private void setActivityRootFragment(ReactBridgeManager bridgeManager) {
|
|
132
149
|
int pendingTag = bridgeManager.getPendingTag();
|
|
133
150
|
ReadableMap pendingLayout = bridgeManager.getPendingLayout();
|
|
134
|
-
if (pendingTag
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
151
|
+
if (pendingTag == 0 || pendingLayout == null) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
AwesomeFragment fragment = bridgeManager.createFragment(pendingLayout);
|
|
156
|
+
if (fragment == null) {
|
|
157
|
+
FLog.e(TAG, "Could not create fragment from pending layout.");
|
|
158
|
+
return;
|
|
141
159
|
}
|
|
160
|
+
setActivityRootFragment(fragment, pendingTag);
|
|
142
161
|
}
|
|
143
162
|
|
|
144
|
-
|
|
163
|
+
protected void setActivityRootFragment(@NonNull AwesomeFragment rootFragment, int tag) {
|
|
164
|
+
if (isFinishing()) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
145
168
|
if (getSupportFragmentManager().isStateSaved()) {
|
|
146
169
|
FLog.i(TAG, "Schedule to set Activity root Fragment.");
|
|
147
170
|
scheduleTaskAtStarted(() -> setActivityRootFragmentSync(rootFragment, tag));
|
|
148
|
-
|
|
149
|
-
if (!isFinishing()) {
|
|
150
|
-
FLog.i(TAG, "Set Activity root Fragment immediately.");
|
|
151
|
-
setActivityRootFragmentSync(rootFragment, tag);
|
|
152
|
-
}
|
|
171
|
+
return;
|
|
153
172
|
}
|
|
173
|
+
|
|
174
|
+
FLog.i(TAG, "Set Activity root Fragment immediately.");
|
|
175
|
+
setActivityRootFragmentSync(rootFragment, tag);
|
|
154
176
|
}
|
|
155
177
|
|
|
156
178
|
protected void setActivityRootFragmentSync(AwesomeFragment fragment, int tag) {
|
|
@@ -160,17 +182,25 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
160
182
|
throw new IllegalStateException("Style hasn't inflated yet. Did you forgot to call `Garden.setStyle` before `Navigator.setRoot` ?");
|
|
161
183
|
}
|
|
162
184
|
}
|
|
163
|
-
|
|
164
|
-
bridgeManager.setPendingLayout(null, 0);
|
|
185
|
+
|
|
165
186
|
ReactContext reactContext = getCurrentReactContext();
|
|
166
|
-
if (reactContext
|
|
167
|
-
|
|
168
|
-
setActivityRootFragmentSync(fragment);
|
|
169
|
-
bridgeManager.setViewHierarchyReady(true);
|
|
170
|
-
WritableMap map = Arguments.createMap();
|
|
171
|
-
map.putInt("tag", tag);
|
|
172
|
-
HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_DID_SET_ROOT, map);
|
|
187
|
+
if (reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
188
|
+
return;
|
|
173
189
|
}
|
|
190
|
+
|
|
191
|
+
// will
|
|
192
|
+
HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_WILL_SET_ROOT, Arguments.createMap());
|
|
193
|
+
|
|
194
|
+
// do
|
|
195
|
+
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
196
|
+
bridgeManager.setPendingLayout(null, 0);
|
|
197
|
+
setActivityRootFragmentSync(fragment);
|
|
198
|
+
bridgeManager.setViewHierarchyReady(true);
|
|
199
|
+
|
|
200
|
+
// did
|
|
201
|
+
WritableMap map = Arguments.createMap();
|
|
202
|
+
map.putInt("tag", tag);
|
|
203
|
+
HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_DID_SET_ROOT, map);
|
|
174
204
|
}
|
|
175
205
|
|
|
176
206
|
@Override
|
|
@@ -77,6 +77,8 @@ public class ReactBridgeManager {
|
|
|
77
77
|
pendingTag = 0;
|
|
78
78
|
stickyLayout = null;
|
|
79
79
|
pendingLayout = null;
|
|
80
|
+
reactBridgeReloadListeners.clear();
|
|
81
|
+
|
|
80
82
|
setViewHierarchyReady(false);
|
|
81
83
|
});
|
|
82
84
|
|
|
@@ -174,9 +176,18 @@ public class ReactBridgeManager {
|
|
|
174
176
|
public void removeReactBridgeReloadListener(@NonNull ReactBridgeReloadListener listener) {
|
|
175
177
|
reactBridgeReloadListeners.remove(listener);
|
|
176
178
|
}
|
|
177
|
-
|
|
178
|
-
public
|
|
179
|
-
|
|
179
|
+
|
|
180
|
+
public void handleReload() {
|
|
181
|
+
invokeReloadListeners();
|
|
182
|
+
setPendingLayout(null, 0);
|
|
183
|
+
setReactModuleRegisterCompleted(false);
|
|
184
|
+
setViewHierarchyReady(false);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private void invokeReloadListeners() {
|
|
188
|
+
for (ReactBridgeManager.ReactBridgeReloadListener listener : reactBridgeReloadListeners) {
|
|
189
|
+
listener.onReload();
|
|
190
|
+
}
|
|
180
191
|
}
|
|
181
192
|
|
|
182
193
|
public void setRootLayout(@NonNull ReadableMap root, boolean sticky) {
|