diff --git a/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.h b/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.h index c41686f..5c27d84 100644 --- a/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.h +++ b/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.h @@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN /// @param completionHandler The completion handler to call when React Native has finished loading. + (void)waitForReactNativeLoadWithCompletionHandler:(void (^)(void))completionHandler; ++ (BOOL) newArchEnabled; + @end NS_ASSUME_NONNULL_END diff --git a/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.m b/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.m index 5e8e872..acd2dbd 100644 --- a/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.m +++ b/DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.m @@ -64,7 +64,18 @@ static int __detox_sync_UIApplication_run(id self, SEL _cmd) m = class_getClassMethod(cls, NSSelectorFromString(@"runRunLoopThread")); dtx_log_info(@"Found legacy class RCTJSCExecutor"); } - else + + if (m == NULL && [DTXReactNativeSupport newArchEnabled]) + { + //Modern RN + cls = NSClassFromString(@"RCTJSThreadManager"); + if (cls != NULL) { + m = class_getClassMethod(cls, NSSelectorFromString(@"runRunLoop")); + dtx_log_info(@"Found modern class RCTJSThreadManager, method runRunLoop"); + } + } + + if (m == NULL) { //Modern RN cls = NSClassFromString(@"RCTCxxBridge"); @@ -215,25 +226,30 @@ + (void)waitForReactNativeLoadWithCompletionHandler:(void (^)(void))handler __block __weak id observer; __block __weak id observer2; - observer = [[NSNotificationCenter defaultCenter] addObserverForName:@"RCTJavaScriptDidLoadNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { + observer = [[NSNotificationCenter defaultCenter] addObserverForName:@"RCTContentDidAppearNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [[NSNotificationCenter defaultCenter] removeObserver:observer]; - [[NSNotificationCenter defaultCenter] removeObserver:observer2]; - - observer = [[NSNotificationCenter defaultCenter] addObserverForName:@"RCTContentDidAppearNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { - [[NSNotificationCenter defaultCenter] removeObserver:observer]; - handler(); - }]; + dispatch_async(dispatch_get_main_queue(), ^{ + handler(); + }); }]; - observer2 = [[NSNotificationCenter defaultCenter] addObserverForName:@"RCTJavaScriptDidFailToLoadNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { + observer2 = [[NSNotificationCenter defaultCenter] addObserverForName:@"RCTJavaScriptDidFailToLoadNotification" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [[NSNotificationCenter defaultCenter] removeObserver:observer]; [[NSNotificationCenter defaultCenter] removeObserver:observer2]; - handler(); + dispatch_async(dispatch_get_main_queue(), ^{ + handler(); + }); }]; } ++ (BOOL) newArchEnabled +{ + NSObject *delegate = UIApplication.sharedApplication.delegate; + return [delegate valueForKey:@"newArchEnabled"]; +} + + (void)cleanupBeforeReload { dtx_log_info(@"Cleaning idling resource before RN load");