Skip to content

Commit 8cdf133

Browse files
committed
Apply code review
- Changed get & set the value using the property. - Move the property definition just above the direction(_ value: Direction) method definition. - Changed documentation description
1 parent 562aadb commit 8cdf133

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

README.md

Lines changed: 4 additions & 10 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)`**
@@ -755,16 +759,6 @@ Item natural size, considering only properties of the view itself. Independent o
755759

756760
<br>
757761

758-
### direction
759-
- Applies to: `flex items`
760-
761-
**Property:**
762-
763-
* **`direction`**
764-
This `direction` property is get the direction flex items are placed in the flex container.
765-
766-
<br>
767-
768762
<a name="absolute_positioning"></a>
769763
## 4. Absolute positioning
770764
- Applies to: `flex items`

Sources/Swift/FlexLayout.swift

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@ public final class Flex {
4343
public var intrinsicSize: CGSize {
4444
return yoga.intrinsicSize
4545
}
46-
47-
/**
48-
This`direction` property is get the direction flex items are placed in the flex container.
49-
*/
50-
public var direction: Direction? {
51-
switch yoga.flexDirection {
52-
case .column: return Flex.Direction.column
53-
case .columnReverse: return Flex.Direction.columnReverse
54-
case .row: return Flex.Direction.row
55-
case .rowReverse: return Flex.Direction.rowReverse
56-
@unknown default: return nil
57-
}
58-
}
5946

6047
init(view: UIView) {
6148
self.view = view
@@ -182,7 +169,34 @@ public final class Flex {
182169
//
183170
// MARK: Direction, wrap, flow
184171
//
185-
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+
186200
/**
187201
The `direction` property establishes the main-axis, thus defining the direction flex items are placed in the flex container.
188202

0 commit comments

Comments
 (0)