Skip to content

Commit

Permalink
[fix] Only stringify numeric aspectRatio
Browse files Browse the repository at this point in the history
Close #2561
  • Loading branch information
itsramiel authored and necolas committed Jul 20, 2023
1 parent 213b616 commit 617b438
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ describe('StyleSheet/preprocess', () => {
expect(preprocess({ aspectRatio: 9 / 16 })).toEqual({
aspectRatio: '0.5625'
});

expect(preprocess({ aspectRatio: '0.5' })).toEqual({
aspectRatio: '0.5'
});

expect(preprocess({ aspectRatio: undefined })).toEqual({});
});

test('fontVariant', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const preprocess = <T: {| [key: string]: any |}>(
continue;
}

if (prop === 'aspectRatio') {
if (prop === 'aspectRatio' && typeof value === 'number') {
nextStyle[prop] = value.toString();
} else if (prop === 'fontVariant') {
if (Array.isArray(value) && value.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-web/src/types/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export type LayoutStyles = {|
| 'flex-start'
| 'stretch'
),
aspectRatio?: ?number,
aspectRatio?: ?NumberOrString,
backfaceVisibility?: ?VisiblilityValue,
borderWidth?: ?DimensionValue,
borderBlockWidth?: ?DimensionValue,
Expand Down

0 comments on commit 617b438

Please sign in to comment.