Skip to content

Commit

Permalink
fix: start work on custom request handlers on new arch
Browse files Browse the repository at this point in the history
  • Loading branch information
WoLewicki committed Feb 6, 2023
1 parent 011ea33 commit 222dd96
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions React/AppSetup/RCTAppSetupUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
} else if (moduleClass == RCTNetworking.class) {
return [[moduleClass alloc]
initWithHandlersProvider:^NSArray<id<RCTURLRequestHandler>> *(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.
Expand Down
1 change: 1 addition & 0 deletions React/Base/RCTBridgeModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
12 changes: 12 additions & 0 deletions React/Base/RCTModuleRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 222dd96

Please sign in to comment.