2018-09-11 15:27:47 -07:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates.
|
2018-05-31 15:31:03 -07:00
|
|
|
|
|
|
|
// This source code is licensed under the MIT license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree.
|
2018-04-10 12:46:20 -07:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2018-09-26 10:02:04 -07:00
|
|
|
#include <mutex>
|
2018-04-10 12:46:20 -07:00
|
|
|
|
|
|
|
#include <fabric/core/ComponentDescriptor.h>
|
|
|
|
#include <fabric/core/LayoutConstraints.h>
|
2018-10-10 19:51:29 -07:00
|
|
|
#include <fabric/uimanager/ComponentDescriptorRegistry.h>
|
2018-06-22 07:28:34 -07:00
|
|
|
#include <fabric/uimanager/ContextContainer.h>
|
2018-04-10 12:46:20 -07:00
|
|
|
#include <fabric/uimanager/SchedulerDelegate.h>
|
2018-05-08 22:56:16 -07:00
|
|
|
#include <fabric/uimanager/ShadowTree.h>
|
|
|
|
#include <fabric/uimanager/ShadowTreeDelegate.h>
|
2018-10-09 16:25:13 -07:00
|
|
|
#include <fabric/uimanager/UIManagerDelegate.h>
|
2018-04-10 12:46:20 -07:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class FabricUIManager;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scheduler coordinates Shadow Tree updates and event flows.
|
|
|
|
*/
|
2018-10-09 16:25:13 -07:00
|
|
|
class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
|
|
|
|
public:
|
2018-06-22 07:28:34 -07:00
|
|
|
Scheduler(const SharedContextContainer &contextContainer);
|
2018-05-08 22:56:16 -07:00
|
|
|
~Scheduler();
|
2018-04-10 12:46:20 -07:00
|
|
|
|
2018-09-26 10:02:04 -07:00
|
|
|
#pragma mark - Surface Management
|
|
|
|
|
|
|
|
void startSurface(
|
2018-10-09 16:25:13 -07:00
|
|
|
SurfaceId surfaceId,
|
|
|
|
const std::string &moduleName,
|
|
|
|
const folly::dynamic &initialProps,
|
|
|
|
const LayoutConstraints &layoutConstraints = {},
|
2018-10-10 19:51:29 -07:00
|
|
|
const LayoutContext &layoutContext = {});
|
2018-09-26 10:02:04 -07:00
|
|
|
|
|
|
|
void stopSurface(SurfaceId surfaceId) const;
|
2018-04-10 12:46:20 -07:00
|
|
|
|
2018-09-26 10:02:04 -07:00
|
|
|
Size measureSurface(
|
2018-10-09 16:25:13 -07:00
|
|
|
SurfaceId surfaceId,
|
|
|
|
const LayoutConstraints &layoutConstraints,
|
|
|
|
const LayoutContext &layoutContext) const;
|
2018-04-10 12:46:20 -07:00
|
|
|
|
2018-10-09 16:25:01 -07:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-10-09 16:25:03 -07:00
|
|
|
void constraintSurfaceLayout(
|
2018-10-09 16:25:13 -07:00
|
|
|
SurfaceId surfaceId,
|
|
|
|
const LayoutConstraints &layoutConstraints,
|
|
|
|
const LayoutContext &layoutContext) const;
|
2018-04-10 12:46:20 -07:00
|
|
|
|
|
|
|
#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);
|
2018-05-08 22:56:16 -07:00
|
|
|
SchedulerDelegate *getDelegate() const;
|
2018-04-10 12:46:20 -07:00
|
|
|
|
|
|
|
#pragma mark - UIManagerDelegate
|
|
|
|
|
2018-10-09 16:25:13 -07:00
|
|
|
void uiManagerDidFinishTransaction(
|
|
|
|
Tag rootTag,
|
|
|
|
const SharedShadowNodeUnsharedList &rootChildNodes) override;
|
|
|
|
void uiManagerDidCreateShadowNode(
|
|
|
|
const SharedShadowNode &shadowNode) override;
|
2018-04-10 12:46:20 -07:00
|
|
|
|
2018-05-08 22:56:16 -07:00
|
|
|
#pragma mark - ShadowTreeDelegate
|
|
|
|
|
2018-10-09 16:25:13 -07:00
|
|
|
void shadowTreeDidCommit(
|
|
|
|
const ShadowTree &shadowTree,
|
|
|
|
const ShadowViewMutationList &mutations) const override;
|
2018-05-08 22:56:16 -07:00
|
|
|
|
2018-04-10 12:46:20 -07:00
|
|
|
#pragma mark - Deprecated
|
|
|
|
|
|
|
|
/*
|
|
|
|
* UIManager instance must be temporarily exposed for registration purposes.
|
|
|
|
*/
|
|
|
|
std::shared_ptr<FabricUIManager> getUIManager_DO_NOT_USE();
|
|
|
|
|
2018-10-09 16:25:13 -07:00
|
|
|
private:
|
2018-04-10 12:46:20 -07:00
|
|
|
SchedulerDelegate *delegate_;
|
|
|
|
std::shared_ptr<FabricUIManager> uiManager_;
|
2018-10-10 19:51:29 -07:00
|
|
|
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
2018-09-26 10:02:04 -07:00
|
|
|
mutable std::mutex mutex_;
|
2018-10-09 16:25:13 -07:00
|
|
|
mutable std::unordered_map<SurfaceId, std::unique_ptr<ShadowTree>>
|
|
|
|
shadowTreeRegistry_; // Protected by `mutex_`.
|
2018-08-27 07:21:26 -07:00
|
|
|
SharedEventDispatcher eventDispatcher_;
|
2018-06-22 07:28:34 -07:00
|
|
|
SharedContextContainer contextContainer_;
|
2018-10-10 19:51:29 -07:00
|
|
|
|
|
|
|
void uiManagerDidFinishTransactionWithoutLock(Tag rootTag, const SharedShadowNodeUnsharedList &rootChildNodes);
|
|
|
|
|
2018-04-10 12:46:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|