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
|
|
|
|
2018-12-05 15:00:35 -08:00
|
|
|
#include <react/config/ReactNativeConfig.h>
|
2018-11-10 14:19:08 -08:00
|
|
|
#include <react/core/ComponentDescriptor.h>
|
|
|
|
#include <react/core/LayoutConstraints.h>
|
2019-01-16 12:01:45 -08:00
|
|
|
#include <react/uimanager/ComponentDescriptorFactory.h>
|
2018-11-10 14:19:08 -08:00
|
|
|
#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>
|
2018-11-21 17:10:30 -08:00
|
|
|
#include <react/uimanager/ShadowTreeRegistry.h>
|
2018-11-10 14:19:08 -08:00
|
|
|
#include <react/uimanager/UIManagerBinding.h>
|
|
|
|
#include <react/uimanager/UIManagerDelegate.h>
|
|
|
|
#include <react/uimanager/primitives.h>
|
2018-04-10 12:46:20 -07:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scheduler coordinates Shadow Tree updates and event flows.
|
|
|
|
*/
|
2018-10-09 16:25:13 -07:00
|
|
|
class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
|
|
|
|
public:
|
2019-01-16 12:01:45 -08:00
|
|
|
Scheduler(
|
|
|
|
const SharedContextContainer &contextContainer,
|
|
|
|
ComponentRegistryFactory buildRegistryFunction);
|
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 = {},
|
mostly working on Android + OTA
Summary:
It works great on iOS, and mostly works on Android, and is now OTA'able as part of the screen config! Haven't done template view yet. One remaining issue:
Layout is borked on Android. I'm guessing the issue has to do with the timing of setting the constraints in `updateRootLayoutSpecs` and calling `mBinding.startSurface` which actually builds the shadow tree. If I try to call `updateRootLayoutSpecs` earlier, it just crashes immediately. Here's the layout it spits out, which clearly has -440 for the x of 420006, which is the RCTText component, causing it to get cut off on the left of the screen:
```
updateLayoutMountItem for reactTag: 420006 x: -440, y: -13, width: 931, height: 78
updateLayoutMountItem for reactTag: 420010 x: 26, y: 79, width: 0, height: 1651
updateLayoutMountItem for reactTag: 420012 x: 0, y: 26, width: 0, height: 158
updateLayoutMountItem for reactTag: 420016 x: 0, y: 210, width: 454, height: 454
updateLayoutMountItem for reactTag: 420018 x: 454, y: 210, width: 455, height: 454
updateLayoutMountItem for reactTag: 420022 x: 0, y: 690, width: 454, height: 454
updateLayoutMountItem for reactTag: 420024 x: 454, y: 690, width: 455, height: 454
updateLayoutMountItem for reactTag: 420028 x: 0, y: 1171, width: 454, height: 454
updateLayoutMountItem for reactTag: 420030 x: 454, y: 1171, width: 455, height: 454
updateLayoutMountItem for reactTag: 420032 x: 0, y: 1651, width: 0, height: 0
```
Reviewed By: mdvacca
Differential Revision: D12813192
fbshipit-source-id: 450d646af4883ff25184141721351da67b091b7c
2018-11-05 15:32:47 -08:00
|
|
|
const LayoutContext &layoutContext = {}) const;
|
|
|
|
|
|
|
|
void renderTemplateToSurface(
|
|
|
|
SurfaceId surfaceId,
|
|
|
|
const std::string &uiTemplate);
|
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(
|
2018-11-21 17:10:30 -08:00
|
|
|
SurfaceId surfaceId,
|
2019-02-04 17:24:23 -08:00
|
|
|
const SharedShadowNodeUnsharedList &rootChildNodes,
|
|
|
|
long startCommitTime) override;
|
2018-10-09 16:25:13 -07:00
|
|
|
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,
|
2019-02-04 17:24:23 -08:00
|
|
|
const ShadowViewMutationList &mutations,
|
|
|
|
long commitStartTime,
|
|
|
|
long layoutTime) const override;
|
2018-05-08 22:56:16 -07:00
|
|
|
|
2018-10-09 16:25:13 -07:00
|
|
|
private:
|
2018-04-10 12:46:20 -07:00
|
|
|
SchedulerDelegate *delegate_;
|
2018-10-10 19:51:29 -07:00
|
|
|
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
2018-11-21 17:10:30 -08:00
|
|
|
ShadowTreeRegistry shadowTreeRegistry_;
|
2018-11-06 10:58:51 -08:00
|
|
|
RuntimeExecutor runtimeExecutor_;
|
|
|
|
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
|
2018-12-05 15:00:35 -08:00
|
|
|
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
|
2018-04-10 12:46:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|