mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-11 15:33:48 +08:00
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
50 lines
1.5 KiB
C++
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
|