Skip to content

Commit

Permalink
Text views implement padding themselves. Add ability for views to dec…
Browse files Browse the repository at this point in the history
…lare this so the yoga layout will not do it for them.
  • Loading branch information
randy-flynn committed Mar 25, 2019
1 parent 85cb9a8 commit e07df99
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
54 changes: 35 additions & 19 deletions RNWCPP/ReactUWP/Modules/NativeUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ static void SetYogaValueAutoHelper(const YGNodeRef yogaNode, const YGEdge edge,
}
}

static void StyleYogaNode(const YGNodeRef yogaNode, const folly::dynamic& props)
static void StyleYogaNode(ShadowNodeBase& shadowNode, const YGNodeRef yogaNode, const folly::dynamic& props)
{
if (props.empty())
return;
Expand Down Expand Up @@ -594,49 +594,65 @@ static void StyleYogaNode(const YGNodeRef yogaNode, const folly::dynamic& props)
SetYogaValueAutoHelper(yogaNode, YGEdgeVertical, result, YGNodeStyleSetMargin, YGNodeStyleSetMarginPercent, YGNodeStyleSetMarginAuto);
}
else if (key == "padding") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeAll, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeAll, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingLeft") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeLeft, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeLeft, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingStart") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeStart, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeStart, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingTop") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeTop, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeTop, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingRight") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeRight, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
else if (key == "paddingEnd") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeEnd, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeEnd, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingBottom") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeBottom, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeBottom, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingHorizontal") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeHorizontal, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeHorizontal, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "paddingVertical") {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);
if (!shadowNode.ImplementsPadding()) {
YGValue result = YGValueOrDefault(value, YGValue{ YGUndefined, YGUnitPoint } /*default*/);

SetYogaValueHelper(yogaNode, YGEdgeVertical, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
SetYogaValueHelper(yogaNode, YGEdgeVertical, result, YGNodeStyleSetPadding, YGNodeStyleSetPaddingPercent);
}
}
else if (key == "borderWidth") {
float result = NumberOrDefault(value, 0.0f /*default*/);
Expand Down Expand Up @@ -687,7 +703,7 @@ void NativeUIManager::CreateView(facebook::react::ShadowNode& shadowNode, folly:
if (result.second == true)
{
YGNodeRef yogaNode = result.first->second.get();
StyleYogaNode(yogaNode, props);
StyleYogaNode(node, yogaNode, props);

YGMeasureFunc func = pViewManager->GetYogaCustomMeasureFunc();
if (func != nullptr)
Expand Down Expand Up @@ -786,7 +802,7 @@ void NativeUIManager::UpdateView(facebook::react::ShadowNode& shadowNode, folly:
if (pViewManager->RequiresYogaNode())
{
YGNodeRef yogaNode = GetYogaNode(node.m_tag);
StyleYogaNode(yogaNode, props);
StyleYogaNode(node, yogaNode, props);
}
}

Expand Down
13 changes: 13 additions & 0 deletions RNWCPP/ReactUWP/Views/TextViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,24 @@ using namespace Windows::UI::Xaml::Documents;

namespace react { namespace uwp {

class TextShadowNode : public ShadowNodeBase
{
using Super = ShadowNodeBase;
public:
TextShadowNode() = default;
bool ImplementsPadding() override { return true; }
};

TextViewManager::TextViewManager(const std::shared_ptr<IReactInstance>& reactInstance)
: Super(reactInstance)
{
}

facebook::react::ShadowNode* TextViewManager::createShadow() const
{
return new TextShadowNode();
}

const char* TextViewManager::GetName() const
{
return "RCTText";
Expand Down
2 changes: 2 additions & 0 deletions RNWCPP/ReactUWP/Views/TextViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class TextViewManager : public FrameworkElementViewManager
public:
TextViewManager(const std::shared_ptr<IReactInstance>& reactInstance);

facebook::react::ShadowNode* createShadow() const override;

const char* GetName() const override;
void UpdateProperties(ShadowNodeBase* nodeToUpdate, folly::dynamic reactDiffMap) override;

Expand Down
1 change: 1 addition & 0 deletions RNWCPP/include/ReactUWP/Views/ShadowNodeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct REACTWINDOWS_EXPORT ShadowNodeBase : public facebook::react::ShadowNode
virtual void updateProperties(const folly::dynamic&& props) override;

virtual void ReplaceChild(XamlView oldChildView, XamlView newChildView);
virtual bool ImplementsPadding() { return false; }

ViewManagerBase* GetViewManager() const { return static_cast<ViewManagerBase*>(m_viewManager); }
XamlView GetView() const { return m_view; }
Expand Down

0 comments on commit e07df99

Please sign in to comment.