react-native/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h
Valentin Shergin 57b0e68a2c Fabric: view module was moved to components subdirectory
Summary:
@public
Trivial. We move all components into `/components/` subdirectory.

Reviewed By: mdvacca

Differential Revision: D8757011

fbshipit-source-id: 6a7da09e01184d41d37a1e1782c20d3c79371ae3
2018-07-15 16:52:26 -07:00

104 lines
3.0 KiB
C++

/**
* Copyright (c) 2015-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 <vector>
#include <yoga/YGNode.h>
#include <fabric/components/view/YogaStylableProps.h>
#include <fabric/core/LayoutableShadowNode.h>
#include <fabric/core/Sealable.h>
#include <fabric/core/ShadowNode.h>
#include <fabric/debug/DebugStringConvertible.h>
namespace facebook {
namespace react {
class YogaLayoutableShadowNode;
using SharedYogaConfig = std::shared_ptr<YGConfig>;
using SharedYogaLayoutableShadowNode = std::shared_ptr<const YogaLayoutableShadowNode>;
using SharedYogaLayoutableShadowNodeList = std::vector<SharedYogaLayoutableShadowNode>;
using SharedYogaLayoutableShadowNodeSharedList = std::shared_ptr<const SharedYogaLayoutableShadowNodeList>;
class YogaLayoutableShadowNode:
public LayoutableShadowNode,
public virtual DebugStringConvertible,
public virtual Sealable {
public:
#pragma mark - Constructors
YogaLayoutableShadowNode(
const SharedYogaStylableProps &props,
const SharedShadowNodeSharedList &children
);
YogaLayoutableShadowNode(
const SharedYogaLayoutableShadowNode &shadowNode,
const SharedYogaStylableProps &props = nullptr,
const SharedShadowNodeSharedList &children = nullptr
);
#pragma mark - Mutating Methods
/*
* Connects `measureFunc` function of Yoga node with
* `LayoutableShadowNode::measure()` method.
*/
void enableMeasurement();
/*
* Appends `child`'s Yoga node to the own Yoga node.
* So, it complements `ShadowNode::appendChild(...)` functionality from Yoga
* perspective.
*/
void appendChild(SharedYogaLayoutableShadowNode child);
void cleanLayout() override;
void dirtyLayout() override;
bool getIsLayoutClean() const override;
void setHasNewLayout(bool hasNewLayout) override;
bool getHasNewLayout() const override;
/*
* Computes layout using Yoga layout engine.
* See `LayoutableShadowNode` for more details.
*/
void layout(LayoutContext layoutContext) override;
void layoutChildren(LayoutContext layoutContext) override;
protected:
/*
* All Yoga functions only accept non-const arguments, so we have to mark
* Yoga node as `mutable` here to avoid `static_cast`ing the pointer to this
* all the time.
*/
mutable YGNode yogaNode_;
/*
* Yoga config associated (only) with this particular node.
*/
YGConfig yogaConfig_;
private:
static void initializeYogaConfig(YGConfig &config);
static void setYogaNodeChildrenBasedOnShadowNodeChildren(YGNode *yogaNodeRawPtr, const SharedShadowNodeSharedList &children);
static YGNode *yogaNodeCloneCallbackConnector(YGNode *oldYogaNode, YGNode *parentYogaNode, int childIndex);
static YGSize yogaNodeMeasureCallbackConnector(YGNode *yogaNode, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode);
};
} // namespace react
} // namespace facebook