[fix] View transforms; add perspective styles

Fixes a regression introduced by
5db300df35

The `perspective` function is distinct from the `perspective` property.
This patch reverts the regression and adds support for `perspective`,
`perspectiveOrigin`, and `transformOrigin`.

Fix #208
This commit is contained in:
Nicolas Gallagher
2017-01-07 19:02:57 -08:00
parent af5fde994d
commit 768e895701
5 changed files with 14 additions and 19 deletions

View File

@@ -172,10 +172,13 @@ from `style`.
+ `paddingRight`
+ `paddingTop`
+ `paddingVertical`
+ `perspective`
+ `perspectiveOrigin`
+ `position`
+ `right`
+ `top`
+ `transform`
+ `transformOrigin`
+ `transitionDelay`
+ `transitionDuration`
+ `transitionProperty`

View File

@@ -16,8 +16,7 @@ describe('apis/StyleSheet/resolveTransform', () => {
resolveTransform(resolvedStyle, style);
expect(resolvedStyle).toEqual({
perspective: '50px',
transform: 'scaleX(20) translateX(20px) rotate(20deg)'
transform: 'perspective(50px) scaleX(20) translateX(20px) rotate(20deg)'
});
});

View File

@@ -1,22 +1,11 @@
import normalizeValue from './normalizeValue';
// [ { perspective: 20 }, { scale: 2 }, { translateX: 20 } ]
// => { perspective: 20px, transform: 'scale(2) translateX(20px)' }
const reduceTransform = (resolvedStyle, transform) => {
// { scale: 2 } => 'scale(2)'
// { translateX: 20 } => 'translateX(20px)'
const mapTransform = (transform) => {
const type = Object.keys(transform)[0];
const value = normalizeValue(type, transform[type]);
if (type === 'perspective') {
resolvedStyle.perspective = value;
} else {
const result = `${type}(${value})`;
if (resolvedStyle.transform) {
resolvedStyle.transform += ` ${result}`;
} else {
resolvedStyle.transform = result;
}
}
return resolvedStyle;
return `${type}(${value})`;
};
// [1,2,3,4,5,6] => 'matrix3d(1,2,3,4,5,6)'
@@ -27,7 +16,8 @@ const convertTransformMatrix = (transformMatrix) => {
const resolveTransform = (resolvedStyle, style) => {
if (Array.isArray(style.transform)) {
style.transform.reduce(reduceTransform, resolvedStyle);
const transform = style.transform.map(mapTransform).join(' ');
resolvedStyle.transform = transform;
} else if (style.transformMatrix) {
const transform = convertTransformMatrix(style.transformMatrix);
resolvedStyle.transform = transform;

View File

@@ -37,6 +37,8 @@ module.exports = process.env.NODE_ENV !== 'production' ? {
outline: string,
overflowX: autoOrHiddenOrVisible,
overflowY: autoOrHiddenOrVisible,
perspective: PropTypes.oneOfType([ number, string ]),
perspectiveOrigin: string,
transitionDelay: string,
transitionDuration: string,
transitionProperty: string,

View File

@@ -28,7 +28,8 @@ const TransformPropTypes = process.env.NODE_ENV !== 'production' ? {
shape({ translateZ: numberOrString }),
shape({ translate3d: string })
])
)
),
transformOrigin: string
} : {};
module.exports = TransformPropTypes;