2018-03-18 19:04:25 -07:00
|
|
|
/**
|
|
|
|
* 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>
|
|
|
|
|
2018-07-15 16:46:31 -07:00
|
|
|
#include <fabric/components/view/YogaStylableProps.h>
|
2018-03-18 19:04:25 -07:00
|
|
|
#include <fabric/core/LayoutableShadowNode.h>
|
|
|
|
#include <fabric/core/Sealable.h>
|
|
|
|
#include <fabric/debug/DebugStringConvertible.h>
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
class YogaLayoutableShadowNode:
|
|
|
|
public LayoutableShadowNode,
|
|
|
|
public virtual DebugStringConvertible,
|
|
|
|
public virtual Sealable {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
#pragma mark - Constructors
|
|
|
|
|
2018-07-17 22:41:31 -07:00
|
|
|
YogaLayoutableShadowNode();
|
2018-03-18 19:04:25 -07:00
|
|
|
|
2018-07-17 22:41:31 -07:00
|
|
|
YogaLayoutableShadowNode(const YogaLayoutableShadowNode &layoutableShadowNode);
|
2018-03-18 19:04:25 -07:00
|
|
|
|
|
|
|
#pragma mark - Mutating Methods
|
|
|
|
|
2018-04-26 17:51:57 -07:00
|
|
|
/*
|
|
|
|
* Connects `measureFunc` function of Yoga node with
|
|
|
|
* `LayoutableShadowNode::measure()` method.
|
|
|
|
*/
|
|
|
|
void enableMeasurement();
|
|
|
|
|
2018-03-18 19:04:25 -07:00
|
|
|
/*
|
|
|
|
* Appends `child`'s Yoga node to the own Yoga node.
|
2018-07-17 22:41:31 -07:00
|
|
|
* Complements `ShadowNode::appendChild(...)` functionality from Yoga perspective.
|
|
|
|
*/
|
|
|
|
void appendChild(YogaLayoutableShadowNode *child);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets Yoga children based on collection of `YogaLayoutableShadowNode` instances.
|
|
|
|
* Complements `ShadowNode::setChildren(...)` functionality from Yoga perspective.
|
2018-03-18 19:04:25 -07:00
|
|
|
*/
|
2018-07-17 22:41:31 -07:00
|
|
|
void setChildren(std::vector<YogaLayoutableShadowNode *> children);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sets Yoga styles based on given `YogaStylableProps`.
|
|
|
|
*/
|
|
|
|
void setProps(const YogaStylableProps &props);
|
|
|
|
|
|
|
|
#pragma mark - LayoutableShadowNode
|
2018-03-18 19:04:25 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2018-07-17 22:41:31 -07:00
|
|
|
std::vector<LayoutableShadowNode *> getLayoutableChildNodes() const override;
|
|
|
|
|
2018-05-15 23:32:33 -07:00
|
|
|
protected:
|
2018-05-22 15:45:55 -07:00
|
|
|
/*
|
|
|
|
* 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_;
|
2018-03-18 19:04:25 -07:00
|
|
|
|
2018-06-22 07:28:31 -07:00
|
|
|
/*
|
|
|
|
* Yoga config associated (only) with this particular node.
|
|
|
|
*/
|
|
|
|
YGConfig yogaConfig_;
|
|
|
|
|
2018-05-15 23:32:33 -07:00
|
|
|
private:
|
2018-06-22 07:28:31 -07:00
|
|
|
static void initializeYogaConfig(YGConfig &config);
|
2018-04-10 16:36:56 -07:00
|
|
|
static YGNode *yogaNodeCloneCallbackConnector(YGNode *oldYogaNode, YGNode *parentYogaNode, int childIndex);
|
2018-04-26 17:51:57 -07:00
|
|
|
static YGSize yogaNodeMeasureCallbackConnector(YGNode *yogaNode, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode);
|
2018-03-18 19:04:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace react
|
|
|
|
} // namespace facebook
|