Skip to content

Commit 3ee1593

Browse files
committed
Add all() + some tests
1 parent d51ee83 commit 3ee1593

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

FlexLayoutTests/AbsolutionPositionContentSpec.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,25 @@ class AbsolutionPositionContentSpec: QuickSpec {
5858
rootFlexContainer.flex.layout()
5959
expect(aView.frame).to(equal(CGRect(x: 0.0, y: 0.0, width: 300.0, height: 200.0)))
6060
}
61+
62+
it("position(.absolute)") {
63+
rootFlexContainer.flex.define { (flex) in
64+
flex.addItem(aView).position(.absolute).horizontally(15).vertically(20)
65+
}
66+
67+
rootFlexContainer.flex.layout()
68+
expect(aView.frame).to(equal(CGRect(x: 15.0, y: 20.0, width: 370.0, height: 360.0)))
69+
}
70+
71+
it("position(.absolute)") {
72+
rootFlexContainer.flex.define { (flex) in
73+
flex.addItem(aView).position(.absolute).all(45)
74+
}
75+
76+
rootFlexContainer.flex.layout()
77+
expect(aView.frame).to(equal(CGRect(x: 45.0, y: 45.0, width: 310.0, height: 310.0)))
78+
}
79+
6180
}
6281
}
6382
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ The position property tells Flexbox how you want your item to be positioned with
780780
view.flex.position(.absolute).top(10).left(10).size(50)
781781
```
782782

783-
### top(), bottom(), left(), right(), start(), end(), vertically(), horizontally()
783+
### top(), bottom(), left(), right(), start(), end(), vertically(), horizontally(), all()
784784
A flex item which is `position` is set to `.absolute` is positioned absolutely in regards to its parent. This is done through the following methods:
785785

786786
**Methods:**
@@ -801,7 +801,8 @@ Controls the distance a child’s end edge is from the parent’s end edge. In l
801801
Controls the distance child’s top and bottom edges from the parent’s edges. Equal to `top().bottom()`.
802802
* **`horizontally(: CGFloat)`** / **`horizontally(: FPercent)`**:
803803
Controls the distance child’s left and right edges from the parent’s edges. Equal to `left().right()`.
804-
804+
* **`all(: CGFloat)`** / **`all(: FPercent)`**:
805+
Controls the distance child’s edges from the parent’s edges. Equal to `top().bottom().left().right()`.
805806

806807
Using these properties you can control the size and position of an absolute item within its parent. Because absolutely positioned children don’t affect their sibling's layout. Absolute position can be used to create overlays and stack children in the Z axis.
807808

Sources/FlexLayout.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,32 @@ public final class Flex {
692692
return self
693693
}
694694

695+
/**
696+
Set all edges distance from the container edges in pixels.
697+
This method is valid only when the item position is absolute (`view.flex.position(.absolute)`)
698+
*/
699+
@discardableResult
700+
public func all(_ value: CGFloat) -> Flex {
701+
yoga.top = YGValue(value)
702+
yoga.left = YGValue(value)
703+
yoga.bottom = YGValue(value)
704+
yoga.right = YGValue(value)
705+
return self
706+
}
707+
708+
/**
709+
Set all edges distance from the container edges in percentage of its container size.
710+
This method is valid only when the item position is absolute (`view.flex.position(.absolute)`)
711+
*/
712+
@discardableResult
713+
public func all(_ percent: FPercent) -> Flex {
714+
yoga.top = YGValue(value: Float(percent.value), unit: .percent)
715+
yoga.left = YGValue(value: Float(percent.value), unit: .percent)
716+
yoga.bottom = YGValue(value: Float(percent.value), unit: .percent)
717+
yoga.right = YGValue(value: Float(percent.value), unit: .percent)
718+
return self
719+
}
720+
695721
//
696722
// MARK: Margins
697723
//

0 commit comments

Comments
 (0)