From dd0b6684c9e8e88eb74f53284b2ce67e95231489 Mon Sep 17 00:00:00 2001 From: Nir Hadassi Date: Sun, 19 Aug 2018 10:54:22 +0300 Subject: [PATCH] Handle negatives on ScaledSheet --- __tests__/ScaledSheet.spec.js | 14 ++++++++++---- lib/ScaledSheet.js | 8 ++++---- package.json | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/__tests__/ScaledSheet.spec.js b/__tests__/ScaledSheet.spec.js index cb337bf..18c04dc 100644 --- a/__tests__/ScaledSheet.spec.js +++ b/__tests__/ScaledSheet.spec.js @@ -8,13 +8,16 @@ const input = { height: '50@vs', margin: { width: 12, - height: '12@s' + height: '12@s', + paddingBottom: -1 } }, row: { padding: '10@ms0.3', height: '34@ms', - margin: '0.5@ms0.9' + marginRight: '0.5@ms0.9', + marginLeft: '-0.5@ms0.9', + marginTop: '-10@s', } }; @@ -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), } }; diff --git a/lib/ScaledSheet.js b/lib/ScaledSheet.js index ad1c66a..d653c4f 100644 --- a/lib/ScaledSheet.js +++ b/lib/ScaledSheet.js @@ -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)) { diff --git a/package.json b/package.json index f93c8ea..7e61c06 100644 --- a/package.json +++ b/package.json @@ -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": {