Skip to content

Commit

Permalink
Handle negatives on ScaledSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir Hadassi committed Aug 19, 2018
1 parent a59a315 commit dd0b668
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
14 changes: 10 additions & 4 deletions __tests__/ScaledSheet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ const input = {
height: '50@vs',
margin: {
width: 12,
height: '12@s'
height: '12@s',
paddingBottom: -1
}
},
row: {
padding: '[email protected]',
height: '34@ms',
margin: '[email protected]'
marginRight: '[email protected]',
marginLeft: '[email protected]',
marginTop: '-10@s',
}
};

Expand All @@ -24,13 +27,16 @@ const expectedOutput = {
height: verticalScale(50),
margin: {
width: 12,
height: scale(12)
height: scale(12),
paddingBottom: -1
}
},
row: {
padding: moderateScale(10, 0.3),
height: moderateScale(34),
margin: moderateScale(0.5, 0.9)
marginRight: moderateScale(0.5, 0.9),
marginLeft: moderateScale(-0.5, 0.9),
marginTop: scale(-10),
}
};

Expand Down
8 changes: 4 additions & 4 deletions lib/ScaledSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { StyleSheet } from 'react-native';
import { moderateScale, scale, verticalScale } from './scalingUtils';
import deepMap from './deepMap';

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

const scaleByAnnotation = (value) => {
if (!validScaleSheetRegex.test(value)) {
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.1.2",
"version": "0.1.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 dd0b668

Please sign in to comment.