-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
NavigationReactNativeHost.java
71 lines (61 loc) · 2.69 KB
/
NavigationReactNativeHost.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.reactnativenavigation.react;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactInstanceManagerBuilder;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
import com.reactnativenavigation.NavigationApplication;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Default implementation of {@link ReactNativeHost} that includes {@link NavigationPackage}
* and user-defined additional packages.
*/
public abstract class NavigationReactNativeHost extends ReactNativeHost implements BundleDownloadListenerProvider {
private @Nullable NavigationDevBundleDownloadListener bundleListener;
private final DevBundleDownloadListener bundleListenerMediator = new DevBundleDownloadListenerAdapter() {
@Override
public void onSuccess() {
if (bundleListener != null) {
bundleListener.onSuccess();
}
}
};
@SuppressWarnings("WeakerAccess")
public NavigationReactNativeHost(NavigationApplication application) {
super(application);
}
@Override
public void setBundleLoaderListener(NavigationDevBundleDownloadListener listener) {
bundleListener = listener;
}
protected ReactInstanceManager createReactInstanceManager() {
ReactInstanceManagerBuilder builder = ReactInstanceManager.builder()
.setApplication(getApplication())
.setJSMainModulePath(getJSMainModuleName())
.setUseDeveloperSupport(getUseDeveloperSupport())
.setRedBoxHandler(getRedBoxHandler())
.setJavaScriptExecutorFactory(getJavaScriptExecutorFactory())
.setUIImplementationProvider(getUIImplementationProvider())
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE)
.setJSIModulesPackage(getJSIModulePackage())
.setDevBundleDownloadListener(getDevBundleDownloadListener());
for (ReactPackage reactPackage : getPackages()) {
builder.addPackage(reactPackage);
}
String jsBundleFile = getJSBundleFile();
if (jsBundleFile != null) {
builder.setJSBundleFile(jsBundleFile);
} else {
builder.setBundleAssetName(Assertions.assertNotNull(getBundleAssetName()));
}
return builder.build();
}
@SuppressWarnings("WeakerAccess")
@NonNull
protected DevBundleDownloadListener getDevBundleDownloadListener() {
return bundleListenerMediator;
}
}