Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(styles): setting border style in yoga and applying logic to for none #10

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ static CALayerCornerCurve CornerCurveFromBorderCurve(BorderCurve borderCurve)
static RCTBorderStyle RCTBorderStyleFromBorderStyle(BorderStyle borderStyle)
{
switch (borderStyle) {
case BorderStyle::None:
return RCTBorderStyleUnset;
case BorderStyle::Solid:
return RCTBorderStyleSolid;
case BorderStyle::Dotted:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ YogaStylableProps::YogaStylableProps(
sourceProps.yogaStyle.boxSizing(),
yogaStyle.boxSizing()));

yogaStyle.setBorderStyle(convertRawProp(
context,
rawProps,
"borderStyle",
sourceProps.yogaStyle.borderStyle(),
yogaStyle.borderStyle()));

convertRawPropAliases(context, sourceProps, rawProps);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,35 @@ inline void fromRawValue(
LOG(ERROR) << "Could not parse yoga::Display: " << stringValue;
}

inline void fromRawValue(
const PropsParserContext& context,
const RawValue& value,
yoga::BorderStyle& result) {
result = yoga::BorderStyle::Solid;
react_native_expect(value.hasType<std::string>());
if (!value.hasType<std::string>()) {
return;
}
auto stringValue = (std::string)value;
if (stringValue == "none") {
result = yoga::BorderStyle::None;
return;
}
if (stringValue == "solid") {
result = yoga::BorderStyle::Solid;
return;
}
if (stringValue == "dotted") {
result = yoga::BorderStyle::Dotted;
return;
}
if (stringValue == "dashed") {
result = yoga::BorderStyle::Dashed;
return;
}
LOG(ERROR) << "Could not parse yoga::BorderStyle: " << stringValue;
}

inline void fromRawValue(
const PropsParserContext& context,
const RawValue& value,
Expand Down Expand Up @@ -775,6 +804,10 @@ inline void fromRawValue(
return;
}
auto stringValue = (std::string)value;
if (stringValue == "none") {
result = BorderStyle::None;
return;
}
if (stringValue == "solid") {
result = BorderStyle::Solid;
return;
Expand Down Expand Up @@ -1369,6 +1402,10 @@ inline std::string toString(const yoga::Display& value) {
return YGDisplayToString(yoga::unscopedEnum(value));
}

inline std::string toString(const yoga::BorderStyle& value) {
return YGBorderStyleToString(yoga::unscopedEnum(value));
}

inline std::string toString(const yoga::Style::Length& length) {
switch (length.unit()) {
case yoga::Unit::Undefined:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum class BackfaceVisibility : uint8_t { Auto, Visible, Hidden };

enum class BorderCurve : uint8_t { Circular, Continuous };

enum class BorderStyle : uint8_t { Solid, Dotted, Dashed };
enum class BorderStyle : uint8_t { None, Solid, Dotted, Dashed };

enum class OutlineStyle : uint8_t { Solid, Dotted, Dashed };

Expand Down
14 changes: 14 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,17 @@ const char* YGWrapToString(const YGWrap value) {
}
return "unknown";
}

const char* YGBorderStyleToString(const YGBorderStyle value) {
switch (value) {
case YGBorderStyleNone:
return "none";
case YGBorderStyleSolid:
return "solid";
case YGBorderStyleDotted:
return "dotted";
case YGBorderStyleDashed:
return "dashed";
}
return "unknown";
}
7 changes: 7 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,11 @@ YG_ENUM_DECL(
YGWrapWrap,
YGWrapWrapReverse)

YG_ENUM_DECL(
YGBorderStyle,
YGBorderStyleNone,
YGBorderStyleSolid,
YGBorderStyleDotted,
YGBorderStyleDashed)

YG_EXTERN_C_END
42 changes: 42 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/enums/BorderStyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// @generated by enums.py
// clang-format off
#pragma once

#include <cstdint>
#include <yoga/YGEnums.h>
#include <yoga/enums/YogaEnums.h>

namespace facebook::yoga {

enum class BorderStyle : uint8_t {
None = YGBorderStyleNone,
Solid = YGBorderStyleSolid,
Dotted = YGBorderStyleDotted,
Dashed = YGBorderStyleDashed,
};

template <>
constexpr int32_t ordinalCount<BorderStyle>() {
return 4;
}

constexpr BorderStyle scopedEnum(YGBorderStyle unscoped) {
return static_cast<BorderStyle>(unscoped);
}

constexpr YGBorderStyle unscopedEnum(BorderStyle scoped) {
return static_cast<YGBorderStyle>(scoped);
}

inline const char* toString(BorderStyle e) {
return YGBorderStyleToString(unscopedEnum(e));
}

} // namespace facebook::yoga
13 changes: 13 additions & 0 deletions packages/react-native/ReactCommon/yoga/yoga/style/Style.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include <yoga/algorithm/FlexDirection.h>
#include <yoga/enums/Align.h>
#include <yoga/enums/BorderStyle.h>
#include <yoga/enums/BoxSizing.h>
#include <yoga/enums/Dimension.h>
#include <yoga/enums/Direction.h>
Expand Down Expand Up @@ -250,6 +251,13 @@ class YG_EXPORT Style {
boxSizing_ = value;
}

BorderStyle borderStyle() const {
return borderStyle_;
}
void setBorderStyle(BorderStyle value) {
borderStyle_ = value;
}

bool horizontalInsetsDefined() const {
return position_[yoga::to_underlying(Edge::Left)].isDefined() ||
position_[yoga::to_underlying(Edge::Right)].isDefined() ||
Expand Down Expand Up @@ -707,6 +715,10 @@ class YG_EXPORT Style {
}

Style::Length computeBorder(PhysicalEdge edge, Direction direction) const {
if (borderStyle_ == BorderStyle::None) {
return Style::Length{};
}

switch (edge) {
case PhysicalEdge::Left:
return computeLeftEdge(border_, direction);
Expand Down Expand Up @@ -734,6 +746,7 @@ class YG_EXPORT Style {
Overflow overflow_ : bitCount<Overflow>() = Overflow::Visible;
Display display_ : bitCount<Display>() = Display::Flex;
BoxSizing boxSizing_ : bitCount<BoxSizing>() = BoxSizing::BorderBox;
BorderStyle borderStyle_ : bitCount<BorderStyle>() = BorderStyle::Solid;

StyleValueHandle flex_{};
StyleValueHandle flexGrow_{};
Expand Down
6 changes: 3 additions & 3 deletions packages/rn-tester/js/examples/View/ViewExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ViewBorderStyleExample extends React.Component<
<View
style={[
{
borderWidth: 1,
borderWidth: 10,
padding: 5,
},
this.state.showBorder
Expand All @@ -48,7 +48,7 @@ class ViewBorderStyleExample extends React.Component<
style={[
{
marginTop: 5,
borderWidth: 1,
borderWidth: 10,
borderRadius: 5,
padding: 5,
},
Expand All @@ -68,7 +68,7 @@ class ViewBorderStyleExample extends React.Component<
style={[
{
marginTop: 5,
borderWidth: 1,
borderWidth: 10,
borderRadius: 5,
padding: 5,
},
Expand Down
Loading