Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Bridgeless files to OSS folders #37066

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <UIKit/UIKit.h>

#import <PikaOptimizationsMacros/PikaOptimizationsMacros.h>
#import <React/RCTTiming.h>
#import <react/bridgeless/PlatformTimerRegistry.h>
#import <react/bridgeless/TimerManager.h>

@interface RCTJSTimerExecutor : NSObject <RCTTimingDelegate>

- (void)setTimerManager:(std::weak_ptr<facebook::react::TimerManager>)timerManager FB_OBJC_DIRECT;

@end

class ObjCTimerRegistry : public facebook::react::PlatformTimerRegistry {
public:
ObjCTimerRegistry();
void createTimer(uint32_t timerID, double delayMS) override;
void deleteTimer(uint32_t timerID) override;
void createRecurringTimer(uint32_t timerID, double delayMS) override;
void setTimerManager(std::weak_ptr<facebook::react::TimerManager> timerManager);
RCTTiming *_Null_unspecified timing;

private:
RCTJSTimerExecutor *_Null_unspecified jsTimerExecutor_;
double toSeconds(double ms);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import "ObjCTimerRegistry.h"

@implementation RCTJSTimerExecutor {
std::weak_ptr<facebook::react::TimerManager> _timerManager;
}

- (void)setTimerManager:(std::weak_ptr<facebook::react::TimerManager>)timerManager
{
_timerManager = timerManager;
}

- (void)callTimers:(NSArray<NSNumber *> *)timers
{
if (auto timerManager = _timerManager.lock()) {
for (NSNumber *timer in timers) {
timerManager->callTimer([timer unsignedIntValue]);
}
}
}

- (void)immediatelyCallTimer:(nonnull NSNumber *)callbackID
{
if (auto timerManager = _timerManager.lock()) {
timerManager->callTimer([callbackID unsignedIntValue]);
}
}

- (void)callIdleCallbacks:(nonnull NSNumber *)absoluteFrameStartMS
{
// TODO(T53992765)(petetheheat) - Implement this
}

@end

ObjCTimerRegistry::ObjCTimerRegistry()
{
jsTimerExecutor_ = [RCTJSTimerExecutor new];
timing = [[RCTTiming alloc] initWithDelegate:jsTimerExecutor_];
}

void ObjCTimerRegistry::createTimer(uint32_t timerID, double delayMS)
{
[timing createTimerForNextFrame:@(timerID) duration:toSeconds(delayMS) jsSchedulingTime:nil repeats:NO];
}

void ObjCTimerRegistry::deleteTimer(uint32_t timerID)
{
[timing deleteTimer:(double)timerID];
}

void ObjCTimerRegistry::createRecurringTimer(uint32_t timerID, double delayMS)
{
[timing createTimerForNextFrame:@(timerID) duration:toSeconds(delayMS) jsSchedulingTime:nil repeats:YES];
}

void ObjCTimerRegistry::setTimerManager(std::weak_ptr<facebook::react::TimerManager> timerManager)
{
[jsTimerExecutor_ setTimerManager:timerManager];
}

// ObjC timing native module expects a NSTimeInterval which is always specified in seconds. JS expresses timer delay
// in ms. Perform a simple conversion here.
double ObjCTimerRegistry::toSeconds(double ms)
{
return ms / 1000.0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import <Foundation/Foundation.h>

#import <PikaOptimizationsMacros/PikaOptimizationsMacros.h>
#import <React/RCTDefines.h>
#import <react/bridgeless/JSEngineInstance.h>
#import <react/bridgeless/ReactInstance.h>
#import <react/renderer/core/ReactPrimitives.h>

#import "RCTInstance.h"

NS_ASSUME_NONNULL_BEGIN

@class RCTFabricSurface;
@class RCTJSThreadManager;
@class RCTModuleRegistry;
@class RCTPerformanceLogger;
@protocol RCTInstanceDelegate;
FB_RUNTIME_PROTOCOL
@protocol RCTTurboModuleManagerDelegate;

/**
* This notification fires just before RCTHost releases it's RCTInstance reference.
*/
RCT_EXTERN NSString *const RCTHostWillReloadNotification;

/**
* This notification fires just after RCTHost releases it's RCTInstance reference.
*/
RCT_EXTERN NSString *const RCTHostDidReloadNotification;

@protocol RCTHostDelegate <NSObject>

- (std::shared_ptr<facebook::react::JSEngineInstance>)getJSEngine;
- (NSURL *)getBundleURL;

@end

/**
* RCTHost is an object which is responsible for managing the lifecycle of a single RCTInstance.
* RCTHost is long lived, while an instance may be deallocated and re-initialized. Some examples of when this happens:
* CMD+R reload in DEV or a JS crash. The host should be the single owner of an RCTInstance.
*/
@interface RCTHost : NSObject <ReactInstanceForwarding>

- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
instanceDelegate:(id<RCTInstanceDelegate>)instanceDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
bindingsInstallFunc:(facebook::react::ReactInstance::BindingsInstallFunc)bindingsInstallFunc
jsErrorHandlingFunc:(facebook::react::JsErrorHandler::JsErrorHandlingFunc)jsErrorHandlingFunc
NS_DESIGNATED_INITIALIZER FB_OBJC_DIRECT;

/**
* This function initializes an RCTInstance if one does not yet exist. This function is currently only called on the
* main thread, but it should be threadsafe.
* TODO T74233481 - Verify if this function is threadsafe.
*/
- (void)preload;

- (RCTFabricSurface *)createSurfaceWithModuleName:(NSString *)moduleName
mode:(facebook::react::DisplayMode)displayMode
initialProperties:(NSDictionary *)properties FB_OBJC_DIRECT;

- (RCTFabricSurface *)createSurfaceWithModuleName:(NSString *)moduleName
initialProperties:(NSDictionary *)properties FB_OBJC_DIRECT;

- (RCTJSThreadManager *)getJSThreadManager FB_OBJC_DIRECT;

- (RCTModuleRegistry *)getModuleRegistry FB_OBJC_DIRECT;

- (RCTPerformanceLogger *)getPerformanceLogger FB_OBJC_DIRECT;

- (RCTSurfacePresenter *)getSurfacePresenter FB_OBJC_DIRECT;

@end

NS_ASSUME_NONNULL_END
Loading