react-native-macos/ReactCommon/fabric/uimanager/Scheduler.h

112 строки
3.5 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/components/root/RootComponentDescriptor.h>
#include <react/config/ReactNativeConfig.h>
#include <react/core/ComponentDescriptor.h>
#include <react/core/LayoutConstraints.h>
#include <react/mounting/ShadowTree.h>
#include <react/mounting/ShadowTreeDelegate.h>
#include <react/mounting/ShadowTreeRegistry.h>
#include <react/uimanager/ComponentDescriptorFactory.h>
#include <react/uimanager/ComponentDescriptorRegistry.h>
#include <react/uimanager/SchedulerDelegate.h>
#include <react/uimanager/UIManagerBinding.h>
#include <react/uimanager/UIManagerDelegate.h>
#include <react/uimanager/primitives.h>
#include <react/utils/ContextContainer.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,
ComponentRegistryFactory buildRegistryFunction);
~Scheduler();
#pragma mark - Surface Management
void startSurface(
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);
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;
const ComponentDescriptor &getComponentDescriptor(ComponentHandle handle);
#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,
long startCommitTime) override;
void uiManagerDidCreateShadowNode(
const SharedShadowNode &shadowNode) override;
#pragma mark - ShadowTreeDelegate
void shadowTreeDidCommit(
const ShadowTree &shadowTree,
const ShadowViewMutationList &mutations,
long commitStartTime,
long layoutTime) const override;
private:
SchedulerDelegate *delegate_;
SharedComponentDescriptorRegistry componentDescriptorRegistry_;
std::unique_ptr<const RootComponentDescriptor> rootComponentDescriptor_;
ShadowTreeRegistry shadowTreeRegistry_;
RuntimeExecutor runtimeExecutor_;
std::shared_ptr<UIManagerBinding> uiManagerBinding_;
std::shared_ptr<const ReactNativeConfig> reactNativeConfig_;
};
} // namespace react
} // namespace facebook