Files
react-native/ReactCommon/fabric/components/root/RootProps.cpp
T
Valentin Shergin 4d35e4d92c Fabric: Make RootProps constructible from RawProps
Summary: Even though it makes no sense to construct RootProps from RawProps, we need to support that (even if it's no-op) to be able to call this once from generic `ConcreteComponentDescriptor`. We will need it in the coming diff.

Reviewed By: mdvacca

Differential Revision: D15752970

fbshipit-source-id: b75a4023c5d0425a8dbe0f104a36a0f265eb6084
2019-06-12 21:35:20 -07:00

48 lines
1.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.
*/
#include "RootProps.h"
#include <react/components/view/YogaLayoutableShadowNode.h>
#include <react/components/view/conversions.h>
namespace facebook {
namespace react {
static YGStyle yogaStyleFromLayoutConstraints(
LayoutConstraints const &layoutConstraints) {
auto yogaStyle = YGStyle{};
yogaStyle.minDimensions()[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.width);
yogaStyle.minDimensions()[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.minimumSize.height);
yogaStyle.maxDimensions()[YGDimensionWidth] =
yogaStyleValueFromFloat(layoutConstraints.maximumSize.width);
yogaStyle.maxDimensions()[YGDimensionHeight] =
yogaStyleValueFromFloat(layoutConstraints.maximumSize.height);
yogaStyle.direction() =
yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection);
return yogaStyle;
}
RootProps::RootProps(RootProps const &sourceProps, RawProps const &rawProps)
: ViewProps(sourceProps, rawProps) {}
RootProps::RootProps(
RootProps const &sourceProps,
LayoutConstraints const &layoutConstraints,
LayoutContext const &layoutContext)
: ViewProps(yogaStyleFromLayoutConstraints(layoutConstraints)),
layoutConstraints(layoutConstraints),
layoutContext(layoutContext){};
} // namespace react
} // namespace facebook