1// Copyright © 2018 650 Industries. All rights reserved. 2 3#import "EXScopedModuleRegistry.h" 4 5#import "EXScopedModuleRegistryAdapter.h" 6#import "EXSensorsManagerBinding.h" 7#import "EXConstantsBinding.h" 8#import "EXScopedFileSystemModule.h" 9#import "EXUnversioned.h" 10#import "EXScopedFilePermissionModule.h" 11#import "EXScopedFontLoader.h" 12#import "EXScopedSecureStore.h" 13#import "EXScopedAmplitude.h" 14#import "EXScopedPermissions.h" 15#import "EXScopedSegment.h" 16#import "EXScopedLocalAuthentication.h" 17#import "EXScopedBranch.h" 18#import "EXScopedErrorRecoveryModule.h" 19#import "EXScopedFacebook.h" 20#import "EXScopedFirebaseCore.h" 21#import "EXUpdatesBinding.h" 22 23#import "EXScopedReactNativeAdapter.h" 24#import "EXExpoUserNotificationCenterProxy.h" 25 26#import "EXScopedNotificationsEmitter.h" 27#import "EXScopedNotificationsHandlerModule.h" 28#import "EXScopedNotificationBuilder.h" 29#import "EXScopedNotificationSchedulerModule.h" 30#import "EXScopedNotificationPresentationModule.h" 31#import "EXScopedNotificationCategoriesModule.h" 32#import "EXScopedServerRegistrationModule.h" 33 34#if __has_include(<EXTaskManager/EXTaskManager.h>) 35#import <EXTaskManager/EXTaskManager.h> 36#endif 37 38@implementation EXScopedModuleRegistryAdapter 39 40- (UMModuleRegistry *)moduleRegistryForParams:(NSDictionary *)params 41 forExperienceStableLegacyId:(NSString *)experienceStableLegacyId 42 scopeKey:(NSString *)scopeKey 43 withKernelServices:(NSDictionary *)kernelServices 44{ 45 UMModuleRegistry *moduleRegistry = [self.moduleRegistryProvider moduleRegistry]; 46 47#if __has_include(<EXUpdates/EXUpdatesService.h>) 48 EXUpdatesBinding *updatesBinding = [[EXUpdatesBinding alloc] initWithScopeKey:scopeKey 49 updatesKernelService:kernelServices[EX_UNVERSIONED(@"EXUpdatesManager")] 50 databaseKernelService:kernelServices[EX_UNVERSIONED(@"EXUpdatesDatabaseManager")]]; 51 [moduleRegistry registerInternalModule:updatesBinding]; 52#endif 53 54#if __has_include(<EXConstants/EXConstantsService.h>) 55 EXConstantsBinding *constantsBinding = [[EXConstantsBinding alloc] initWithParams:params]; 56 [moduleRegistry registerInternalModule:constantsBinding]; 57#endif 58 59#if __has_include(<EXFacebook/EXFacebook.h>) 60 // only override in Expo Go 61 if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) { 62 EXScopedFacebook *scopedFacebook = [[EXScopedFacebook alloc] initWithScopeKey:scopeKey andParams:params]; 63 [moduleRegistry registerExportedModule:scopedFacebook]; 64 } 65#endif 66 67#if __has_include(<EXFileSystem/EXFileSystem.h>) 68 EXScopedFileSystemModule *fileSystemModule; 69 if (params[@"fileSystemDirectories"]) { 70 NSString *documentDirectory = params[@"fileSystemDirectories"][@"documentDirectory"]; 71 NSString *cachesDirectory = params[@"fileSystemDirectories"][@"cachesDirectory"]; 72 fileSystemModule = [[EXScopedFileSystemModule alloc] initWithDocumentDirectory:documentDirectory 73 cachesDirectory:cachesDirectory 74 bundleDirectory:nil]; 75 } else { 76 fileSystemModule = [EXScopedFileSystemModule new]; 77 } 78 [moduleRegistry registerExportedModule:fileSystemModule]; 79 [moduleRegistry registerInternalModule:fileSystemModule]; 80#endif 81 82#if __has_include(<EXFont/EXFontLoader.h>) 83 EXScopedFontLoader *fontModule = [[EXScopedFontLoader alloc] init]; 84 [moduleRegistry registerExportedModule:fontModule]; 85#endif 86 87#if __has_include(<EXSensors/EXSensorsManager.h>) 88 EXSensorsManagerBinding *sensorsManagerBinding = [[EXSensorsManagerBinding alloc] initWithScopeKey:scopeKey andKernelService:kernelServices[EX_UNVERSIONED(@"EXSensorManager")]]; 89 [moduleRegistry registerInternalModule:sensorsManagerBinding]; 90#endif 91 92 EXScopedReactNativeAdapter *reactNativeAdapter = [[EXScopedReactNativeAdapter alloc] init]; 93 [moduleRegistry registerInternalModule:reactNativeAdapter]; 94 95 EXExpoUserNotificationCenterProxy *userNotificationCenter = [[EXExpoUserNotificationCenterProxy alloc] initWithUserNotificationCenter:kernelServices[EX_UNVERSIONED(@"EXUserNotificationCenter")]]; 96 [moduleRegistry registerInternalModule:userNotificationCenter]; 97 98#if __has_include(<EXFileSystem/EXFilePermissionModule.h>) 99 EXScopedFilePermissionModule *filePermissionModule = [[EXScopedFilePermissionModule alloc] init]; 100 [moduleRegistry registerInternalModule:filePermissionModule]; 101#endif 102 103#if __has_include(<EXSecureStore/EXSecureStore.h>) 104 EXScopedSecureStore *secureStoreModule = [[EXScopedSecureStore alloc] initWithScopeKey:scopeKey andConstantsBinding:constantsBinding]; 105 [moduleRegistry registerExportedModule:secureStoreModule]; 106#endif 107 108#if __has_include(<EXAmplitude/EXAmplitude.h>) 109 EXScopedAmplitude *amplitudeModule = [[EXScopedAmplitude alloc] initWithExperienceStableLegacyId:experienceStableLegacyId]; 110 [moduleRegistry registerExportedModule:amplitudeModule]; 111#endif 112 113#if __has_include(<UMReactNativeAdapter/EXPermissionsService.h>) 114 EXScopedPermissions *permissionsModule = [[EXScopedPermissions alloc] initWithScopeKey:scopeKey andConstantsBinding:constantsBinding]; 115 [moduleRegistry registerExportedModule:permissionsModule]; 116 [moduleRegistry registerInternalModule:permissionsModule]; 117#endif 118 119#if __has_include(<EXSegment/EXSegment.h>) 120 EXScopedSegment *segmentModule = [[EXScopedSegment alloc] init]; 121 [moduleRegistry registerExportedModule:segmentModule]; 122#endif 123 124#if __has_include(<EXBranch/RNBranch.h>) 125 EXScopedBranch *branchModule = [[EXScopedBranch alloc] initWithScopeKey:scopeKey]; 126 [moduleRegistry registerInternalModule:branchModule]; 127#endif 128 129#if __has_include(<EXLocalAuthentication/EXLocalAuthentication.h>) 130 EXScopedLocalAuthentication *localAuthenticationModule = [[EXScopedLocalAuthentication alloc] init]; 131 [moduleRegistry registerExportedModule:localAuthenticationModule]; 132#endif 133 134#if __has_include(<EXTaskManager/EXTaskManager.h>) 135 // TODO: Make scoped task manager when adding support for bare React Native 136 EXTaskManager *taskManagerModule = [[EXTaskManager alloc] initWithScopeKey:scopeKey]; 137 [moduleRegistry registerInternalModule:taskManagerModule]; 138 [moduleRegistry registerExportedModule:taskManagerModule]; 139#endif 140 141#if __has_include(<EXErrorRecovery/EXErrorRecoveryModule.h>) 142 EXScopedErrorRecoveryModule *errorRecovery = [[EXScopedErrorRecoveryModule alloc] initWithScopeKey:scopeKey]; 143 [moduleRegistry registerExportedModule:errorRecovery]; 144#endif 145 146#if __has_include(<EXFirebaseCore/EXFirebaseCore.h>) 147 EXScopedFirebaseCore *firebaseCoreModule = [[EXScopedFirebaseCore alloc] initWithScopeKey:scopeKey andConstantsBinding:constantsBinding]; 148 [moduleRegistry registerExportedModule:firebaseCoreModule]; 149 [moduleRegistry registerInternalModule:firebaseCoreModule]; 150#endif 151 152#if __has_include(<EXNotifications/EXNotificationsEmitter.h>) 153 // only override in Expo Go 154 if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) { 155 EXScopedNotificationsEmitter *notificationsEmmitter = [[EXScopedNotificationsEmitter alloc] initWithScopeKey:scopeKey]; 156 [moduleRegistry registerExportedModule:notificationsEmmitter]; 157 } 158#endif 159 160#if __has_include(<EXNotifications/EXNotificationsHandlerModule.h>) 161 // only override in Expo Go 162 if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) { 163 EXScopedNotificationsHandlerModule *notificationsHandler = [[EXScopedNotificationsHandlerModule alloc] initWithScopeKey:scopeKey]; 164 [moduleRegistry registerExportedModule:notificationsHandler]; 165 } 166#endif 167 168#if __has_include(<EXNotifications/EXNotificationsHandlerModule.h>) 169 EXScopedNotificationBuilder *notificationsBuilder = [[EXScopedNotificationBuilder alloc] initWithScopeKey:scopeKey 170 andConstantsBinding:constantsBinding]; 171 [moduleRegistry registerInternalModule:notificationsBuilder]; 172#endif 173 174#if __has_include(<EXNotifications/EXNotificationSchedulerModule.h>) 175 // only override in Expo Go 176 if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) { 177 EXScopedNotificationSchedulerModule *schedulerModule = [[EXScopedNotificationSchedulerModule alloc] initWithScopeKey:scopeKey]; 178 [moduleRegistry registerExportedModule:schedulerModule]; 179 } 180#endif 181 182#if __has_include(<EXNotifications/EXNotificationPresentationModule.h>) 183 // only override in Expo Go 184 if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) { 185 EXScopedNotificationPresentationModule *notificationPresentationModule = [[EXScopedNotificationPresentationModule alloc] initWithScopeKey:scopeKey]; 186 [moduleRegistry registerExportedModule:notificationPresentationModule]; 187 } 188#endif 189 190#if __has_include(<EXNotifications/EXNotificationCategoriesModule.h>) 191 // only override in Expo Go 192 if ([params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]) { 193 EXScopedNotificationCategoriesModule *scopedCategoriesModule = [[EXScopedNotificationCategoriesModule alloc] initWithScopeKey:scopeKey 194 andConstantsBinding:constantsBinding]; 195 [moduleRegistry registerExportedModule:scopedCategoriesModule]; 196 } 197 [EXScopedNotificationCategoriesModule maybeMigrateLegacyCategoryIdentifiersForProjectWithExperienceStableLegacyId:experienceStableLegacyId 198 scopeKey:scopeKey 199 isInExpoGo:[params[@"constants"][@"appOwnership"] isEqualToString:@"expo"]]; 200#endif 201 202#if __has_include(<EXNotifications/EXServerRegistrationModule.h>) 203 EXScopedServerRegistrationModule *serverRegistrationModule = [[EXScopedServerRegistrationModule alloc] initWithScopeKey:scopeKey]; 204 [moduleRegistry registerExportedModule:serverRegistrationModule]; 205#endif 206 207 return moduleRegistry; 208} 209 210@end 211