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 5e8236db40689ccc63fbefed5dd67ff2bf8106ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Oct 2019 09:07:22 +0000 Subject: [PATCH 2/2] Bump mixin-deep from 1.3.1 to 1.3.2 Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2. - [Release notes](https://github.com/jonschlinkert/mixin-deep/releases) - [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2) Signed-off-by: dependabot[bot] --- yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 53583871e85..4593636be6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5050,9 +5050,9 @@ minizlib@^1.1.0: minipass "^2.2.1" mixin-deep@^1.2.0: - version "1.3.1" - resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.1.tgz#a49e7268dce1a0d9698e45326c5626df3543d0fe" - integrity sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ== + version "1.3.2" + resolved "https://registry.yarnpkg.com/mixin-deep/-/mixin-deep-1.3.2.tgz#1120b43dc359a785dce65b55b82e257ccf479566" + integrity sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA== dependencies: for-in "^1.0.2" is-extendable "^1.0.1" @@ -5508,7 +5508,7 @@ p-finally@^1.0.0: p-is-promise@^1.1.0: version "1.1.0" - resolved "http://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz#9c9456989e9f6588017b0434d56097675c3da05e" + resolved "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz#9c9456989e9f6588017b0434d56097675c3da05e" integrity sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4= p-limit@^1.1.0: