Fabric: Introducing RCTScheduler

Summary:
RCTScheduler represent facebook::react::Scheduler as a Obejctive-C object.
It supposed to be single, unified, bidirectional interop layer between C++ and Obejctive-C worlds.

Reviewed By: mdvacca

Differential Revision: D7526405

fbshipit-source-id: a206755f64f2904981b356a40e7659922b24d7bb
This commit is contained in:
Valentin Shergin 2018-04-10 16:37:01 -07:00 committed by Facebook Github Bot
parent 00f44248b3
commit 515d49ed1c
2 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,49 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* 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 <memory>
#import <React/RCTPrimitives.h>
#import <fabric/uimanager/FabricUIManager.h>
#import <fabric/uimanager/TreeMutationInstruction.h>
NS_ASSUME_NONNULL_BEGIN
@class RCTMountingManager;
/**
* Exacly same semantic as `facebook::react::SchedulerDelegate`.
*/
@protocol RCTSchedulerDelegate
- (void)schedulerDidComputeMutationInstructions:(facebook::react::TreeMutationInstructionList)instructions rootTag:(ReactTag)rootTag;
- (void)schedulerDidRequestPreliminaryViewAllocationWithComponentName:(NSString *)componentName;
@end
/**
* `facebook::react::Scheduler` as an Objective-C class.
*/
@interface RCTScheduler : NSObject
@property (atomic, weak, nullable) id<RCTSchedulerDelegate> delegate;
- (void)registerRootTag:(ReactTag)tag;
- (void)unregisterRootTag:(ReactTag)tag;
@end
@interface RCTScheduler (Deprecated)
- (std::shared_ptr<facebook::react::FabricUIManager>)uiManager_DO_NOT_USE;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,73 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTScheduler.h"
#import <fabric/uimanager/Scheduler.h>
#import <fabric/uimanager/SchedulerDelegate.h>
using namespace facebook::react;
class SchedulerDelegateProxy: public SchedulerDelegate {
public:
SchedulerDelegateProxy(void *scheduler): scheduler_(scheduler) {}
void schedulerDidComputeMutationInstructions(Tag rootTag, const TreeMutationInstructionList &instructions) override {
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerDidComputeMutationInstructions:instructions rootTag:rootTag];
}
void schedulerDidRequestPreliminaryViewAllocation(ComponentName componentName) override {
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerDidRequestPreliminaryViewAllocationWithComponentName:[NSString stringWithCString:componentName.c_str() encoding:NSASCIIStringEncoding]];
}
private:
void *scheduler_;
};
@implementation RCTScheduler {
std::shared_ptr<Scheduler> _scheduler;
std::shared_ptr<SchedulerDelegateProxy> _delegateProxy;
}
- (instancetype)init
{
if (self = [super init]) {
_delegateProxy = std::make_shared<SchedulerDelegateProxy>((__bridge void *)self);
_scheduler = std::make_shared<Scheduler>();
_scheduler->setDelegate(_delegateProxy.get());
}
return self;
}
- (void)dealloc
{
_scheduler->setDelegate(nullptr);
}
- (void)registerRootTag:(ReactTag)tag
{
_scheduler->registerRootTag(tag);
}
- (void)unregisterRootTag:(ReactTag)tag
{
_scheduler->unregisterRootTag(tag);
}
@end
@implementation RCTScheduler (Deprecated)
- (std::shared_ptr<FabricUIManager>)uiManager_DO_NOT_USE
{
return _scheduler->getUIManager_DO_NOT_USE();
}
@end