mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-08 12:32:58 +00:00
[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:
@@ -172,10 +172,13 @@ from `style`.
|
|||||||
+ `paddingRight`‡
|
+ `paddingRight`‡
|
||||||
+ `paddingTop`
|
+ `paddingTop`
|
||||||
+ `paddingVertical`
|
+ `paddingVertical`
|
||||||
|
+ `perspective`
|
||||||
|
+ `perspectiveOrigin`
|
||||||
+ `position`
|
+ `position`
|
||||||
+ `right`‡
|
+ `right`‡
|
||||||
+ `top`
|
+ `top`
|
||||||
+ `transform`
|
+ `transform`
|
||||||
|
+ `transformOrigin`
|
||||||
+ `transitionDelay`
|
+ `transitionDelay`
|
||||||
+ `transitionDuration`
|
+ `transitionDuration`
|
||||||
+ `transitionProperty`
|
+ `transitionProperty`
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ describe('apis/StyleSheet/resolveTransform', () => {
|
|||||||
resolveTransform(resolvedStyle, style);
|
resolveTransform(resolvedStyle, style);
|
||||||
|
|
||||||
expect(resolvedStyle).toEqual({
|
expect(resolvedStyle).toEqual({
|
||||||
perspective: '50px',
|
transform: 'perspective(50px) scaleX(20) translateX(20px) rotate(20deg)'
|
||||||
transform: 'scaleX(20) translateX(20px) rotate(20deg)'
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
import normalizeValue from './normalizeValue';
|
import normalizeValue from './normalizeValue';
|
||||||
|
|
||||||
// [ { perspective: 20 }, { scale: 2 }, { translateX: 20 } ]
|
// { scale: 2 } => 'scale(2)'
|
||||||
// => { perspective: 20px, transform: 'scale(2) translateX(20px)' }
|
// { translateX: 20 } => 'translateX(20px)'
|
||||||
const reduceTransform = (resolvedStyle, transform) => {
|
const mapTransform = (transform) => {
|
||||||
const type = Object.keys(transform)[0];
|
const type = Object.keys(transform)[0];
|
||||||
const value = normalizeValue(type, transform[type]);
|
const value = normalizeValue(type, transform[type]);
|
||||||
|
return `${type}(${value})`;
|
||||||
if (type === 'perspective') {
|
|
||||||
resolvedStyle.perspective = value;
|
|
||||||
} else {
|
|
||||||
const result = `${type}(${value})`;
|
|
||||||
if (resolvedStyle.transform) {
|
|
||||||
resolvedStyle.transform += ` ${result}`;
|
|
||||||
} else {
|
|
||||||
resolvedStyle.transform = result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return resolvedStyle;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// [1,2,3,4,5,6] => 'matrix3d(1,2,3,4,5,6)'
|
// [1,2,3,4,5,6] => 'matrix3d(1,2,3,4,5,6)'
|
||||||
@@ -27,7 +16,8 @@ const convertTransformMatrix = (transformMatrix) => {
|
|||||||
|
|
||||||
const resolveTransform = (resolvedStyle, style) => {
|
const resolveTransform = (resolvedStyle, style) => {
|
||||||
if (Array.isArray(style.transform)) {
|
if (Array.isArray(style.transform)) {
|
||||||
style.transform.reduce(reduceTransform, resolvedStyle);
|
const transform = style.transform.map(mapTransform).join(' ');
|
||||||
|
resolvedStyle.transform = transform;
|
||||||
} else if (style.transformMatrix) {
|
} else if (style.transformMatrix) {
|
||||||
const transform = convertTransformMatrix(style.transformMatrix);
|
const transform = convertTransformMatrix(style.transformMatrix);
|
||||||
resolvedStyle.transform = transform;
|
resolvedStyle.transform = transform;
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ module.exports = process.env.NODE_ENV !== 'production' ? {
|
|||||||
outline: string,
|
outline: string,
|
||||||
overflowX: autoOrHiddenOrVisible,
|
overflowX: autoOrHiddenOrVisible,
|
||||||
overflowY: autoOrHiddenOrVisible,
|
overflowY: autoOrHiddenOrVisible,
|
||||||
|
perspective: PropTypes.oneOfType([ number, string ]),
|
||||||
|
perspectiveOrigin: string,
|
||||||
transitionDelay: string,
|
transitionDelay: string,
|
||||||
transitionDuration: string,
|
transitionDuration: string,
|
||||||
transitionProperty: string,
|
transitionProperty: string,
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ const TransformPropTypes = process.env.NODE_ENV !== 'production' ? {
|
|||||||
shape({ translateZ: numberOrString }),
|
shape({ translateZ: numberOrString }),
|
||||||
shape({ translate3d: string })
|
shape({ translate3d: string })
|
||||||
])
|
])
|
||||||
)
|
),
|
||||||
|
transformOrigin: string
|
||||||
} : {};
|
} : {};
|
||||||
|
|
||||||
module.exports = TransformPropTypes;
|
module.exports = TransformPropTypes;
|
||||||
|
|||||||
Reference in New Issue
Block a user