From 1ce7e4c1e5dd0e7c8f0d8b49161d2759103a2dcf Mon Sep 17 00:00:00 2001 From: Ben Nham Date: Thu, 17 Aug 2017 17:09:59 -0700 Subject: [PATCH] add notifications for dev reload Reviewed By: alexeylang Differential Revision: D5630472 fbshipit-source-id: 1c44a52fddead361b43551384bbfc73e2d89438f --- React/Base/RCTBridge.h | 18 ++++++++++++++++++ React/Base/RCTBridge.m | 5 +++++ React/CxxBridge/RCTCxxBridge.mm | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/React/Base/RCTBridge.h b/React/Base/RCTBridge.h index 51b2ec0cbd79d0..889c4b3e5a110c 100644 --- a/React/Base/RCTBridge.h +++ b/React/Base/RCTBridge.h @@ -44,6 +44,24 @@ RCT_EXTERN NSString *const RCTJavaScriptDidFailToLoadNotification; */ RCT_EXTERN NSString *const RCTDidInitializeModuleNotification; +/** + * This notification fires just before the bridge starts processing a request to + * reload. + */ +RCT_EXTERN NSString *const RCTBridgeWillReloadNotification; + +/** + * This notification fires just before the bridge begins downloading a script + * from the packager. + */ +RCT_EXTERN NSString *const RCTBridgeWillDownloadScriptNotification; + +/** + * This notification fires just after the bridge finishes downloading a script + * from the packager. + */ +RCT_EXTERN NSString *const RCTBridgeDidDownloadScriptNotification; + /** * This block can be used to instantiate modules that require additional * init parameters, or additional configuration prior to being used. diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index c769a3664308c4..85ee29802e2e23 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -29,6 +29,9 @@ NSString *const RCTJavaScriptDidLoadNotification = @"RCTJavaScriptDidLoadNotification"; NSString *const RCTJavaScriptDidFailToLoadNotification = @"RCTJavaScriptDidFailToLoadNotification"; NSString *const RCTDidInitializeModuleNotification = @"RCTDidInitializeModuleNotification"; +NSString *const RCTBridgeWillReloadNotification = @"RCTBridgeWillReloadNotification"; +NSString *const RCTBridgeWillDownloadScriptNotification = @"RCTBridgeWillDownloadScriptNotification"; +NSString *const RCTBridgeDidDownloadScriptNotification = @"RCTBridgeDidDownloadScriptNotification"; static NSMutableArray *RCTModuleClasses; NSArray *RCTGetModuleClasses(void) @@ -260,6 +263,8 @@ - (void)reload [RCTInspectorDevServerHelper disableDebugger]; #endif + [[NSNotificationCenter defaultCenter] postNotificationName:RCTBridgeWillReloadNotification object:self]; + /** * Any thread */ diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 9d24ebb3100ea2..fd0346a74ef834 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -377,6 +377,8 @@ - (void)start - (void)loadSource:(RCTSourceLoadBlock)_onSourceLoad onProgress:(RCTSourceLoadProgressBlock)onProgress { + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center postNotificationName:RCTBridgeWillDownloadScriptNotification object:_parentBridge]; [_performanceLogger markStartForTag:RCTPLScriptDownload]; NSUInteger cookie = RCTProfileBeginAsyncEvent(0, @"JavaScript download", nil); @@ -388,6 +390,8 @@ - (void)loadSource:(RCTSourceLoadBlock)_onSourceLoad onProgress:(RCTSourceLoadPr RCTProfileEndAsyncEvent(0, @"native", cookie, @"JavaScript download", @"JS async"); [performanceLogger markStopForTag:RCTPLScriptDownload]; [performanceLogger setValue:sourceLength forTag:RCTPLBundleSize]; + [center postNotificationName:RCTBridgeDidDownloadScriptNotification object:self->_parentBridge]; + _onSourceLoad(error, source, sourceLength); };