mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-08-15 18:45:06 +00:00
[fix] Add matrix transform style
Remove the deprecated 'transformMatrix' style prop and support 'matrix' and 'matrix3d' in the 'transform' prop. Fix #1771
This commit is contained in:
+10
-11
@@ -148,21 +148,20 @@ describe('StyleSheet/createReactDOMStyle', () => {
|
||||
|
||||
test('array', () => {
|
||||
const style = {
|
||||
transform: [{ perspective: 50 }, { scaleX: 20 }, { translateX: 20 }, { rotate: '20deg' }]
|
||||
transform: [
|
||||
{ perspective: 50 },
|
||||
{ scaleX: 20 },
|
||||
{ translateX: 20 },
|
||||
{ rotate: '20deg' },
|
||||
{ matrix: [1, 2, 3, 4, 5, 6] },
|
||||
{ matrix3d: [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4] }
|
||||
]
|
||||
};
|
||||
const resolved = createReactDOMStyle(style);
|
||||
|
||||
expect(resolved).toEqual({
|
||||
transform: 'perspective(50px) scaleX(20) translateX(20px) rotate(20deg)'
|
||||
});
|
||||
});
|
||||
|
||||
test('transformMatrix', () => {
|
||||
const style = { transformMatrix: [1, 2, 3, 4, 5, 6] };
|
||||
const resolved = createReactDOMStyle(style);
|
||||
|
||||
expect(resolved).toEqual({
|
||||
transform: 'matrix3d(1,2,3,4,5,6)'
|
||||
transform:
|
||||
'perspective(50px) scaleX(20) translateX(20px) rotate(20deg) matrix(1,2,3,4,5,6) matrix3d(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,24 +37,22 @@ const supportsCSS3TextDecoration =
|
||||
|
||||
// { scale: 2 } => 'scale(2)'
|
||||
// { translateX: 20 } => 'translateX(20px)'
|
||||
// { matrix: [1,2,3,4,5,6] } => 'matrix(1,2,3,4,5,6)'
|
||||
const mapTransform = transform => {
|
||||
const type = Object.keys(transform)[0];
|
||||
const value = normalizeValueWithProperty(transform[type], type);
|
||||
return `${type}(${value})`;
|
||||
};
|
||||
|
||||
// [1,2,3,4,5,6] => 'matrix3d(1,2,3,4,5,6)'
|
||||
const convertTransformMatrix = transformMatrix => {
|
||||
const matrix = transformMatrix.join(',');
|
||||
return `matrix3d(${matrix})`;
|
||||
const value = transform[type];
|
||||
if (type === 'matrix' || type === 'matrix3d') {
|
||||
return `${type}(${value.join(',')})`;
|
||||
} else {
|
||||
const normalizedValue = normalizeValueWithProperty(value, type);
|
||||
return `${type}(${normalizedValue})`;
|
||||
}
|
||||
};
|
||||
|
||||
const resolveTransform = (resolvedStyle, style) => {
|
||||
let transform = style.transform;
|
||||
if (Array.isArray(style.transform)) {
|
||||
transform = style.transform.map(mapTransform).join(' ');
|
||||
} else if (style.transformMatrix) {
|
||||
transform = convertTransformMatrix(style.transformMatrix);
|
||||
}
|
||||
resolvedStyle.transform = transform;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user