/
ExpoModuleRegistryAdapter.java
93 lines (73 loc) · 5.03 KB
/
ExpoModuleRegistryAdapter.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package versioned.host.exp.exponent.modules.universal;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import org.json.JSONObject;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.ModuleRegistry;
import org.unimodules.core.interfaces.InternalModule;
import org.unimodules.core.interfaces.RegistryLifecycleListener;
import java.util.List;
import java.util.Map;
import host.exp.exponent.kernel.ExperienceId;
import host.exp.exponent.utils.ScopedContext;
import versioned.host.exp.exponent.modules.universal.av.SharedCookiesDataSourceFactoryProvider;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedAccelerometerService;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedGravitySensorService;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedGyroscopeService;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedLinearAccelerationSensorService;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedMagnetometerService;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedMagnetometerUncalibratedService;
import versioned.host.exp.exponent.modules.universal.sensors.ScopedRotationVectorSensorService;
public class ExpoModuleRegistryAdapter extends ModuleRegistryAdapter implements ScopedModuleRegistryAdapter {
public ExpoModuleRegistryAdapter(ReactModuleRegistryProvider moduleRegistryProvider) {
super(moduleRegistryProvider);
}
public List<NativeModule> createNativeModules(ScopedContext scopedContext, ExperienceId experienceId, Map<String, Object> experienceProperties, JSONObject manifest, List<NativeModule> otherModules) {
ModuleRegistry moduleRegistry = mModuleRegistryProvider.get(scopedContext);
// Overriding sensor services from expo-sensors for scoped implementations using kernel services
moduleRegistry.registerInternalModule(new ScopedAccelerometerService(experienceId));
moduleRegistry.registerInternalModule(new ScopedGravitySensorService(experienceId));
moduleRegistry.registerInternalModule(new ScopedGyroscopeService(experienceId));
moduleRegistry.registerInternalModule(new ScopedLinearAccelerationSensorService(experienceId));
moduleRegistry.registerInternalModule(new ScopedMagnetometerService(experienceId));
moduleRegistry.registerInternalModule(new ScopedMagnetometerUncalibratedService(experienceId));
moduleRegistry.registerInternalModule(new ScopedRotationVectorSensorService(experienceId));
moduleRegistry.registerInternalModule(new SharedCookiesDataSourceFactoryProvider());
// Overriding expo-constants/ConstantsService -- binding provides manifest and other expo-related constants
moduleRegistry.registerInternalModule(new ConstantsBinding(scopedContext, experienceProperties, manifest));
// Overriding expo-file-system FilePermissionModule
moduleRegistry.registerInternalModule(new ScopedFilePermissionModule(scopedContext));
// Overriding expo-file-system FileSystemModule
moduleRegistry.registerExportedModule(new ScopedFileSystemModule(scopedContext));
// Overriding expo-error-recovery ErrorRecoveryModule
moduleRegistry.registerExportedModule(new ScopedErrorRecoveryModule(scopedContext, manifest, experienceId));
// Overriding expo-permissions ScopedPermissionsService
moduleRegistry.registerInternalModule(new ScopedPermissionsService(scopedContext, experienceId));
// Overriding expo-facebook
moduleRegistry.registerExportedModule(new ScopedFacebookModule(scopedContext, manifest));
// Scoping Amplitude
moduleRegistry.registerExportedModule(new ScopedAmplitudeModule(scopedContext, experienceId));
// Overriding expo-firebase-core
moduleRegistry.registerInternalModule(new ScopedFirebaseCoreService(scopedContext, manifest, experienceId));
// ReactAdapterPackage requires ReactContext
ReactApplicationContext reactContext = (ReactApplicationContext) scopedContext.getContext();
for (InternalModule internalModule : mReactAdapterPackage.createInternalModules(reactContext)) {
moduleRegistry.registerInternalModule(internalModule);
}
// Overriding ScopedUIManagerModuleWrapper from ReactAdapterPackage
moduleRegistry.registerInternalModule(new ScopedUIManagerModuleWrapper(reactContext));
// Adding other modules (not universal) to module registry as consumers.
// It allows these modules to refer to universal modules.
for (NativeModule otherModule : otherModules) {
if (otherModule instanceof RegistryLifecycleListener) {
moduleRegistry.registerExtraListener((RegistryLifecycleListener) otherModule);
}
}
return getNativeModulesFromModuleRegistry(reactContext, moduleRegistry);
}
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
throw new RuntimeException("Use createNativeModules(ReactApplicationContext, ExperienceId, JSONObject, List<NativeModule>) to get a list of native modules.");
}
}