mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Preserve negative values in transformOrigin strings (#57691)
Summary: The numeric tokenizer updated in https://github.com/react/react-native/issues/57487 still starts at the first digit when a percentage or pixel value is negative. This silently changes values such as `-12.5px -7.5px` into `[12.5, 7.5, 0]`. Allow a leading minus in numeric tokens so negative percentages, pixel offsets, and leading-dot decimals retain their sign. The pattern is intentionally limited to the failing negative case and leaves leading-plus values unchanged. ## Changelog: [GENERAL] [FIXED] - Preserve negative values in `transformOrigin` strings. Pull Request resolved: https://github.com/react/react-native/pull/57691 Test Plan: - Added Fantom regression coverage for negative percentages, x/y/z pixel offsets, and leading-dot decimals in `processTransformOrigin-itest.js` - `./node_modules/.bin/prettier --check packages/react-native/Libraries/StyleSheet/processTransformOrigin.js packages/react-native/Libraries/StyleSheet/__tests__/processTransformOrigin-itest.js` - `./node_modules/.bin/eslint --max-warnings 0 packages/react-native/Libraries/StyleSheet/processTransformOrigin.js packages/react-native/Libraries/StyleSheet/__tests__/processTransformOrigin-itest.js` - Ran focused runtime checks against the Flow-stripped parser for the new negative cases and existing leading-plus behavior Reviewed By: javache Differential Revision: D113756417 Pulled By: fabriziocucci fbshipit-source-id: a1506ada24adbeb81892a7c1d821e03ccd388de2
This commit is contained in:
1 parent
4043e818f1
commit
4501979c1a
3 files changed
+54
-1
No files matched your search
+11
@@ -122,5 +122,16 @@ describe('processTransformOrigin', () => {
|
||||
expect(processTransformOrigin('12.5px 7.5px')).toEqual([12.5, 7.5, 0]);
|
||||
expect(processTransformOrigin('.5% .5px')).toEqual(['.5%', 0.5, 0]);
|
||||
});
|
||||
it('should preserve negative percentage and pixel values', () => {
|
||||
expect(processTransformOrigin('-50.5% -30.2%')).toEqual([
|
||||
'-50.5%',
|
||||
'-30.2%',
|
||||
0,
|
||||
]);
|
||||
expect(processTransformOrigin('-12.5px -7.5px -2.5px')).toEqual([
|
||||
-12.5, -7.5, -2.5,
|
||||
]);
|
||||
expect(processTransformOrigin('-.5% -.5px')).toEqual(['-.5%', -0.5, 0]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -12,7 +12,7 @@ import invariant from 'invariant';
|
||||
|
||||
// Pre-compiled regex pattern for performance - avoids regex compilation on each call
|
||||
const TRANSFORM_ORIGIN_REGEX =
|
||||
/(top|bottom|left|right|center|\d*\.?\d+(?:%|px)|0)/gi;
|
||||
/(top|bottom|left|right|center|-?\d*\.?\d+(?:%|px)|0)/gi;
|
||||
|
||||
const INDEX_X = 0;
|
||||
const INDEX_Y = 1;
|
||||
|
||||
@@ -455,4 +455,46 @@ TEST(CSSTransformOrigin, decimal_percentage_percentage) {
|
||||
EXPECT_EQ(origin.z, CSSLength{});
|
||||
}
|
||||
|
||||
TEST(CSSTransformOrigin, negative_lengths) {
|
||||
auto value = parseCSSProperty<CSSTransformOrigin>("-12.5px -7.5px -2.5px");
|
||||
EXPECT_TRUE(std::holds_alternative<CSSTransformOrigin>(value));
|
||||
auto& origin = std::get<CSSTransformOrigin>(value);
|
||||
|
||||
EXPECT_TRUE(std::holds_alternative<CSSLength>(origin.x));
|
||||
EXPECT_EQ(std::get<CSSLength>(origin.x).value, -12.5f);
|
||||
EXPECT_EQ(std::get<CSSLength>(origin.x).unit, CSSLengthUnit::Px);
|
||||
|
||||
EXPECT_TRUE(std::holds_alternative<CSSLength>(origin.y));
|
||||
EXPECT_EQ(std::get<CSSLength>(origin.y).value, -7.5f);
|
||||
EXPECT_EQ(std::get<CSSLength>(origin.y).unit, CSSLengthUnit::Px);
|
||||
|
||||
EXPECT_EQ(origin.z.value, -2.5f);
|
||||
EXPECT_EQ(origin.z.unit, CSSLengthUnit::Px);
|
||||
}
|
||||
|
||||
TEST(CSSTransformOrigin, negative_percentages) {
|
||||
auto value = parseCSSProperty<CSSTransformOrigin>("-50.5% -30.2%");
|
||||
EXPECT_TRUE(std::holds_alternative<CSSTransformOrigin>(value));
|
||||
auto& origin = std::get<CSSTransformOrigin>(value);
|
||||
|
||||
EXPECT_TRUE(std::holds_alternative<CSSPercentage>(origin.x));
|
||||
EXPECT_EQ(std::get<CSSPercentage>(origin.x).value, -50.5f);
|
||||
|
||||
EXPECT_TRUE(std::holds_alternative<CSSPercentage>(origin.y));
|
||||
EXPECT_EQ(std::get<CSSPercentage>(origin.y).value, -30.2f);
|
||||
}
|
||||
|
||||
TEST(CSSTransformOrigin, negative_leading_dot_values) {
|
||||
auto value = parseCSSProperty<CSSTransformOrigin>("-.5% -.5px");
|
||||
EXPECT_TRUE(std::holds_alternative<CSSTransformOrigin>(value));
|
||||
auto& origin = std::get<CSSTransformOrigin>(value);
|
||||
|
||||
EXPECT_TRUE(std::holds_alternative<CSSPercentage>(origin.x));
|
||||
EXPECT_EQ(std::get<CSSPercentage>(origin.x).value, -0.5f);
|
||||
|
||||
EXPECT_TRUE(std::holds_alternative<CSSLength>(origin.y));
|
||||
EXPECT_EQ(std::get<CSSLength>(origin.y).value, -0.5f);
|
||||
EXPECT_EQ(std::get<CSSLength>(origin.y).unit, CSSLengthUnit::Px);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
Reference in new issue
Block a user