Skip to content

Commit b957375

Browse files
committed
Fix negative values in transformOrigin string parser
1 parent 14c3bd8 commit b957375

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

packages/react-native/Libraries/StyleSheet/__tests__/processTransformOrigin-itest.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,16 @@ describe('processTransformOrigin', () => {
122122
expect(processTransformOrigin('12.5px 7.5px')).toEqual([12.5, 7.5, 0]);
123123
expect(processTransformOrigin('.5% .5px')).toEqual(['.5%', 0.5, 0]);
124124
});
125+
it('should preserve negative percentage and pixel values', () => {
126+
expect(processTransformOrigin('-50.5% -30.2%')).toEqual([
127+
'-50.5%',
128+
'-30.2%',
129+
0,
130+
]);
131+
expect(processTransformOrigin('-12.5px -7.5px -2.5px')).toEqual([
132+
-12.5, -7.5, -2.5,
133+
]);
134+
expect(processTransformOrigin('-.5% -.5px')).toEqual(['-.5%', -0.5, 0]);
135+
});
125136
});
126137
});

packages/react-native/Libraries/StyleSheet/processTransformOrigin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import invariant from 'invariant';
1212

1313
// Pre-compiled regex pattern for performance - avoids regex compilation on each call
1414
const TRANSFORM_ORIGIN_REGEX =
15-
/(top|bottom|left|right|center|\d*\.?\d+(?:%|px)|0)/gi;
15+
/(top|bottom|left|right|center|[+-]?\d*\.?\d+(?:%|px)|0)/gi;
1616

1717
const INDEX_X = 0;
1818
const INDEX_Y = 1;

0 commit comments

Comments
 (0)