diff --git a/Libraries/StyleSheet/__tests__/__snapshots__/processTransform-test.js.snap b/Libraries/StyleSheet/__tests__/__snapshots__/processTransform-test.js.snap
index 9ec8fbc3cd6674..dc8d045189ea5e 100644
--- a/Libraries/StyleSheet/__tests__/__snapshots__/processTransform-test.js.snap
+++ b/Libraries/StyleSheet/__tests__/__snapshots__/processTransform-test.js.snap
@@ -2,6 +2,8 @@
exports[`processTransform validation should throw on invalid transform property 1`] = `"Invalid transform translateW: {\\"translateW\\":10}"`;
+exports[`processTransform validation should throw on invalid transform property 2`] = `"Invalid transform translateW: {\\"translateW\\":10}"`;
+
exports[`processTransform validation should throw on object with multiple properties 1`] = `"You must specify exactly one property per transform object. Passed properties: {\\"scale\\":0.5,\\"translateY\\":10}"`;
exports[`processTransform validation should throw when not passing an array to an array prop 1`] = `"Transform with key of matrix must have an array as the value: {\\"matrix\\":\\"not-a-matrix\\"}"`;
@@ -10,17 +12,25 @@ exports[`processTransform validation should throw when not passing an array to a
exports[`processTransform validation should throw when passing a matrix of the wrong size 1`] = `"Matrix transform must have a length of 9 (2d) or 16 (3d). Provided matrix has a length of 4: {\\"matrix\\":[1,1,1,1]}"`;
+exports[`processTransform validation should throw when passing a matrix of the wrong size 2`] = `"Matrix transform must have a length of 9 (2d) or 16 (3d). Provided matrix has a length of 4: {\\"matrix\\":[1,1,1,1]}"`;
+
exports[`processTransform validation should throw when passing a perspective of 0 1`] = `"Transform with key of \\"perspective\\" cannot be zero: {\\"perspective\\":0}"`;
exports[`processTransform validation should throw when passing a translate of the wrong size 1`] = `"Transform with key translate must be an array of length 2 or 3, found 1: {\\"translate\\":[1]}"`;
exports[`processTransform validation should throw when passing a translate of the wrong size 2`] = `"Transform with key translate must be an array of length 2 or 3, found 4: {\\"translate\\":[1,1,1,1]}"`;
+exports[`processTransform validation should throw when passing a translate of the wrong size 3`] = `"Transform with key translate must be an string with 1 or 2 parameters, found 4: translate(1px, 1px, 1px, 1px)"`;
+
exports[`processTransform validation should throw when passing an Animated.Value 1`] = `"You passed an Animated.Value to a normal component. You need to wrap that component in an Animated. For example, replace by ."`;
exports[`processTransform validation should throw when passing an invalid angle prop 1`] = `"Transform with key of \\"rotate\\" must be a string: {\\"rotate\\":10}"`;
-exports[`processTransform validation should throw when passing an invalid angle prop 2`] = `"Rotate transform must be expressed in degrees (deg) or radians (rad): {\\"skewX\\":\\"10drg\\"}"`;
+exports[`processTransform validation should throw when passing an invalid angle prop 2`] = `"Transform with key of \\"rotate\\" must be a string: {\\"rotate\\":10}"`;
+
+exports[`processTransform validation should throw when passing an invalid angle prop 3`] = `"Rotate transform must be expressed in degrees (deg) or radians (rad): {\\"skewX\\":\\"10drg\\"}"`;
+
+exports[`processTransform validation should throw when passing an invalid angle prop 4`] = `"Rotate transform must be expressed in degrees (deg) or radians (rad): {\\"skewX\\":\\"10drg\\"}"`;
exports[`processTransform validation should throw when passing an invalid value to a number prop 1`] = `"Transform with key of \\"translateY\\" must be a number: {\\"translateY\\":\\"20deg\\"}"`;
diff --git a/Libraries/StyleSheet/__tests__/processTransform-test.js b/Libraries/StyleSheet/__tests__/processTransform-test.js
index bf6f42db4fe9b4..66ce708c033897 100644
--- a/Libraries/StyleSheet/__tests__/processTransform-test.js
+++ b/Libraries/StyleSheet/__tests__/processTransform-test.js
@@ -18,6 +18,10 @@ describe('processTransform', () => {
processTransform([]);
});
+ it('should accept an empty string', () => {
+ processTransform('');
+ });
+
it('should accept a simple valid transform', () => {
processTransform([
{scale: 0.5},
@@ -25,6 +29,9 @@ describe('processTransform', () => {
{translateY: 20},
{rotate: '10deg'},
]);
+ processTransform(
+ 'scale(0.5) translateX(10px) translateY(20px) rotate(10deg)',
+ );
});
it('should throw on object with multiple properties', () => {
@@ -37,6 +44,9 @@ describe('processTransform', () => {
expect(() =>
processTransform([{translateW: 10}]),
).toThrowErrorMatchingSnapshot();
+ expect(() =>
+ processTransform('translateW(10)'),
+ ).toThrowErrorMatchingSnapshot();
});
it('should throw when not passing an array to an array prop', () => {
@@ -50,19 +60,28 @@ describe('processTransform', () => {
it('should accept a valid matrix', () => {
processTransform([{matrix: [1, 1, 1, 1, 1, 1, 1, 1, 1]}]);
+ processTransform('matrix(1, 1, 1, 1, 1, 1, 1, 1, 1)');
processTransform([
{matrix: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]},
]);
+ processTransform(
+ 'matrix(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)',
+ );
});
it('should throw when passing a matrix of the wrong size', () => {
expect(() =>
processTransform([{matrix: [1, 1, 1, 1]}]),
).toThrowErrorMatchingSnapshot();
+ expect(() =>
+ processTransform('matrix(1, 1, 1, 1)'),
+ ).toThrowErrorMatchingSnapshot();
});
it('should accept a valid translate', () => {
processTransform([{translate: [1, 1]}]);
+ processTransform('translate(1px)');
+ processTransform('translate(1px, 1px)');
processTransform([{translate: [1, 1, 1]}]);
});
@@ -73,6 +92,9 @@ describe('processTransform', () => {
expect(() =>
processTransform([{translate: [1, 1, 1, 1]}]),
).toThrowErrorMatchingSnapshot();
+ expect(() =>
+ processTransform('translate(1px, 1px, 1px, 1px)'),
+ ).toThrowErrorMatchingSnapshot();
});
it('should throw when passing an invalid value to a number prop', () => {
@@ -95,16 +117,24 @@ describe('processTransform', () => {
it('should accept an angle in degrees or radians', () => {
processTransform([{skewY: '10deg'}]);
+ processTransform('skewY(10deg)');
processTransform([{rotateX: '1.16rad'}]);
+ processTransform('rotateX(1.16rad)');
});
it('should throw when passing an invalid angle prop', () => {
expect(() =>
processTransform([{rotate: 10}]),
).toThrowErrorMatchingSnapshot();
+ expect(() =>
+ processTransform('rotate(10)'),
+ ).toThrowErrorMatchingSnapshot();
expect(() =>
processTransform([{skewX: '10drg'}]),
).toThrowErrorMatchingSnapshot();
+ expect(() =>
+ processTransform('skewX(10drg)'),
+ ).toThrowErrorMatchingSnapshot();
});
it('should throw when passing an Animated.Value', () => {
diff --git a/Libraries/StyleSheet/private/_TransformStyle.js b/Libraries/StyleSheet/private/_TransformStyle.js
index a0d0a9be5a1728..0a264a393e57b5 100644
--- a/Libraries/StyleSheet/private/_TransformStyle.js
+++ b/Libraries/StyleSheet/private/_TransformStyle.js
@@ -27,27 +27,29 @@ export type ____TransformStyle_Internal = $ReadOnly<{|
*
* `transform([{ skewX: '45deg' }])`
*/
- transform?: $ReadOnlyArray<
- | {|+perspective: number | AnimatedNode|}
- | {|+rotate: string | AnimatedNode|}
- | {|+rotateX: string | AnimatedNode|}
- | {|+rotateY: string | AnimatedNode|}
- | {|+rotateZ: string | AnimatedNode|}
- | {|+scale: number | AnimatedNode|}
- | {|+scaleX: number | AnimatedNode|}
- | {|+scaleY: number | AnimatedNode|}
- | {|+translateX: number | AnimatedNode|}
- | {|+translateY: number | AnimatedNode|}
- | {|
- +translate:
- | [number | AnimatedNode, number | AnimatedNode]
- | AnimatedNode,
- |}
- | {|+skewX: string|}
- | {|+skewY: string|}
- // TODO: what is the actual type it expects?
- | {|
- +matrix: $ReadOnlyArray | AnimatedNode,
- |},
- >,
+ transform?:
+ | $ReadOnlyArray<
+ | {|+perspective: number | AnimatedNode|}
+ | {|+rotate: string | AnimatedNode|}
+ | {|+rotateX: string | AnimatedNode|}
+ | {|+rotateY: string | AnimatedNode|}
+ | {|+rotateZ: string | AnimatedNode|}
+ | {|+scale: number | AnimatedNode|}
+ | {|+scaleX: number | AnimatedNode|}
+ | {|+scaleY: number | AnimatedNode|}
+ | {|+translateX: number | AnimatedNode|}
+ | {|+translateY: number | AnimatedNode|}
+ | {|
+ +translate:
+ | [number | AnimatedNode, number | AnimatedNode]
+ | AnimatedNode,
+ |}
+ | {|+skewX: string|}
+ | {|+skewY: string|}
+ // TODO: what is the actual type it expects?
+ | {|
+ +matrix: $ReadOnlyArray | AnimatedNode,
+ |},
+ >
+ | string,
|}>;
diff --git a/Libraries/StyleSheet/processTransform.js b/Libraries/StyleSheet/processTransform.js
index 7b065c0403756d..07dfa910b8616b 100644
--- a/Libraries/StyleSheet/processTransform.js
+++ b/Libraries/StyleSheet/processTransform.js
@@ -22,8 +22,26 @@ const stringifySafe = require('../Utilities/stringifySafe').default;
* interface to native code.
*/
function processTransform(
- transform: Array