diff --git a/React/AppSetup/RCTAppSetupUtils.mm b/React/AppSetup/RCTAppSetupUtils.mm index 4d58caebfe2e13..6ce3d20a9497ec 100644 --- a/React/AppSetup/RCTAppSetupUtils.mm +++ b/React/AppSetup/RCTAppSetupUtils.mm @@ -83,11 +83,13 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled) } else if (moduleClass == RCTNetworking.class) { return [[moduleClass alloc] initWithHandlersProvider:^NSArray> *(RCTModuleRegistry *moduleRegistry) { - return @[ - [RCTHTTPRequestHandler new], - [RCTDataRequestHandler new], - [RCTFileRequestHandler new], - ]; + NSArray *handlers = [moduleRegistry modulesConformingToProtocol:@protocol(RCTURLRequestHandler)]; + NSArray *handlersWithDefaultOnes = [handlers arrayByAddingObjectsFromArray: @[ + [RCTHTTPRequestHandler new], + [RCTDataRequestHandler new], + [RCTFileRequestHandler new], + ]]; + return handlersWithDefaultOnes; }]; } // No custom initializer here. diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index cc429c410f58ab..375ba0c2a6a143 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -390,6 +390,7 @@ RCT_EXTERN_C_END - (id)moduleForName:(const char *)moduleName; - (id)moduleForName:(const char *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyLoad; +- (NSArray *)modulesConformingToProtocol:(Protocol *)protocol; @end typedef UIView * (^RCTBridgelessComponentViewProvider)(NSNumber *); diff --git a/React/Base/RCTModuleRegistry.m b/React/Base/RCTModuleRegistry.m index 98dd082fe8ee90..c6dc1e3021775f 100644 --- a/React/Base/RCTModuleRegistry.m +++ b/React/Base/RCTModuleRegistry.m @@ -47,4 +47,16 @@ - (id)moduleForName:(const char *)moduleName lazilyLoadIfNecessary:(BOOL)lazilyL return module; } +- (NSArray *)modulesConformingToProtocol:(Protocol *)protocol +{ + NSMutableArray *modules = [NSMutableArray new]; + RCTBridge *bridge = _bridge; + if (bridge) { + [modules addObjectsFromArray:[bridge modulesConformingToProtocol:protocol]]; + } + + // TODO: find a way to get the same information of turboModules + return [modules copy]; +} + @end