// Copyright 2015-present 650 Industries. All rights reserved. #import // The search path for the Swift generated headers are different // between use_frameworks and non_use_frameworks mode. #if __has_include() #import #else #import #endif #if __has_include() #import #else #import #endif #if __has_include() #import #else #import #endif #import #import #import #import #import #import #import #if __has_include() // for importing the header from framework, the dash will be transformed to underscore #import #else #import #endif #if __has_include() #import #endif @implementation DevMenuRCTCxxBridge - (instancetype)initWithParentBridge:(RCTBridge *)bridge { if ((self = [super initWithParentBridge:bridge])) { RCTBridge *appBridge = DevMenuManager.shared.currentBridge; // reset the singleton `RCTBridge.currentBridge` to app bridge instance RCTBridge.currentBridge = appBridge != nil ? appBridge.batchedBridge : nil; } return self; } /** * Theoretically, we could overwrite the `RCTDevSettings` module by exporting our version through the bridge. * However, this won't work with the js remote debugging. For some reason, the RN needs to initialized remote tools very early. So it always uses the default module to do it. * When we export our module, it won't be used in the initialized phase. So the dev-menu will start with remote debug support. */ - (RCTDevSettings *)devSettings { // uncomment below to enable fast refresh for development builds of DevMenu // return super.devSettings; return nil; } - (RCTDevMenu *)devMenu { return nil; } - (NSArray *)filterModuleList:(NSArray *)modules { NSArray *allowedModules = @[@"RCT", @"ExpoBridgeModule", @"EXNativeModulesProxy", @"EXReactNativeEventEmitter"]; NSArray *filteredModuleList = [modules filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id _Nullable clazz, NSDictionary * _Nullable bindings) { NSString* clazzName = NSStringFromClass(clazz); if ([clazz conformsToProtocol:@protocol(EXDevExtensionProtocol)]) { return true; } for (NSString *allowedModule in allowedModules) { if ([clazzName hasPrefix:allowedModule]) { return true; } } return false; }]]; return filteredModuleList; } - (NSArray *)_initializeModules:(NSArray *)modules withDispatchGroup:(dispatch_group_t)dispatchGroup lazilyDiscovered:(BOOL)lazilyDiscovered { NSArray *filteredModuleList = [self filterModuleList: modules]; return [super _initializeModules:filteredModuleList withDispatchGroup:dispatchGroup lazilyDiscovered:lazilyDiscovered]; } @end @implementation DevMenuRCTBridge - (Class)bridgeClass { return [DevMenuRCTCxxBridge class]; } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-implementations" // This method is still used so we need to override it even if it's deprecated - (void)reloadWithReason:(NSString *)reason {} #pragma clang diagnostic pop @end @interface DevClientAppDelegate (DevMenuRCTAppDelegate) #ifdef __cplusplus - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge; #endif @end @implementation DevMenuRCTAppDelegate - (RCTBridge *)createBridgeWithDelegate:(id)delegate launchOptions:(NSDictionary *)launchOptions { return [[DevMenuRCTBridge alloc] initWithDelegate:delegate launchOptions:launchOptions]; } #pragma mark - RCTCxxBridgeDelegate - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge { std::unique_ptr executorFactory = [super jsExecutorFactoryForBridge:bridge]; #if __has_include() auto rawExecutorFactory = executorFactory.get(); auto hermesExecFactory = dynamic_cast(rawExecutorFactory); if (hermesExecFactory != nullptr) { hermesExecFactory->setEnableDebugger(false); } #endif return executorFactory; } @end