2018-04-10 23:37:01 +00:00
|
|
|
/**
|
|
|
|
* 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"
|
|
|
|
|
2018-06-22 14:28:38 +00:00
|
|
|
#import <fabric/imagemanager/ImageManager.h>
|
2018-06-22 14:28:34 +00:00
|
|
|
#import <fabric/uimanager/ContextContainer.h>
|
2018-04-10 23:37:01 +00:00
|
|
|
#import <fabric/uimanager/Scheduler.h>
|
|
|
|
#import <fabric/uimanager/SchedulerDelegate.h>
|
2018-06-22 14:28:38 +00:00
|
|
|
#import <React/RCTImageLoader.h>
|
|
|
|
#import <React/RCTBridge+Private.h>
|
2018-04-10 23:37:01 +00:00
|
|
|
|
2018-05-09 05:56:27 +00:00
|
|
|
#import "RCTConversions.h"
|
|
|
|
|
2018-04-10 23:37:01 +00:00
|
|
|
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_;
|
2018-06-22 18:53:44 +00:00
|
|
|
[scheduler.delegate schedulerDidRequestPreliminaryViewAllocationWithComponentName:RCTNSStringFromString(componentName, NSASCIIStringEncoding)];
|
2018-04-10 23:37:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-06-22 14:28:34 +00:00
|
|
|
|
|
|
|
SharedContextContainer contextContainer = std::make_shared<ContextContainer>();
|
2018-06-22 14:28:38 +00:00
|
|
|
|
|
|
|
void *imageLoader = (__bridge void *)[[RCTBridge currentBridge] imageLoader];
|
|
|
|
contextContainer->registerInstance(typeid(ImageManager), std::make_shared<ImageManager>(imageLoader));
|
|
|
|
|
2018-06-22 14:28:34 +00:00
|
|
|
_scheduler = std::make_shared<Scheduler>(contextContainer);
|
2018-04-10 23:37:01 +00:00
|
|
|
_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);
|
|
|
|
}
|
|
|
|
|
2018-05-09 05:56:27 +00:00
|
|
|
- (CGSize)measureWithLayoutConstraints:(LayoutConstraints)layoutConstraints
|
|
|
|
layoutContext:(LayoutContext)layoutContext
|
|
|
|
rootTag:(ReactTag)rootTag
|
|
|
|
{
|
|
|
|
return RCTCGSizeFromSize(_scheduler->measure(rootTag, layoutConstraints, layoutContext));
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)constraintLayoutWithLayoutConstraints:(LayoutConstraints)layoutConstraints
|
|
|
|
layoutContext:(LayoutContext)layoutContext
|
|
|
|
rootTag:(ReactTag)rootTag
|
|
|
|
{
|
|
|
|
_scheduler->constraintLayout(rootTag, layoutConstraints, layoutContext);
|
|
|
|
}
|
|
|
|
|
2018-04-10 23:37:01 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTScheduler (Deprecated)
|
|
|
|
|
|
|
|
- (std::shared_ptr<FabricUIManager>)uiManager_DO_NOT_USE
|
|
|
|
{
|
|
|
|
return _scheduler->getUIManager_DO_NOT_USE();
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|