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; +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/yarn.lock b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock index 3bf115e2a8f..7ffb1f9b87e 100644 --- a/ReactCommon/hermes/inspector/tools/msggen/yarn.lock +++ b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock @@ -145,8 +145,10 @@ asn1.js@^4.0.0: minimalistic-assert "^1.0.0" asn1@~0.2.3: - version "0.2.3" - resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" + version "0.2.4" + resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.4.tgz#8d2475dfab553bb33e77b54e59e880bb8ce23136" + dependencies: + safer-buffer "~2.1.0" assert-plus@1.0.0, assert-plus@^1.0.0: version "1.0.0" @@ -751,8 +753,8 @@ base64-js@^1.0.2: resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886" bcrypt-pbkdf@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d" + version "1.0.2" + resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e" dependencies: tweetnacl "^0.14.3" @@ -1205,10 +1207,11 @@ domain-browser@^1.1.1: resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" ecc-jsbn@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505" + version "0.1.2" + resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz#3a83a904e54353287874c564b7549386849a98c9" dependencies: jsbn "~0.1.0" + safer-buffer "^2.1.0" electron-to-chromium@^1.3.24: version "1.3.26" @@ -3100,6 +3103,10 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@~5.1.0, version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" +safer-buffer@^2.0.2, safer-buffer@^2.1.0, safer-buffer@~2.1.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + sane@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/sane/-/sane-2.2.0.tgz#d6d2e2fcab00e3d283c93b912b7c3a20846f1d56" @@ -3214,17 +3221,17 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" sshpk@^1.7.0: - version "1.13.1" - resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.13.1.tgz#512df6da6287144316dc4c18fe1cf1d940739be3" + version "1.16.1" + resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877" dependencies: asn1 "~0.2.3" assert-plus "^1.0.0" - dashdash "^1.12.0" - getpass "^0.1.1" - optionalDependencies: bcrypt-pbkdf "^1.0.0" + dashdash "^1.12.0" ecc-jsbn "~0.1.1" + getpass "^0.1.1" jsbn "~0.1.0" + safer-buffer "^2.0.2" tweetnacl "~0.14.0" stream-browserify@^2.0.1: