Skip to content

Commit dd0b668

Browse files
author
Nir Hadassi
committed
Handle negatives on ScaledSheet
1 parent a59a315 commit dd0b668

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

Diff for: __tests__/ScaledSheet.spec.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ const input = {
88
height: '50@vs',
99
margin: {
1010
width: 12,
11-
height: '12@s'
11+
height: '12@s',
12+
paddingBottom: -1
1213
}
1314
},
1415
row: {
1516
padding: '10@ms0.3',
1617
height: '34@ms',
17-
margin: '0.5@ms0.9'
18+
marginRight: '0.5@ms0.9',
19+
marginLeft: '-0.5@ms0.9',
20+
marginTop: '-10@s',
1821
}
1922
};
2023

@@ -24,13 +27,16 @@ const expectedOutput = {
2427
height: verticalScale(50),
2528
margin: {
2629
width: 12,
27-
height: scale(12)
30+
height: scale(12),
31+
paddingBottom: -1
2832
}
2933
},
3034
row: {
3135
padding: moderateScale(10, 0.3),
3236
height: moderateScale(34),
33-
margin: moderateScale(0.5, 0.9)
37+
marginRight: moderateScale(0.5, 0.9),
38+
marginLeft: moderateScale(-0.5, 0.9),
39+
marginTop: scale(-10),
3440
}
3541
};
3642

Diff for: lib/ScaledSheet.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { StyleSheet } from 'react-native';
22
import { moderateScale, scale, verticalScale } from './scalingUtils';
33
import deepMap from './deepMap';
44

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

1010
const scaleByAnnotation = (value) => {
1111
if (!validScaleSheetRegex.test(value)) {

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-size-matters",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "A React-Native utility belt for scaling the size your apps UI across different sized devices",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)