Skip to content

Commit

Permalink
Fix scaling factor handling in moderateVerticalScale function.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyYuhimovich committed Aug 19, 2020
1 parent 0aaac86 commit e08df73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/ScaledSheet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StyleSheet } from 'react-native';
import deepMap from './deep-map';

const validScaleSheetRegex = /^(\-?\d+(\.\d{1,3})?)@(ms(\d+(\.\d{1,2})?)?|s|vs|mvs)(r?)$/;
const validScaleSheetRegex = /^(\-?\d+(\.\d{1,3})?)@(ms(\d+(\.\d{1,2})?)?|mvs(\d+(\.\d{1,2})?)?|s|vs)(r?)$/;

const scaleByAnnotation = (scale, verticalScale, moderateScale, moderateVerticalScale) => (value) => {
if (!validScaleSheetRegex.test(value)) {
Expand Down Expand Up @@ -29,8 +29,13 @@ const scaleByAnnotation = (scale, verticalScale, moderateScale, moderateVertical
result = moderateVerticalScale(size);
break;
default:
const scaleFactor = value.split('ms')[1].replace('r', '');
result = moderateScale(size, parseFloat(scaleFactor));
if (value.includes('ms')) {
const scaleFactor = value.split('ms')[1].replace('r', '');
result = moderateScale(size, parseFloat(scaleFactor));
} else if (value.includes('mvs')) {
const scaleFactor = value.split('mvs')[1].replace('r', '');
result = moderateVerticalScale(size, parseFloat(scaleFactor));
}
}

return shouldRound ? Math.round(result) : result;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-size-matters",
"version": "0.3.2",
"version": "0.3.3",
"description": "A React-Native utility belt for scaling the size your apps UI across different sized devices",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit e08df73

Please sign in to comment.