mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-05-17 12:34:48 +00:00
[fix] check 'transform' style is array before mapping
This commit is contained in:
@@ -3,7 +3,18 @@
|
||||
import resolveTransform from '../resolveTransform';
|
||||
|
||||
describe('apis/StyleSheet/resolveTransform', () => {
|
||||
test('transform', () => {
|
||||
// passthrough if transform value is ever a string
|
||||
test('transform string', () => {
|
||||
const resolvedStyle = {};
|
||||
const transform = 'perspective(50px) scaleX(20) translateX(20px) rotate(20deg)';
|
||||
|
||||
const style = { transform };
|
||||
resolveTransform(resolvedStyle, style);
|
||||
|
||||
expect(resolvedStyle).toEqual({ transform });
|
||||
});
|
||||
|
||||
test('transform array', () => {
|
||||
const resolvedStyle = {};
|
||||
const style = {
|
||||
transform: [{ perspective: 50 }, { scaleX: 20 }, { translateX: 20 }, { rotate: '20deg' }]
|
||||
|
||||
@@ -71,15 +71,17 @@ const i18nStyle = originalStyle => {
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = style[prop];
|
||||
|
||||
if (PROPERTIES_TO_SWAP[prop]) {
|
||||
const newProp = flipProperty(prop);
|
||||
nextStyle[newProp] = style[prop];
|
||||
nextStyle[newProp] = value;
|
||||
} else if (PROPERTIES_SWAP_LEFT_RIGHT[prop]) {
|
||||
nextStyle[prop] = swapLeftRight(style[prop]);
|
||||
nextStyle[prop] = swapLeftRight(value);
|
||||
} else if (prop === 'textShadowOffset') {
|
||||
nextStyle[prop] = style[prop];
|
||||
nextStyle[prop].width = additiveInverse(style[prop].width);
|
||||
} else if (prop === 'transform') {
|
||||
nextStyle[prop] = value;
|
||||
nextStyle[prop].width = additiveInverse(value.width);
|
||||
} else if (prop === 'transform' && Array.isArray(value)) {
|
||||
nextStyle[prop] = style[prop].map(flipTransform);
|
||||
} else {
|
||||
nextStyle[prop] = style[prop];
|
||||
|
||||
@@ -15,13 +15,13 @@ const convertTransformMatrix = transformMatrix => {
|
||||
};
|
||||
|
||||
const resolveTransform = (resolvedStyle, style) => {
|
||||
let transform = style.transform;
|
||||
if (Array.isArray(style.transform)) {
|
||||
const transform = style.transform.map(mapTransform).join(' ');
|
||||
resolvedStyle.transform = transform;
|
||||
transform = style.transform.map(mapTransform).join(' ');
|
||||
} else if (style.transformMatrix) {
|
||||
const transform = convertTransformMatrix(style.transformMatrix);
|
||||
resolvedStyle.transform = transform;
|
||||
transform = convertTransformMatrix(style.transformMatrix);
|
||||
}
|
||||
resolvedStyle.transform = transform;
|
||||
};
|
||||
|
||||
module.exports = resolveTransform;
|
||||
|
||||
Reference in New Issue
Block a user