Files
react-native/ReactCommon/fabric/components/root/RootProps.cpp
David Aurelio 54af7fc645 YGStyle: wrap all fields into accessors
Summary:
@public

In order to encapsulate property access on `YGStyle`, as a first measure we wrap all fields with accessors.

This will e.g. enable dynamic property storage and instrumentation in the future.

All accessors have a `const` version that allows direct access via `const&`. For mutation, bit fields are wrapped with a custom reference object.

This style allows for the least amount of changes in client code. Property access simply needs appended parens, eg `style.direction` becomes `style.direction`.

Reviewed By: shergin

Differential Revision: D14999096

fbshipit-source-id: fbf29f7ddab520513d4618f5e70094c4f6330b30
2019-04-23 08:12:35 -07:00

50 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(
const LayoutConstraints &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(const RootProps &sourceProps, const RawProps &rawProps) {
// `RootProps` cannot be constructed from `RawProps`.
assert(false);
}
RootProps::RootProps(
const RootProps &sourceProps,
const LayoutConstraints &layoutConstraints,
const LayoutContext &layoutContext)
: ViewProps(yogaStyleFromLayoutConstraints(layoutConstraints)),
layoutConstraints(layoutConstraints),
layoutContext(layoutContext){};
} // namespace react
} // namespace facebook