mirror of
https://github.com/status-im/react-native.git
synced 2025-01-16 20:44:10 +00:00
0792fba63f
Summary: @public This is quite a big diff but the actual meaningful change is simple: now we use ShadowView class instead of ShadowNode in mutation instructions. Note: * In some places (especially during diffing) we have to operate with ShadowNodeViewPair objects (which represents a pair of ShadowNode and ShadowView). The reason for that is that we cannot construct child ShadowViews from parent ShadowViews because they don't have any information about children. * `ShadowTree::emitLayoutEvents` is now much simpler because ShadowView better represents the specifics of this kind of object. * The code in RCTMountingManager also became simpler. This change will allow us to implement more cool tricks soon. Reviewed By: mdvacca Differential Revision: D9403564 fbshipit-source-id: dbc7c61af250144d6c7335a01dc30df0005559a2
97 lines
2.6 KiB
C++
97 lines
2.6 KiB
C++
// Copyright (c) 2004-present, Facebook, Inc.
|
|
|
|
// 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 <fabric/components/root/RootShadowNode.h>
|
|
#include <fabric/core/LayoutConstraints.h>
|
|
#include <fabric/core/ReactPrimitives.h>
|
|
#include <fabric/core/ShadowNode.h>
|
|
#include <fabric/uimanager/ShadowTreeDelegate.h>
|
|
#include <fabric/uimanager/ShadowViewMutation.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class ShadowTree;
|
|
|
|
using SharedShadowTree = std::shared_ptr<ShadowTree>;
|
|
|
|
/*
|
|
* Represents the shadow tree and its lifecycle.
|
|
*/
|
|
class ShadowTree final:
|
|
public std::enable_shared_from_this<ShadowTree> {
|
|
|
|
public:
|
|
|
|
/*
|
|
* Creates a new shadow tree instance with given `rootTag`.
|
|
*/
|
|
ShadowTree(Tag rootTag);
|
|
|
|
/*
|
|
* Returns the rootTag associated with the shadow tree (the tag of the
|
|
* root shadow node).
|
|
*/
|
|
Tag getRootTag() const;
|
|
|
|
#pragma mark - Layout
|
|
|
|
/*
|
|
* Measures the shadow tree with given `layoutConstraints` and `layoutContext`.
|
|
* Can be called from any thread, side-effect-less.
|
|
*/
|
|
Size measure(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const;
|
|
|
|
/*
|
|
* Applies given `layoutConstraints` and `layoutContext` and commit
|
|
* the new shadow tree.
|
|
* Can be called from any thread.
|
|
*/
|
|
void constraintLayout(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext);
|
|
|
|
#pragma mark - Application
|
|
|
|
/*
|
|
* Create a new shadow tree with given `rootChildNodes` and commit.
|
|
* Can be called from any thread.
|
|
*/
|
|
void complete(const SharedShadowNodeUnsharedList &rootChildNodes);
|
|
|
|
#pragma mark - Delegate
|
|
|
|
/*
|
|
* Sets and gets the delegate.
|
|
* The delegate is stored as a raw pointer, so the owner must null
|
|
* the pointer before being destroyed.
|
|
*/
|
|
void setDelegate(ShadowTreeDelegate *delegate);
|
|
ShadowTreeDelegate *getDelegate() const;
|
|
|
|
private:
|
|
|
|
UnsharedRootShadowNode cloneRootShadowNode(const LayoutConstraints &layoutConstraints, const LayoutContext &layoutContext) const;
|
|
void complete(UnsharedRootShadowNode newRootShadowNode);
|
|
bool commit(
|
|
const SharedRootShadowNode &oldRootShadowNode,
|
|
const SharedRootShadowNode &newRootShadowNode,
|
|
const ShadowViewMutationList &mutations
|
|
);
|
|
void toggleEventEmitters(const ShadowViewMutationList &mutations);
|
|
void emitLayoutEvents(const ShadowViewMutationList &mutations);
|
|
|
|
const Tag rootTag_;
|
|
SharedRootShadowNode rootShadowNode_;
|
|
ShadowTreeDelegate *delegate_;
|
|
mutable std::mutex commitMutex_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|