Summary: X-link: https://github.com/facebook/react-native/pull/44791 Pull Request resolved: https://github.com/facebook/yoga/pull/1662 This should fix https://github.com/facebook/yoga/issues/1657. Rather insidious bug but we had code like ``` // The total padding/border for a given axis does not depend on the direction // so hardcoding LTR here to avoid piping direction to this function return node->style().computeInlineStartPaddingAndBorder( axis, Direction::LTR, widthSize) + node->style().computeInlineEndPaddingAndBorder( axis, Direction::LTR, widthSize); ``` That comment is NOT true if someone sets both the physical edge and relative edge. So like paddingLeft and paddingEnd for RTL. This diff simply pipes the direction to that spot to use instead of hardcoding LTR. Every file changed is just to pipe `direction`. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D58169843 fbshipit-source-id: 5b4854dddc019285076bd06955557edf73ef7ec5
310 lines
11 KiB
C++
310 lines
11 KiB
C++
/*
|
|
* 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.
|
|
*
|
|
* clang-format off
|
|
* @generated SignedSource<<f1bb0b5643b1db2ff78e5c327f45f0f3>>
|
|
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGPaddingTest.html
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <yoga/Yoga.h>
|
|
|
|
TEST(YogaTest, padding_no_size) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetPadding(root, YGEdgeLeft, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeTop, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeRight, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeBottom, 10);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetHeight(root));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, padding_container_match_child) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetPadding(root, YGEdgeLeft, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeTop, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeRight, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeBottom, 10);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(30, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(30, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, padding_flex_child) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetPadding(root, YGEdgeLeft, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeTop, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeRight, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeBottom, 10);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetFlexGrow(root_child0, 1);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, padding_stretch_child) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetPadding(root, YGEdgeLeft, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeTop, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeRight, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeBottom, 10);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(80, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, padding_center_child) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetJustifyContent(root, YGJustifyCenter);
|
|
YGNodeStyleSetAlignItems(root, YGAlignCenter);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetPadding(root, YGEdgeStart, 10);
|
|
YGNodeStyleSetPadding(root, YGEdgeEnd, 20);
|
|
YGNodeStyleSetPadding(root, YGEdgeBottom, 20);
|
|
YGNodeStyleSetWidth(root, 100);
|
|
YGNodeStyleSetHeight(root, 100);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidth(root_child0, 10);
|
|
YGNodeStyleSetHeight(root_child0, 10);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(40, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(35, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, child_with_padding_align_end) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetJustifyContent(root, YGJustifyFlexEnd);
|
|
YGNodeStyleSetAlignItems(root, YGAlignFlexEnd);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetWidth(root, 200);
|
|
YGNodeStyleSetHeight(root, 200);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetPadding(root_child0, YGEdgeLeft, 20);
|
|
YGNodeStyleSetPadding(root_child0, YGEdgeTop, 20);
|
|
YGNodeStyleSetPadding(root_child0, YGEdgeRight, 20);
|
|
YGNodeStyleSetPadding(root_child0, YGEdgeBottom, 20);
|
|
YGNodeStyleSetWidth(root_child0, 100);
|
|
YGNodeStyleSetHeight(root_child0, 100);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|
|
|
|
TEST(YogaTest, physical_and_relative_edge_defined) {
|
|
const YGConfigRef config = YGConfigNew();
|
|
|
|
const YGNodeRef root = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
|
YGNodeStyleSetPadding(root, YGEdgeLeft, 20);
|
|
YGNodeStyleSetPadding(root, YGEdgeEnd, 50);
|
|
YGNodeStyleSetWidth(root, 200);
|
|
YGNodeStyleSetHeight(root, 200);
|
|
|
|
const YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
|
YGNodeStyleSetWidthPercent(root_child0, 100);
|
|
YGNodeStyleSetHeight(root_child0, 50);
|
|
YGNodeInsertChild(root, root_child0, 0);
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(130, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
|
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetWidth(root));
|
|
ASSERT_FLOAT_EQ(200, YGNodeLayoutGetHeight(root));
|
|
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child0));
|
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root_child0));
|
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
|
|
|
YGNodeFreeRecursive(root);
|
|
|
|
YGConfigFree(config);
|
|
}
|