Skip to content

Commit f27dfb6

Browse files
authored
Merge pull request #241 from Skyline-23/master
Add feature for Gap
2 parents 78f50be + e72a228 commit f27dfb6

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,23 @@ This property takes the same values as the width and height properties, and spec
681681

682682
<br>
683683

684+
### gap
685+
- Applies to: `flex containers`
686+
- CSS name: `gap`
687+
688+
**Method:**
689+
690+
* **`columnGap(_ value: CGFloat)`**
691+
This property set distance between columns.
692+
693+
* **`rowGap(_ value: CGFloat)`**
694+
This property set distance between rows.
695+
696+
* **`gap(_ value: CGFloat)`**
697+
This property set distance between both of rows and columns.
698+
699+
<br/>
700+
684701
### isIncludedInLayout()
685702
- Applies to: `flex items`
686703

Sources/Swift/FlexLayout.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,49 @@ public final class Flex {
12131213
return self
12141214
}
12151215

1216+
//
1217+
// MARK: Gap
1218+
//
1219+
1220+
/**
1221+
Set distance between columns.
1222+
1223+
- Parameters:
1224+
- value: distance
1225+
- Returns: flex interface
1226+
*/
1227+
@discardableResult
1228+
public func columnGap(_ value: CGFloat) -> Flex {
1229+
yoga.columnGap = value
1230+
return self
1231+
}
1232+
1233+
/**
1234+
Set distance between rows.
1235+
1236+
- Parameters:
1237+
- value: distance
1238+
- Returns: flex interface
1239+
*/
1240+
@discardableResult
1241+
public func rowGap(_ value: CGFloat) -> Flex {
1242+
yoga.rowGap = value
1243+
return self
1244+
}
1245+
1246+
/**
1247+
Set distance between both of rows and columns.
1248+
1249+
- Parameters:
1250+
- value: distance
1251+
- Returns: flex interface
1252+
*/
1253+
@discardableResult
1254+
public func gap(_ value: CGFloat) -> Flex {
1255+
yoga.gap = value
1256+
return self
1257+
}
1258+
12161259
//
12171260
// MARK: UIView Visual properties
12181261
//

Sources/YogaKit/include/YogaKit/YGLayout.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ typedef NS_OPTIONS(NSInteger, YGDimensionFlexibility) {
115115
// Yoga specific properties, not compatible with flexbox specification
116116
@property(nonatomic, readwrite, assign) CGFloat aspectRatio;
117117

118+
@property(nonatomic, readwrite, assign) CGFloat columnGap;
119+
@property(nonatomic, readwrite, assign) CGFloat rowGap;
120+
@property(nonatomic, readwrite, assign) CGFloat gap;
121+
118122
/**
119123
Get the resolved direction of this node. This won't be YGDirectionInherit
120124
*/

Tests/FlexLayoutTests/WidthSizeContentTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ final class WidthSizeContentTests: XCTestCase {
1818
var viewController: UIViewController!
1919
var rootFlexContainer: UIView!
2020
var aView: UIView!
21+
var bView: UIView!
22+
var cView: UIView!
2123

2224
override func setUp() {
2325
super.setUp()
@@ -29,6 +31,8 @@ final class WidthSizeContentTests: XCTestCase {
2931
viewController.view.addSubview(rootFlexContainer)
3032

3133
aView = UIView()
34+
bView = UIView()
35+
cView = UIView()
3236
}
3337

3438
func test_basis_adjust_aView_size_and_position() {
@@ -159,4 +163,49 @@ final class WidthSizeContentTests: XCTestCase {
159163
rootFlexContainer.flex.layout()
160164
XCTAssertEqual(aView.frame, CGRect(x: 0.0, y: 0.0, width: 400.0, height: 200.0))
161165
}
166+
167+
func test_row_gap() {
168+
rootFlexContainer.flex.direction(.row).define { flex in
169+
flex.addItem(aView).height(100).width(100)
170+
flex.addItem(bView).height(100).width(100)
171+
flex.alignItems(.start)
172+
173+
flex.columnGap(50)
174+
}
175+
176+
rootFlexContainer.flex.layout()
177+
XCTAssertEqual(bView.frame, CGRect(x: 150.0, y: 0.0, width: 100.0, height: 100.0))
178+
}
179+
180+
func test_column_gap() {
181+
rootFlexContainer.flex.direction(.column).define { flex in
182+
flex.addItem(aView).height(100).width(100)
183+
flex.addItem(bView).height(100).width(100)
184+
flex.alignItems(.start)
185+
186+
flex.rowGap(50)
187+
}
188+
189+
rootFlexContainer.flex.layout()
190+
XCTAssertEqual(bView.frame, CGRect(x: 0.0, y: 150.0, width: 100.0, height: 100.0))
191+
}
192+
193+
func test_gap() {
194+
rootFlexContainer.flex.direction(.column).define { flex in
195+
flex.addItem().direction(.row).define { flex in
196+
flex.addItem(aView).height(100).width(100)
197+
flex.addItem(bView).height(100).width(100)
198+
flex.gap(50)
199+
}
200+
flex.addItem(cView).height(100).width(100)
201+
202+
flex.alignItems(.start)
203+
flex.gap(50)
204+
}
205+
206+
rootFlexContainer.flex.layout()
207+
208+
XCTAssertEqual(bView.frame, CGRect(x: 150.0, y: 0.0, width: 100.0, height: 100.0))
209+
XCTAssertEqual(cView.frame, CGRect(x: 0.0, y: 150.0, width: 100.0, height: 100.0))
210+
}
162211
}

0 commit comments

Comments
 (0)