mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-01 09:27:14 +08:00
30 lines
864 B
JavaScript
30 lines
864 B
JavaScript
import normalizeValue from './normalizeValue';
|
|
|
|
// { scale: 2 } => 'scale(2)'
|
|
// { translateX: 20 } => 'translateX(20px)'
|
|
const mapTransform = (transform) => {
|
|
const type = Object.keys(transform)[0];
|
|
const value = normalizeValue(type, transform[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 processTransform = (style) => {
|
|
if (style) {
|
|
if (style.transform && Array.isArray(style.transform)) {
|
|
style.transform = style.transform.map(mapTransform).join(' ');
|
|
} else if (style.transformMatrix) {
|
|
style.transform = convertTransformMatrix(style.transformMatrix);
|
|
style.transformMatrix = null;
|
|
}
|
|
}
|
|
return style;
|
|
};
|
|
|
|
module.exports = processTransform;
|