diff --git a/src/Layout.js b/src/Layout.js index caa2c228..800bf887 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -46,6 +46,20 @@ var computeLayout = (function() { return 0; } + function getPositiveSpacing(node, type, suffix, location) { + var key = type + capitalizeFirst(location) + suffix; + if (key in node.style && node.style[key] >= 0) { + return node.style[key]; + } + + key = type + suffix; + if (key in node.style && node.style[key] >= 0) { + return node.style[key]; + } + + return 0; + } + function isUndefined(value) { return value == undefined; } @@ -55,11 +69,11 @@ var computeLayout = (function() { } function getPadding(node, location) { - return getSpacing(node, 'padding', '', location); + return getPositiveSpacing(node, 'padding', '', location); } function getBorder(node, location) { - return getSpacing(node, 'border', 'Width', location); + return getPositiveSpacing(node, 'border', 'Width', location); } function getPaddingAndBorder(node, location) { diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index 8d6e2052..db7497b8 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -761,9 +761,9 @@ describe('Layout', function() { randMinMax(node, 0.5, 'left', -10, 10); randMinMax(node, 0.5, 'right', -10, 10); randMinMax(node, 0.5, 'bottom', -10, 10); - randSpacing(node, 0.5, 'margin', '', 0, 20); - randSpacing(node, 0.5, 'padding', '', 0, 20); - randSpacing(node, 0.5, 'border', 'Width', 0, 4); + randSpacing(node, 0.5, 'margin', '', -10, 20); + randSpacing(node, 0.5, 'padding', '', -10, 20); + randSpacing(node, 0.5, 'border', 'Width', -4, 4); randEnum(node, 0.5, 'flexDirection', ['column', 'row']); randEnum(node, 0.5, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']); randEnum(node, 0.5, 'alignItems', ['flex-start', 'center', 'flex-end', 'stretch']);