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

Fixup direction == 'rtl' #4683

Merged
merged 5 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -0,0 +1,8 @@
{
"type": "prerelease",
"comment": "fix RTL",
"packageName": "react-native-windows",
"email": "kmelmon@microsoft.com",
"dependentChangeType": "patch",
"date": "2020-04-22T23:22:32.344Z"
}
13 changes: 6 additions & 7 deletions vnext/ReactUWP/Modules/NativeUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,12 @@ static void StyleYogaNode(ShadowNodeBase &shadowNode, const YGNodeRef yogaNode,

YGNodeStyleSetDisplay(yogaNode, display);
} else if (key == "direction") {
YGDirection direction = YGDirectionInherit;
if (value == "inherit" || value.isNull())
direction = YGDirectionInherit;
else if (value == "ltr" || value.isNull())
direction = YGDirectionLTR;
else if (value == "rtl")
direction = YGDirectionRTL;
// https://github.com/microsoft/react-native-windows/issues/4668
// In order to support the direction property, we tell yoga to always layout
// in LTR direction, then push the appropriate FlowDirection into XAML.
// This way XAML handles flipping in RTL mode, which works both for RN components
// as well as native components that have purely XAML sub-trees (eg ComboBox).
YGDirection direction = YGDirectionLTR;

YGNodeStyleSetDirection(yogaNode, direction);
} else if (key == "aspectRatio") {
Expand Down
21 changes: 5 additions & 16 deletions vnext/include/ReactUWP/Utils/PropertyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ static const std::unordered_map<std::string, ShadowEdges> edgeTypeMap = {
{"borderWidth", ShadowEdges::AllEdges},
};

inline winrt::Windows::UI::Xaml::Thickness GetThickness(double thicknesses[ShadowEdges::CountEdges], bool isRTL) {
inline winrt::Windows::UI::Xaml::Thickness GetThickness(double thicknesses[ShadowEdges::CountEdges]) {
const double defaultWidth = std::max<double>(0, thicknesses[ShadowEdges::AllEdges]);
double startWidth = DefaultOrOverride(thicknesses[ShadowEdges::Left], thicknesses[ShadowEdges::Start]);
double endWidth = DefaultOrOverride(thicknesses[ShadowEdges::Right], thicknesses[ShadowEdges::End]);
if (isRTL)
std::swap(startWidth, endWidth);

// Compute each edge. Most specific setting wins, so fill from broad to
// narrow: all, horiz/vert, start/end, left/right
Expand All @@ -68,9 +66,7 @@ inline winrt::Windows::UI::Xaml::Thickness GetThickness(double thicknesses[Shado
return thickness;
}

inline winrt::Windows::UI::Xaml::CornerRadius GetCornerRadius(
double cornerRadii[ShadowCorners::CountCorners],
bool isRTL) {
inline winrt::Windows::UI::Xaml::CornerRadius GetCornerRadius(double cornerRadii[ShadowCorners::CountCorners]) {
winrt::Windows::UI::Xaml::CornerRadius cornerRadius;
const double defaultRadius = std::max<double>(0, cornerRadii[ShadowCorners::AllCorners]);
double topStartRadius = DefaultOrOverride(cornerRadii[ShadowCorners::TopLeft], cornerRadii[ShadowCorners::TopStart]);
Expand All @@ -79,10 +75,6 @@ inline winrt::Windows::UI::Xaml::CornerRadius GetCornerRadius(
DefaultOrOverride(cornerRadii[ShadowCorners::BottomLeft], cornerRadii[ShadowCorners::BottomStart]);
double bottomEndRadius =
DefaultOrOverride(cornerRadii[ShadowCorners::BottomRight], cornerRadii[ShadowCorners::BottomEnd]);
if (isRTL) {
std::swap(topStartRadius, topEndRadius);
std::swap(bottomStartRadius, bottomEndRadius);
}

cornerRadius.TopLeft = DefaultOrOverride(defaultRadius, topStartRadius);
cornerRadius.TopRight = DefaultOrOverride(defaultRadius, topEndRadius);
Expand All @@ -95,16 +87,14 @@ inline winrt::Windows::UI::Xaml::CornerRadius GetCornerRadius(
template <class T>
void UpdatePadding(ShadowNodeBase *node, const T &element, ShadowEdges edge, double margin) {
node->m_padding[edge] = margin;
winrt::Thickness thickness =
GetThickness(node->m_padding, element.FlowDirection() == winrt::FlowDirection::RightToLeft);
winrt::Thickness thickness = GetThickness(node->m_padding);
element.Padding(thickness);
}

template <class T>
void SetBorderThickness(ShadowNodeBase *node, const T &element, ShadowEdges edge, double margin) {
node->m_border[edge] = margin;
winrt::Thickness thickness =
GetThickness(node->m_border, element.FlowDirection() == winrt::FlowDirection::RightToLeft);
winrt::Thickness thickness = GetThickness(node->m_border);
element.BorderThickness(thickness);
}

Expand Down Expand Up @@ -141,8 +131,7 @@ UpdateCornerRadiusValueOnNode(ShadowNodeBase *node, ShadowCorners corner, const

template <class T>
void UpdateCornerRadiusOnElement(ShadowNodeBase *node, const T &element) {
winrt::CornerRadius cornerRadius =
GetCornerRadius(node->m_cornerRadius, element.FlowDirection() == winrt::FlowDirection::RightToLeft);
winrt::CornerRadius cornerRadius = GetCornerRadius(node->m_cornerRadius);
element.CornerRadius(cornerRadius);
}

Expand Down
Loading