From 3d6ffcf903f02bc3e67ebee1e57c7baf62fe1398 Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Mon, 22 Jun 2015 13:29:39 -0700 Subject: [PATCH] [ReactNative][Profiler] Fix initialize extra call + add popup Summary: @public When the profile is initialized, it automatically hooks into every method of the bridge modules, that was causing `+initialize` to be called twice. Also add a popup to notify the user that the profile has been created. Test Plan: Run the UIExplorer, start the profiler, try to rage shake to open the dev menu again. It should now work, and show an alertview with some information once the profile is stopped. --- React/Base/RCTBridge.m | 6 ++++++ React/Base/RCTProfile.m | 2 ++ 2 files changed, 8 insertions(+) diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index 5a03d25b0..c1b4373c9 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -1529,6 +1529,12 @@ RCT_INNER_BRIDGE_ONLY(_invokeAndProcessModule:(__unused NSString *)module ^(__unused NSData *data, __unused NSURLResponse *response, NSError *error) { if (error) { RCTLogError(@"%@", error.localizedDescription); + } else { + [[[UIAlertView alloc] initWithTitle:@"Profile" + message:@"The profile has been generated, check the dev server log for instructions." + delegate:nil + cancelButtonTitle:@"OK" + otherButtonTitles:nil] show]; } }]; diff --git a/React/Base/RCTProfile.m b/React/Base/RCTProfile.m index a2b3d7106..d81d545f2 100644 --- a/React/Base/RCTProfile.m +++ b/React/Base/RCTProfile.m @@ -172,6 +172,8 @@ static void RCTProfileHookModules(RCTBridge *bridge) } free(methods); + class_replaceMethod(object_getClass(proxyClass), @selector(initialize), imp_implementationWithBlock(^{}), "v@:"); + for (Class cls in @[proxyClass, object_getClass(proxyClass)]) { Method oldImp = class_getInstanceMethod(cls, @selector(class)); class_replaceMethod(cls, @selector(class), imp_implementationWithBlock(^{ return moduleClass; }), method_getTypeEncoding(oldImp));