2018-09-12 01:27:47 +03:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates.
|
2018-06-01 01:31:03 +03: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 22:46:20 +03:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2018-09-26 20:02:04 +03:00
|
|
|
#include <mutex>
|
2018-04-10 22:46:20 +03:00
|
|
|
|
2019-03-04 00:47:14 +03:00
|
|
|
#include <react/components/root/RootComponentDescriptor.h>
|
2018-12-06 02:00:35 +03:00
|
|
|
#include <react/config/ReactNativeConfig.h>
|
2018-11-11 01:19:08 +03:00
|
|
|
#include <react/core/ComponentDescriptor.h>
|
|
|
|
#include <react/core/LayoutConstraints.h>
|
2019-04-01 20:47:04 +03:00
|
|
|
#include <react/mounting/ShadowTree.h>
|
|
|
|
#include <react/mounting/ShadowTreeDelegate.h>
|
|
|
|
#include <react/mounting/ShadowTreeRegistry.h>
|
2019-01-16 23:01:45 +03:00
|
|
|
#include <react/uimanager/ComponentDescriptorFactory.h>
|
2018-11-11 01:19:08 +03:00
|
|
|
#include <react/uimanager/ComponentDescriptorRegistry.h>
|
|
|
|
#include <react/uimanager/SchedulerDelegate.h>
|
2019-06-07 22:00:01 +03:00
|
|
|
#include <react/uimanager/SchedulerToolbox.h>
|
2018-11-11 01:19:08 +03:00
|
|
|
#include <react/uimanager/UIManagerBinding.h>
|
|
|
|
#include <react/uimanager/UIManagerDelegate.h>
|
2019-04-13 01:10:40 +03:00
|
|
|
#include <react/utils/ContextContainer.h>
|
2019-07-25 05:37:22 +03:00
|
|
|
#include <react/utils/RuntimeExecutor.h>
|
2018-04-10 22:46:20 +03:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scheduler coordinates Shadow Tree updates and event flows.
|
|
|
|
*/
|
2018-10-10 02:25:13 +03:00
|
|
|
class Scheduler final : public UIManagerDelegate, public ShadowTreeDelegate {
|
|
|
|
public:
|
2019-07-29 20:38:10 +03:00
|
|
|
Scheduler(SchedulerToolbox schedulerToolbox, SchedulerDelegate *delegate);
|
2018-05-09 08:56:16 +03:00
|
|
|
~Scheduler();
|
2018-04-10 22:46:20 +03:00
|
|
|
|
2018-09-26 20:02:04 +03:00
|
|
|
#pragma mark - Surface Management
|
|
|
|
|
|
|
|
void startSurface(
|
2018-10-10 02:25:13 +03: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-06 02:32:47 +03:00
|
|
|
const LayoutContext &layoutContext = {}) const;
|
|
|
|
|
|
|
|
void renderTemplateToSurface(
|
|
|
|
SurfaceId surfaceId,
|
|
|
|
const std::string &uiTemplate);
|
2018-09-26 20:02:04 +03:00
|
|
|
|
|
|
|
void stopSurface(SurfaceId surfaceId) const;
|
2018-04-10 22:46:20 +03:00
|
|
|
|
2018-09-26 20:02:04 +03:00
|
|
|
Size measureSurface(
|
2018-10-10 02:25:13 +03:00
|
|
|
SurfaceId surfaceId,
|
|
|
|
const LayoutConstraints &layoutConstraints,
|
|
|
|
const LayoutContext &layoutContext) const;
|
2018-04-10 22:46:20 +03:00
|
|
|
|
2018-10-10 02:25:01 +03: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-10 02:25:03 +03:00
|
|
|
void constraintSurfaceLayout(
|
2018-10-10 02:25:13 +03:00
|
|
|
SurfaceId surfaceId,
|
|
|
|
const LayoutConstraints &layoutConstraints,
|
|
|
|
const LayoutContext &layoutContext) const;
|
2018-04-10 22:46:20 +03:00
|
|
|
|
2019-02-25 23:22:24 +03:00
|
|
|
const ComponentDescriptor &getComponentDescriptor(ComponentHandle handle);
|
|
|
|
|
2018-04-10 22:46:20 +03: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-09 08:56:16 +03:00
|
|
|
SchedulerDelegate *getDelegate() const;
|
2018-04-10 22:46:20 +03:00
|
|
|
|
|
|
|
#pragma mark - UIManagerDelegate
|
|
|
|
|
2018-10-10 02:25:13 +03:00
|
|
|
void uiManagerDidFinishTransaction(
|
2018-11-22 04:10:30 +03:00
|
|
|
SurfaceId surfaceId,
|
2019-05-04 01:05:26 +03:00
|
|
|
const SharedShadowNodeUnsharedList &rootChildNodes) override;
|
2018-10-10 02:25:13 +03:00
|
|
|
void uiManagerDidCreateShadowNode(
|
|
|
|
const SharedShadowNode &shadowNode) override;
|
2019-07-31 08:39:15 +03:00
|
|
|
void uiManagerDidDispatchCommand(
|
2019-07-19 21:45:40 +03:00
|
|
|
const SharedShadowNode &shadowNode,
|
|
|
|
std::string const &commandName,
|
|
|
|
folly::dynamic const args) override;
|
2018-04-10 22:46:20 +03:00
|
|
|
|
2018-05-09 08:56:16 +03:00
|
|
|
#pragma mark - ShadowTreeDelegate
|
|
|
|
|
2018-10-10 02:25:13 +03:00
|
|
|
void shadowTreeDidCommit(
|
2019-05-04 01:05:26 +03:00
|
|
|
ShadowTree const &shadowTree,
|
|
|
|
MountingCoordinator::Shared const &mountingCoordinator) const override;
|
2018-05-09 08:56:16 +03:00
|
|
|
|
2018-10-10 02:25:13 +03:00
|
|
|
private:
|
2018-04-10 22:46:20 +03:00
|
|
|
SchedulerDelegate *delegate_;
|
2018-10-11 05:51:29 +03:00
|
|
|
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
|
2019-03-04 00:47:14 +03:00
|
|
|
std::unique_ptr<const RootComponentDescriptor> rootComponentDescriptor_;
|
2018-11-22 04:10:30 +03:00
|
|
|
ShadowTreeRegistry shadowTreeRegistry_;
|
2018-11-06 21:58:51 +03:00
|
|
|
RuntimeExecutor runtimeExecutor_;
|
|
|
|
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
|
2018-12-06 02:00:35 +03:00
|
|
|
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
|
2018-04-10 22:46:20 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|