Skip to content

Commit fcbe2d1

Browse files
Freddy03hnecolas
authored andcommitted
[fix] Support array syntax on transformOrigin
1 parent 0d5fb0f commit fcbe2d1

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

packages/react-native-web/src/exports/StyleSheet/__tests__/preprocess-test.js

+22
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ describe('StyleSheet/preprocess', () => {
188188
});
189189
});
190190
});
191+
192+
describe('transformOrigin', () => {
193+
// passthrough if transformOrigin value is ever a string
194+
test('string', () => {
195+
const transformOrigin = '2px 30% 10px';
196+
const style = { transformOrigin };
197+
const resolved = preprocess(style);
198+
199+
expect(resolved).toEqual({ transformOrigin });
200+
});
201+
202+
test('array', () => {
203+
const style = {
204+
transformOrigin: [2, '30%', 10]
205+
};
206+
const resolved = preprocess(style);
207+
208+
expect(resolved).toEqual({
209+
transformOrigin: '2px 30% 10px'
210+
});
211+
});
212+
});
191213
});
192214

193215
describe('preprocesses multiple shadow styles into a single declaration', () => {

packages/react-native-web/src/exports/StyleSheet/preprocess.js

+12
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ export const createTransformValue = (value: Array<Object>): string => {
9292
return value.map(mapTransform).join(' ');
9393
};
9494

95+
// [2, '30%', 10] => '2px 30% 10px'
96+
export const createTransformOriginValue = (
97+
value: Array<number | string>
98+
): string => {
99+
return value.map((v) => normalizeValueWithProperty(v)).join(' ');
100+
};
101+
95102
const PROPERTIES_STANDARD: { [key: string]: string } = {
96103
borderBottomEndRadius: 'borderEndEndRadius',
97104
borderBottomStartRadius: 'borderEndStartRadius',
@@ -231,6 +238,11 @@ export const preprocess = <T: {| [key: string]: any |}>(
231238
value = createTransformValue(value);
232239
}
233240
nextStyle.transform = value;
241+
} else if (prop === 'transformOrigin') {
242+
if (Array.isArray(value)) {
243+
value = createTransformOriginValue(value);
244+
}
245+
nextStyle.transformOrigin = value;
234246
} else {
235247
nextStyle[prop] = value;
236248
}

packages/react-native-web/src/types/styles.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,6 @@ export type TransformStyles = {|
341341
| {| +translateZ: NumberOrString |}
342342
| {| +translate3d: string |}
343343
>,
344-
transformOrigin?: ?string,
344+
transformOrigin?: ?string | Array<NumberOrString>,
345345
transformStyle?: ?('flat' | 'preserve-3d')
346346
|};

0 commit comments

Comments
 (0)