Skip to content

Commit ee33385

Browse files
acoates-msfacebook-github-bot
authored andcommitted
Unify platform behavior of processTransform (#33579)
Summary: Currently both iOS and Android send over the list of transforms as an array. But there is an if statement that causes other platforms to get a matrix. This prevents other platforms from being able to use the fabric ViewProps class and the conversion functions as they exist in core, as those expect the transforms to be an array. Stop special casing iOS and android. - Which will allow for example Windows to be able to share more fabric code. ## Changelog [Internal] [Changed] - All platforms should get transform sent to native as an array of transform operations instead of a matrix Pull Request resolved: #33579 Test Plan: Similar change made in react-native-windows. microsoft/react-native-windows#9797 Reviewed By: NickGerleman Differential Revision: D38615676 Pulled By: cortinico fbshipit-source-id: 8861afe6bf34bebb09dd82f7365faf007dd79cbf
1 parent be39184 commit ee33385

File tree

1 file changed

+1
-108
lines changed

1 file changed

+1
-108
lines changed

Libraries/StyleSheet/processTransform.js

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
'use strict';
1212

13-
const MatrixMath = require('../Utilities/MatrixMath');
14-
const Platform = require('../Utilities/Platform');
15-
1613
const invariant = require('invariant');
1714
const stringifySafe = require('../Utilities/stringifySafe').default;
1815

@@ -31,111 +28,7 @@ function processTransform(
3128
_validateTransforms(transform);
3229
}
3330

34-
// Android & iOS implementations of transform property accept the list of
35-
// transform properties as opposed to a transform Matrix. This is necessary
36-
// to control transform property updates completely on the native thread.
37-
if (Platform.OS === 'android' || Platform.OS === 'ios') {
38-
return transform;
39-
}
40-
41-
const result = MatrixMath.createIdentityMatrix();
42-
43-
transform.forEach(transformation => {
44-
const key = Object.keys(transformation)[0];
45-
const value = transformation[key];
46-
47-
switch (key) {
48-
case 'matrix':
49-
MatrixMath.multiplyInto(result, result, value);
50-
break;
51-
case 'perspective':
52-
_multiplyTransform(result, MatrixMath.reusePerspectiveCommand, [value]);
53-
break;
54-
case 'rotateX':
55-
_multiplyTransform(result, MatrixMath.reuseRotateXCommand, [
56-
_convertToRadians(value),
57-
]);
58-
break;
59-
case 'rotateY':
60-
_multiplyTransform(result, MatrixMath.reuseRotateYCommand, [
61-
_convertToRadians(value),
62-
]);
63-
break;
64-
case 'rotate':
65-
case 'rotateZ':
66-
_multiplyTransform(result, MatrixMath.reuseRotateZCommand, [
67-
_convertToRadians(value),
68-
]);
69-
break;
70-
case 'scale':
71-
_multiplyTransform(result, MatrixMath.reuseScaleCommand, [value]);
72-
break;
73-
case 'scaleX':
74-
_multiplyTransform(result, MatrixMath.reuseScaleXCommand, [value]);
75-
break;
76-
case 'scaleY':
77-
_multiplyTransform(result, MatrixMath.reuseScaleYCommand, [value]);
78-
break;
79-
case 'translate':
80-
_multiplyTransform(result, MatrixMath.reuseTranslate3dCommand, [
81-
value[0],
82-
value[1],
83-
value[2] || 0,
84-
]);
85-
break;
86-
case 'translateX':
87-
_multiplyTransform(result, MatrixMath.reuseTranslate2dCommand, [
88-
value,
89-
0,
90-
]);
91-
break;
92-
case 'translateY':
93-
_multiplyTransform(result, MatrixMath.reuseTranslate2dCommand, [
94-
0,
95-
value,
96-
]);
97-
break;
98-
case 'skewX':
99-
_multiplyTransform(result, MatrixMath.reuseSkewXCommand, [
100-
_convertToRadians(value),
101-
]);
102-
break;
103-
case 'skewY':
104-
_multiplyTransform(result, MatrixMath.reuseSkewYCommand, [
105-
_convertToRadians(value),
106-
]);
107-
break;
108-
default:
109-
throw new Error('Invalid transform name: ' + key);
110-
}
111-
});
112-
113-
return result;
114-
}
115-
116-
/**
117-
* Performs a destructive operation on a transform matrix.
118-
*/
119-
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
120-
* Flow's LTI update could not be added via codemod */
121-
function _multiplyTransform(
122-
result: Array<number>,
123-
matrixMathFunction: Function,
124-
args: Array<number>,
125-
): void {
126-
const matrixToApply = MatrixMath.createIdentityMatrix();
127-
const argsWithIdentity = [matrixToApply].concat(args);
128-
matrixMathFunction.apply(this, argsWithIdentity);
129-
MatrixMath.multiplyInto(result, result, matrixToApply);
130-
}
131-
132-
/**
133-
* Parses a string like '0.5rad' or '60deg' into radians expressed in a float.
134-
* Note that validation on the string is done in `_validateTransform()`.
135-
*/
136-
function _convertToRadians(value: string): number {
137-
const floatValue = parseFloat(value);
138-
return value.indexOf('rad') > -1 ? floatValue : (floatValue * Math.PI) / 180;
31+
return transform;
13932
}
14033

14134
function _validateTransforms(transform: Array<Object>): void {

0 commit comments

Comments
 (0)