Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JS load handler. Fix JS run loop sync. Add New Arch flag #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
36 changes: 26 additions & 10 deletions DetoxSync/DetoxSync/ReactNativeSupport/DTXReactNativeSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see any reason to wait for RCTJavaScriptDidLoadNotification when in any case we will need to wait for RCTContentDidAppearNotification. Also RCTJavaScriptDidLoadNotification is not emitted on RN 0.76 with New Arch.

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(), ^{
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dispatch_async probably can be removed

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<UIApplicationDelegate> *delegate = UIApplication.sharedApplication.delegate;
return [delegate valueForKey:@"newArchEnabled"];
}

+ (void)cleanupBeforeReload
{
dtx_log_info(@"Cleaning idling resource before RN load");
Expand Down