Skip to content

Commit 3a0cc73

Browse files
petrbelanecolas
authored andcommitted
[fix] Convert 'aspectRatio' style value to string
The RN value is a number and the CSS value must be a string. Close #2038
1 parent 17d8b12 commit 3a0cc73

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ describe('StyleSheet/createReactDOMStyle', () => {
3939
expect(createReactDOMStyle(style)).toMatchSnapshot();
4040
});
4141

42+
test('aspectRatio', () => {
43+
expect(createReactDOMStyle({ aspectRatio: 9 / 16 })).toEqual({
44+
aspectRatio: '0.5625'
45+
});
46+
});
47+
4248
describe('flexbox styles', () => {
4349
test('flex: -1', () => {
4450
expect(createReactDOMStyle({ flex: -1 })).toEqual({

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ const createReactDOMStyle = (style) => {
8787
break;
8888
}
8989

90+
case 'aspectRatio': {
91+
resolvedStyle[prop] = value.toString();
92+
break;
93+
}
94+
9095
// TODO: remove once this issue is fixed
9196
// https://github.com/rofrischmann/inline-style-prefixer/issues/159
9297
case 'backgroundClip': {

packages/react-native-web/src/modules/unitlessNumbers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
const unitlessNumbers = {
1212
animationIterationCount: true,
13+
aspectRatio: true,
1314
borderImageOutset: true,
1415
borderImageSlice: true,
1516
borderImageWidth: true,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export type LayoutStyles = {|
154154
| 'stretch',
155155
alignItems?: ?('baseline' | 'center' | 'flex-end' | 'flex-start' | 'stretch'),
156156
alignSelf?: ?('auto' | 'baseline' | 'center' | 'flex-end' | 'flex-start' | 'stretch'),
157+
aspectRatio?: ?number,
157158
backfaceVisibility?: ?VisiblilityValue,
158159
borderWidth?: ?DimensionValue,
159160
borderBottomWidth?: ?DimensionValue,
@@ -216,10 +217,6 @@ export type LayoutStyles = {|
216217
visibility?: ?VisiblilityValue,
217218
width?: ?DimensionValue,
218219
zIndex?: ?number,
219-
/**
220-
* @platform unsupported
221-
*/
222-
aspectRatio?: ?number,
223220
/**
224221
* @platform web
225222
*/

0 commit comments

Comments
 (0)