Valentin Shergin eabf29e320 Fabric: Getting rid of many auto &&
Summary:
@public
After reading about move-semantic and rvalue refs I realized that we (I) definitely overuse  `auto &&` (aka universal reference) construction. Even if this is harmless, does not look good and idiomatic.
Whenever I used that from a semantical point of view I always meant  "I need an alias for this" which is actually "read-only reference" which is `const auto &`.
This is also fit good to our policy where "everything is const (immutable) by default".
Hence I change that to how it should be.

Reviewed By: fkgozali

Differential Revision: D8475637

fbshipit-source-id: 0a691ededa0e798db8ffa053bff0f400913ab7b8
2018-06-22 07:32:49 -07:00

109 lines
3.5 KiB
C++

// Copyright (c) 2004-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.
#include "Scheduler.h"
#include <fabric/core/LayoutContext.h>
#include <fabric/scrollview/ScrollViewComponentDescriptor.h>
#include <fabric/text/ParagraphComponentDescriptor.h>
#include <fabric/text/RawTextComponentDescriptor.h>
#include <fabric/text/TextComponentDescriptor.h>
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
#include <fabric/uimanager/FabricUIManager.h>
#include <fabric/view/ViewComponentDescriptor.h>
#include <fabric/view/ViewProps.h>
#include <fabric/view/ViewShadowNode.h>
#include "ComponentDescriptorFactory.h"
#include "Differentiator.h"
namespace facebook {
namespace react {
Scheduler::Scheduler(const SharedContextContainer &contextContainer):
contextContainer_(contextContainer) {
const auto &eventDispatcher = std::make_shared<SchedulerEventDispatcher>();
const auto &componentDescriptorRegistry = ComponentDescriptorFactory::buildRegistry(eventDispatcher, contextContainer);
uiManager_ = std::make_shared<FabricUIManager>(componentDescriptorRegistry);
uiManager_->setDelegate(this);
eventDispatcher->setUIManager(uiManager_);
eventDispatcher_ = eventDispatcher;
}
Scheduler::~Scheduler() {
uiManager_->setDelegate(nullptr);
eventDispatcher_->setUIManager(nullptr);
}
void Scheduler::registerRootTag(Tag rootTag) {
const auto &shadowTree = std::make_shared<ShadowTree>(rootTag);
shadowTree->setDelegate(this);
shadowTreeRegistry_.insert({rootTag, shadowTree});
}
void Scheduler::unregisterRootTag(Tag rootTag) {
const auto &iterator = shadowTreeRegistry_.find(rootTag);
const auto &shadowTree = iterator->second;
assert(shadowTree);
shadowTree->setDelegate(nullptr);
shadowTreeRegistry_.erase(iterator);
}
Size Scheduler::measure(const Tag &rootTag, const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const {
const auto &shadowTree = shadowTreeRegistry_.at(rootTag);
assert(shadowTree);
return shadowTree->measure(layoutConstraints, layoutContext);
}
void Scheduler::constraintLayout(const Tag &rootTag, const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) {
const auto &shadowTree = shadowTreeRegistry_.at(rootTag);
assert(shadowTree);
return shadowTree->constraintLayout(layoutConstraints, layoutContext);
}
#pragma mark - Delegate
void Scheduler::setDelegate(SchedulerDelegate *delegate) {
delegate_ = delegate;
}
SchedulerDelegate *Scheduler::getDelegate() const {
return delegate_;
}
#pragma mark - ShadowTreeDelegate
void Scheduler::shadowTreeDidCommit(const SharedShadowTree &shadowTree, const TreeMutationInstructionList &instructions) {
if (delegate_) {
delegate_->schedulerDidComputeMutationInstructions(shadowTree->getRootTag(), instructions);
}
}
#pragma mark - UIManagerDelegate
void Scheduler::uiManagerDidFinishTransaction(Tag rootTag, const SharedShadowNodeUnsharedList &rootChildNodes) {
const auto &iterator = shadowTreeRegistry_.find(rootTag);
const auto &shadowTree = iterator->second;
assert(shadowTree);
return shadowTree->complete(rootChildNodes);
}
void Scheduler::uiManagerDidCreateShadowNode(const SharedShadowNode &shadowNode) {
if (delegate_) {
delegate_->schedulerDidRequestPreliminaryViewAllocation(shadowNode->getComponentName());
}
}
#pragma mark - Deprecated
std::shared_ptr<FabricUIManager> Scheduler::getUIManager_DO_NOT_USE() {
return uiManager_;
}
} // namespace react
} // namespace facebook