Valentin Shergin b4fa1fa0c6 Fabric: Introducing ShadowTreeRegistry
Summary:
Why do we need a dedicated registry class?
* We need to simplify registry-related logic in Scheduler.
* We need to couple threading aspect of the registry with the registry itself, otherwise it's not clear why exactly we acquire the mutex. We also should not acquire the mutex in a per-method way (as we did before), because it's incorrect and misleading (only lines that access the registry should by protected).
* We need to have a way to share the registry with other classes (e.g. UIManager) without passing a reference to the whole Scheduler.

Reviewed By: mdvacca

Differential Revision: D13036550

fbshipit-source-id: 644da910e823666c586834a3da2b4cdcb90eebb2
2018-11-21 17:16:48 -08:00

101 lines
3.0 KiB
C++

// Copyright (c) Facebook, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#pragma once
#include <memory>
#include <mutex>
#include <react/core/ComponentDescriptor.h>
#include <react/core/LayoutConstraints.h>
#include <react/uimanager/ComponentDescriptorRegistry.h>
#include <react/uimanager/ContextContainer.h>
#include <react/uimanager/SchedulerDelegate.h>
#include <react/uimanager/ShadowTree.h>
#include <react/uimanager/ShadowTreeDelegate.h>
#include <react/uimanager/ShadowTreeRegistry.h>
#include <react/uimanager/UIManagerBinding.h>
#include <react/uimanager/UIManagerDelegate.h>
#include <react/uimanager/primitives.h>
namespace facebook {
namespace react {
/*
* Scheduler coordinates Shadow Tree updates and event flows.
*/
class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
public:
Scheduler(const SharedContextContainer &contextContainer);
~Scheduler();
#pragma mark - Surface Management
void startSurface(
SurfaceId surfaceId,
const std::string &moduleName,
const folly::dynamic &initialProps,
const LayoutConstraints &layoutConstraints = {},
const LayoutContext &layoutContext = {}) const;
void renderTemplateToSurface(
SurfaceId surfaceId,
const std::string &uiTemplate);
void stopSurface(SurfaceId surfaceId) const;
Size measureSurface(
SurfaceId surfaceId,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext) const;
/*
* Applies given `layoutConstraints` and `layoutContext` to a Surface.
* The user interface will be relaid out as a result. The operation will be
* performed synchronously (including mounting) if the method is called
* on the main thread.
* Can be called from any thread.
*/
void constraintSurfaceLayout(
SurfaceId surfaceId,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext) const;
#pragma mark - Delegate
/*
* Sets and gets the Scheduler's delegate.
* The delegate is stored as a raw pointer, so the owner must null
* the pointer before being destroyed.
*/
void setDelegate(SchedulerDelegate *delegate);
SchedulerDelegate *getDelegate() const;
#pragma mark - UIManagerDelegate
void uiManagerDidFinishTransaction(
SurfaceId surfaceId,
const SharedShadowNodeUnsharedList &rootChildNodes) override;
void uiManagerDidCreateShadowNode(
const SharedShadowNode &shadowNode) override;
#pragma mark - ShadowTreeDelegate
void shadowTreeDidCommit(
const ShadowTree &shadowTree,
const ShadowViewMutationList &mutations) const override;
private:
SchedulerDelegate *delegate_;
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
ShadowTreeRegistry shadowTreeRegistry_;
SharedContextContainer contextContainer_;
RuntimeExecutor runtimeExecutor_;
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
};
} // namespace react
} // namespace facebook