// Copyright 2004-present Facebook. All Rights Reserved. #include "Scheduler.h" #include #include #include #include #include #include #include "Differentiator.h" namespace facebook { namespace react { Scheduler::Scheduler() { auto componentDescriptorRegistry = std::make_shared(); SharedComponentDescriptor viewComponentDescriptor = std::make_shared(); componentDescriptorRegistry->registerComponentDescriptor(viewComponentDescriptor); uiManager_ = std::make_shared(componentDescriptorRegistry); uiManager_->setDelegate(this); } Scheduler::~Scheduler() { uiManager_->setDelegate(nullptr); } void Scheduler::registerRootTag(Tag rootTag) { auto rootShadowNode = std::make_shared(rootTag, rootTag, nullptr); rootNodeRegistry_.insert({rootTag, rootShadowNode}); } void Scheduler::unregisterRootTag(Tag rootTag) { rootNodeRegistry_.erase(rootTag); } #pragma mark - Delegate void Scheduler::setDelegate(SchedulerDelegate *delegate) { delegate_ = delegate; } SchedulerDelegate *Scheduler::getDelegate() { return delegate_; } #pragma mark - UIManagerDelegate void Scheduler::uiManagerDidFinishTransaction(Tag rootTag, const SharedShadowNodeUnsharedList &rootChildNodes) { SharedRootShadowNode oldRootShadowNode = rootNodeRegistry_[rootTag]; assert(oldRootShadowNode); SharedRootShadowNode newRootShadowNode = std::make_shared(oldRootShadowNode, nullptr, SharedShadowNodeSharedList(rootChildNodes)); auto nonConstOldRootShadowNode = std::const_pointer_cast(oldRootShadowNode); auto nonConstNewRootShadowNode = std::const_pointer_cast(newRootShadowNode); LayoutContext layoutContext = LayoutContext(); layoutContext.affectedShadowNodes = std::make_shared>(); LOG(INFO) << "Old Shadow Tree: \n" << oldRootShadowNode->getDebugDescription(); LOG(INFO) << "New Shadow Tree *before* layout: \n" << newRootShadowNode->getDebugDescription(); nonConstNewRootShadowNode->layout(layoutContext); nonConstNewRootShadowNode->sealRecursive(); LOG(INFO) << "New Shadow Tree *after* layout: \n" << nonConstNewRootShadowNode->getDebugDescription(); TreeMutationInstructionList instructions = TreeMutationInstructionList(); calculateMutationInstructions( instructions, oldRootShadowNode, oldRootShadowNode->ShadowNode::getChildren(), newRootShadowNode->ShadowNode::getChildren() ); LOG(INFO) << "TreeMutationInstructionList:"; for (auto instruction : instructions) { LOG(INFO) << "Instruction: " << instruction.getDebugDescription(); } rootNodeRegistry_[rootTag] = newRootShadowNode; if (delegate_) { delegate_->schedulerDidComputeMutationInstructions(rootTag, instructions); } } void Scheduler::uiManagerDidCreateShadowNode(const SharedShadowNode &shadowNode) { if (delegate_) { delegate_->schedulerDidRequestPreliminaryViewAllocation(shadowNode->getComponentName()); } } #pragma mark - Deprecated std::shared_ptr Scheduler::getUIManager_DO_NOT_USE() { return uiManager_; } } // namespace react } // namespace facebook