diff --git a/src/Layout.js b/src/Layout.js index 90549a86..dff63f01 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -467,15 +467,26 @@ var computeLayout = (function() { for (var/*int*/ i = 0; i < node.children.length; ++i) { var/*css_node_t**/ child = node.children[i]; + var/*bool*/ leadingPos = isPosDefined(child, leading[crossAxis]); + var/*bool*/ trailingPos = isPosDefined(child, trailing[crossAxis]); + if (getPositionType(child) === CSS_POSITION_ABSOLUTE && - isPosDefined(child, leading[crossAxis])) { + (leadingPos || trailingPos)) { // In case the child is absolutely positionned and has a // top/left/bottom/right being set, we override all the previously // computed positions to set it correctly. - child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) + - getBorder(node, leading[crossAxis]) + - getMargin(child, leading[crossAxis]); - + if (leadingPos && !trailingPos) { + child.layout[pos[crossAxis]] = + getPosition(child, leading[crossAxis]) + + getBorder(node, leading[crossAxis]) + + getMargin(child, leading[crossAxis]); + } + if (!leadingPos && trailingPos) { + child.layout[pos[crossAxis]] = + node.layout[dim[crossAxis]] - + getDimWithMargin(child, crossAxis) - + getPosition(child, trailing[crossAxis]); + } } else { var/*float*/ leadingCrossDim = getPaddingAndBorder(node, leading[crossAxis]); diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index 423212fc..1c3b5804 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -906,6 +906,17 @@ describe('Layout', function() { ); }); + it('should layout with position absolute right', function() { + testLayout( + {style: {}, children: [ + {style: {right: 5, borderWidth: 5, position: 'absolute'}} + ]}, + {width: 0, height: 0, top: 0, left: 0, children: [ + {width: 10, height: 10, top: 0, left: -15} + ]} + ); + }); + xit('should layout text with alignItems: stretch', function() { testLayout( {style: {width: 80, padding: 7, alignItems: 'stretch', measure: text('loooooooooong with space')}}, @@ -937,9 +948,6 @@ describe('Layout', function() { var rng = new RNG(0); function randMinMax(node, chance, attribute, min, max) { if (rng.nextFloat() < chance) { - if (attribute === 'right' || attribute === 'bottom') { - return; - } node.style[attribute] = Math.floor(rng.nextFloat() * (max - min)) + min; } }