From 2b5f4de7eb4e5453e91d4956bcb0f58fe37b6562 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Wed, 16 Oct 2019 18:43:00 -0700 Subject: [PATCH 1/2] Make RCTTiming TurboModule-compatible Summary: Changelog: [iOS][Added] Make RCTTiming TurboModule-compatible Reviewed By: PeteTheHeat Differential Revision: D17891665 fbshipit-source-id: e0d36ccfb4f3f1d428668836a8b66698d51bdeaf --- React/CoreModules/BUCK | 5 +- React/CoreModules/CoreModulesPlugins.h | 1 + React/CoreModules/CoreModulesPlugins.mm | 1 + React/{Modules => CoreModules}/RCTTiming.h | 2 +- .../RCTTiming.m => CoreModules/RCTTiming.mm} | 49 +++++++++++++------ 5 files changed, 41 insertions(+), 17 deletions(-) rename React/{Modules => CoreModules}/RCTTiming.h (95%) rename React/{Modules/RCTTiming.m => CoreModules/RCTTiming.mm} (90%) diff --git a/React/CoreModules/BUCK b/React/CoreModules/BUCK index af7a3ecd4f9..5de047226c6 100644 --- a/React/CoreModules/BUCK +++ b/React/CoreModules/BUCK @@ -26,12 +26,12 @@ rn_apple_library( "WebKit", ], exported_preprocessor_flags = rn_extra_build_flags(), - labels = ["supermodule:ios/isolation/infra.react_native"], frameworks = [ "Foundation", "UIKit", ], header_path_prefix = "React", + labels = ["supermodule:ios/isolation/infra.react_native"], lang_compiler_flags = get_fbobjc_enable_exception_lang_compiler_flags_DEPRECATED(), link_whole = True, platform_preprocessor_flags = [( @@ -75,6 +75,9 @@ rn_apple_library( ) + react_module_plugin_providers( name = "AsyncLocalStorage", native_class_func = "RCTAsyncLocalStorageCls", + ) + react_module_plugin_providers( + name = "Timing", + native_class_func = "RCTTimingCls", ), plugins_header = "FBCoreModulesPlugins.h", preprocessor_flags = OBJC_ARC_PREPROCESSOR_FLAGS + get_debug_preprocessor_flags() + rn_extra_build_flags() + [ diff --git a/React/CoreModules/CoreModulesPlugins.h b/React/CoreModules/CoreModulesPlugins.h index e1b8558a144..dca8fb2fdcc 100644 --- a/React/CoreModules/CoreModulesPlugins.h +++ b/React/CoreModules/CoreModulesPlugins.h @@ -41,6 +41,7 @@ Class RCTSourceCodeCls(void) __attribute__((used)); Class RCTActionSheetManagerCls(void) __attribute__((used)); Class RCTAlertManagerCls(void) __attribute__((used)); Class RCTAsyncLocalStorageCls(void) __attribute__((used)); +Class RCTTimingCls(void) __attribute__((used)); #ifdef __cplusplus } diff --git a/React/CoreModules/CoreModulesPlugins.mm b/React/CoreModules/CoreModulesPlugins.mm index 61e400db4e2..1778f3c2231 100644 --- a/React/CoreModules/CoreModulesPlugins.mm +++ b/React/CoreModules/CoreModulesPlugins.mm @@ -30,6 +30,7 @@ Class RCTCoreModulesClassProvider(const char *name) { {"ActionSheetManager", RCTActionSheetManagerCls}, {"AlertManager", RCTAlertManagerCls}, {"AsyncLocalStorage", RCTAsyncLocalStorageCls}, + {"Timing", RCTTimingCls}, }; auto p = sCoreModuleClassMap.find(name); diff --git a/React/Modules/RCTTiming.h b/React/CoreModules/RCTTiming.h similarity index 95% rename from React/Modules/RCTTiming.h rename to React/CoreModules/RCTTiming.h index 9c5f3b3bfe5..f004bd302f6 100644 --- a/React/Modules/RCTTiming.h +++ b/React/CoreModules/RCTTiming.h @@ -26,7 +26,7 @@ duration:(NSTimeInterval)jsDuration jsSchedulingTime:(NSDate *)jsSchedulingTime repeats:(BOOL)repeats; -- (void)deleteTimer:(nonnull NSNumber *)timerID; +- (void)deleteTimer:(double)timerID; @end diff --git a/React/Modules/RCTTiming.m b/React/CoreModules/RCTTiming.mm similarity index 90% rename from React/Modules/RCTTiming.m rename to React/CoreModules/RCTTiming.mm index 4a9edaa6023..1c6e61047f8 100644 --- a/React/Modules/RCTTiming.m +++ b/React/CoreModules/RCTTiming.mm @@ -7,11 +7,16 @@ #import "RCTTiming.h" -#import "RCTAssert.h" -#import "RCTBridge+Private.h" -#import "RCTBridge.h" -#import "RCTLog.h" -#import "RCTUtils.h" +#import + +#import +#import +#import +#import +#import +#import + +#import "CoreModulesPlugins.h" static const NSTimeInterval kMinimumSleepInterval = 1; @@ -91,6 +96,9 @@ - (void)timerDidFire @end +@interface RCTTiming() +@end + @implementation RCTTiming { NSMutableDictionary *_timers; @@ -158,10 +166,10 @@ - (void)dealloc - (void)markStartOfBackgroundTaskIfNeeded { if (_backgroundTaskIdentifier == UIBackgroundTaskInvalid) { - __weak typeof(self) weakSelf = self; + __weak RCTTiming *weakSelf = self; // Marks the beginning of a new long-running background task. We can run the timer in the background. _backgroundTaskIdentifier = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"rct.timing.gb.task" expirationHandler:^{ - typeof(self) strongSelf = weakSelf; + RCTTiming *strongSelf = weakSelf; if (!strongSelf) { return; } @@ -360,24 +368,26 @@ - (void)timerDidFire * calculating the timer's target time. We calculate this by passing in * Date.now() from JS and then subtracting that from the current time here. */ -RCT_EXPORT_METHOD(createTimer:(nonnull NSNumber *)callbackID +RCT_EXPORT_METHOD(createTimer:(double)callbackID duration:(NSTimeInterval)jsDuration - jsSchedulingTime:(NSDate *)jsSchedulingTime + jsSchedulingTime:(double)jsSchedulingTime repeats:(BOOL)repeats) { + NSNumber *callbackIdObjc = [NSNumber numberWithDouble:callbackID]; + NSDate *schedulingTime = [RCTConvert NSDate:[NSNumber numberWithDouble: jsSchedulingTime]]; if (jsDuration == 0 && repeats == NO) { // For super fast, one-off timers, just enqueue them immediately rather than waiting a frame. if (_bridge) { - [_bridge _immediatelyCallTimer:callbackID]; + [_bridge _immediatelyCallTimer:callbackIdObjc]; } else { - [_timingDelegate immediatelyCallTimer:callbackID]; + [_timingDelegate immediatelyCallTimer:callbackIdObjc]; } return; } - [self createTimerForNextFrame:callbackID + [self createTimerForNextFrame:callbackIdObjc duration:jsDuration - jsSchedulingTime:jsSchedulingTime + jsSchedulingTime:schedulingTime repeats:repeats]; } @@ -417,10 +427,10 @@ - (void)createTimerForNextFrame:(nonnull NSNumber *)callbackID } } -RCT_EXPORT_METHOD(deleteTimer:(nonnull NSNumber *)timerID) +RCT_EXPORT_METHOD(deleteTimer:(double)timerID) { @synchronized (_timers) { - [_timers removeObjectForKey:timerID]; + [_timers removeObjectForKey:[NSNumber numberWithDouble:timerID]]; } if (![self hasPendingTimers]) { [self stopTimers]; @@ -437,4 +447,13 @@ - (void)createTimerForNextFrame:(nonnull NSNumber *)callbackID } } +- (std::shared_ptr)getTurboModuleWithJsInvoker:(std::shared_ptr)jsInvoker +{ + return std::make_shared(self, jsInvoker); +} + @end + +Class RCTTimingCls(void) { + return RCTTiming.class; +} From 1d4604711526ee976b805db700072b86d5b476ce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Aug 2020 00:07:06 +0000 Subject: [PATCH 2/2] Bump elliptic in /ReactCommon/hermes/inspector/tools/msggen Bumps [elliptic](https://github.com/indutny/elliptic) from 6.4.0 to 6.5.3. - [Release notes](https://github.com/indutny/elliptic/releases) - [Commits](https://github.com/indutny/elliptic/compare/v6.4.0...v6.5.3) Signed-off-by: dependabot[bot] --- .../hermes/inspector/tools/msggen/yarn.lock | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ReactCommon/hermes/inspector/tools/msggen/yarn.lock b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock index 3bf115e2a8f..de80cfd6eea 100644 --- a/ReactCommon/hermes/inspector/tools/msggen/yarn.lock +++ b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock @@ -771,8 +771,8 @@ block-stream@*: inherits "~2.0.0" bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: - version "4.11.8" - resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" + version "4.11.9" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.9.tgz#26d556829458f9d1e81fc48952493d0ba3507828" boom@2.x.x: version "2.10.1" @@ -1215,8 +1215,8 @@ electron-to-chromium@^1.3.24: resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.26.tgz#996427294861a74d9c7c82b9260ea301e8c02d66" elliptic@^6.0.0: - version "6.4.0" - resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df" + version "6.5.3" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6" dependencies: bn.js "^4.4.0" brorand "^1.0.1" @@ -1668,11 +1668,11 @@ hash-base@^3.0.0: safe-buffer "^5.0.1" hash.js@^1.0.0, hash.js@^1.0.3: - version "1.1.3" - resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.3.tgz#340dedbe6290187151c1ea1d777a3448935df846" + version "1.1.7" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.7.tgz#0babca538e8d4ee4a0f8988d68866537a003cf42" dependencies: inherits "^2.0.3" - minimalistic-assert "^1.0.0" + minimalistic-assert "^1.0.1" hawk@3.1.3, hawk@~3.1.3: version "3.1.3" @@ -1773,8 +1773,8 @@ inflight@^1.0.4: wrappy "1" inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1, inherits@~2.0.3: - version "2.0.3" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" inherits@2.0.1: version "2.0.1" @@ -2455,9 +2455,9 @@ mimic-fn@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18" -minimalistic-assert@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz#702be2dda6b37f4836bcb3f5db56641b64a1d3d3" +minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7" minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: version "1.0.1"