Skip to content

Commit

Permalink
Disable live reload when running in Detox
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoNatan committed Oct 13, 2020
1 parent c1edeae commit 36ea886
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions detox/ios/Detox/Utilities/ReactNativeSupport/ReactNativeSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@

DTX_CREATE_LOG(ReactNativeSupport);

@interface NSObject (DTXRNFix) @end
@implementation NSObject (DTXRNFix)

//Disable live reload for Detox
- (void)__detox_sync__reloadWithDefaults:(NSDictionary *)defaultValues
{
NSMutableDictionary* dv = [defaultValues mutableCopy];
dv[@"hotLoadingEnabled"] = @NO;

[self __detox_sync__reloadWithDefaults:defaultValues];

NSMutableDictionary* _settings = [self valueForKey:@"_settings"];
_settings[@"hotLoadingEnabled"] = @NO;
[NSUserDefaults.standardUserDefaults setObject:_settings forKey:@"RCTDevMenu"];
}

@end

static NSString *const RCTReloadNotification = @"RCTReloadNotification";

static dispatch_queue_t __currentIdlingResourceSerialQueue;
Expand Down Expand Up @@ -221,6 +239,12 @@ static void __setupRNSupport()
[[GREYUIThreadExecutor sharedInstance] registerIdlingResource:[WXAnimatedDisplayLinkIdlingResource new]];
}

cls = NSClassFromString(@"RCTDevSettingsUserDefaultsDataSource");
if(cls != nil)
{
DTXSwizzleMethod(cls, NSSelectorFromString(@"_reloadWithDefaults:"), @selector(__detox_sync__reloadWithDefaults:), NULL);
}

//🤦‍♂️ RN doesn't set the data source and relies on undocumented behavior.
cls = NSClassFromString(@"RCTPicker");
if(cls != nil)
Expand Down

0 comments on commit 36ea886

Please sign in to comment.