Skip to content

Commit f78bea5

Browse files
authored
Merge pull request #213 from gyuchan/master
Add direction property in Flex class
2 parents dc4235f + 8cdf133 commit f78bea5

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ This section describes all flex container's properties.
439439
- Default value: `column`
440440
- CSS name: `flex-direction`
441441

442+
**Property:**
443+
444+
* **`direction: Direction?`**
445+
442446
**Method:**
443447

444448
* **`direction(_: Direction)`**

Sources/Swift/FlexLayout.swift

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,34 @@ public final class Flex {
169169
//
170170
// MARK: Direction, wrap, flow
171171
//
172-
172+
173+
/**
174+
The `direction` property establishes the main-axis, thus defining the direction flex items are placed in the flex container.
175+
176+
The `direction` property specifies how flex items are laid out in the flex container, by setting the direction of the flex
177+
container’s main axis. They can be laid out in two main directions, like columns vertically or like rows horizontally.
178+
179+
Note that row and row-reverse are affected by the layout direction (see `layoutDirection` property) of the flex container.
180+
If its text direction is LTR (left to right), row represents the horizontal axis oriented from left to right, and row-reverse
181+
from right to left; if the direction is rtl, it's the opposite.
182+
183+
- Parameter value: Default value is .column
184+
*/
185+
public var direction: Direction? {
186+
get {
187+
switch yoga.flexDirection {
188+
case .column: return Flex.Direction.column
189+
case .columnReverse: return Flex.Direction.columnReverse
190+
case .row: return Flex.Direction.row
191+
case .rowReverse: return Flex.Direction.rowReverse
192+
@unknown default: return nil
193+
}
194+
}
195+
set {
196+
direction(newValue ?? .column)
197+
}
198+
}
199+
173200
/**
174201
The `direction` property establishes the main-axis, thus defining the direction flex items are placed in the flex container.
175202

0 commit comments

Comments
 (0)