Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion React/CoreModules/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [(
Expand Down Expand Up @@ -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() + [
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Class RCTCoreModulesClassProvider(const char *name) {
{"ActionSheetManager", RCTActionSheetManagerCls},
{"AlertManager", RCTAlertManagerCls},
{"AsyncLocalStorage", RCTAsyncLocalStorageCls},
{"Timing", RCTTimingCls},
};

auto p = sCoreModuleClassMap.find(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
duration:(NSTimeInterval)jsDuration
jsSchedulingTime:(NSDate *)jsSchedulingTime
repeats:(BOOL)repeats;
- (void)deleteTimer:(nonnull NSNumber *)timerID;
- (void)deleteTimer:(double)timerID;

@end

49 changes: 34 additions & 15 deletions React/Modules/RCTTiming.m β†’ React/CoreModules/RCTTiming.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@

#import "RCTTiming.h"

#import "RCTAssert.h"
#import "RCTBridge+Private.h"
#import "RCTBridge.h"
#import "RCTLog.h"
#import "RCTUtils.h"
#import <FBReactNativeSpec/FBReactNativeSpec.h>

#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTBridge.h>
#import <React/RCTLog.h>
#import <React/RCTUtils.h>
#import <React/RCTConvert.h>

#import "CoreModulesPlugins.h"

static const NSTimeInterval kMinimumSleepInterval = 1;

Expand Down Expand Up @@ -91,6 +96,9 @@ - (void)timerDidFire

@end

@interface RCTTiming() <NativeTimingSpec>
@end

@implementation RCTTiming
{
NSMutableDictionary<NSNumber *, _RCTTimer *> *_timers;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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];
Expand All @@ -437,4 +447,13 @@ - (void)createTimerForNextFrame:(nonnull NSNumber *)callbackID
}
}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
{
return std::make_shared<facebook::react::NativeTimingSpecJSI>(self, jsInvoker);
}

@end

Class RCTTimingCls(void) {
return RCTTiming.class;
}
16 changes: 9 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2778,14 +2778,16 @@ eslint-scope@^4.0.0:
estraverse "^4.1.1"

eslint-utils@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.3.1.tgz#9a851ba89ee7c460346f97cf8939c7298827e512"
integrity sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==
version "1.4.2"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.4.2.tgz#166a5180ef6ab7eb462f162fd0e6f2463d7309ab"
integrity sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==
dependencies:
eslint-visitor-keys "^1.0.0"

eslint-visitor-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz#3f3180fb2e291017716acb4c9d6d5b5c34a6a81d"
integrity sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==
version "1.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==

eslint@5.1.0:
version "5.1.0"
Expand Down Expand Up @@ -5508,7 +5510,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:
Expand Down