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..85b7d4e5944 100644 --- a/ReactCommon/hermes/inspector/tools/msggen/yarn.lock +++ b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock @@ -2413,8 +2413,8 @@ memory-fs@^0.4.0, memory-fs@~0.4.1: readable-stream "^2.0.1" merge@^1.1.3: - version "1.2.0" - resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da" + version "1.2.1" + resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.1.tgz#38bebf80c3220a8a487b6fcfb3941bb11720c145" micromatch@^2.1.5, micromatch@^2.3.11: version "2.3.11"