@@ -58,9 +58,12 @@ public final class Flex {
58
58
//
59
59
60
60
/**
61
- This method adds a flex item (UIView) to a flex container. Internally the methods adds the UIView has subviews and enables flexbox.
61
+ Adds a flex item (`UIView`) to the receiver and returns the item's flex interface.
62
+
63
+ This method internally creates a new `UIView` instance corresponding to the flex item,
64
+ and is useful for adding a flex item/container when you don't need to refer to it later.
62
65
63
- - Returns: The added view flex interface
66
+ - Returns: The flex interface corresponding to the added view.
64
67
*/
65
68
@discardableResult
66
69
public func addItem( ) -> Flex {
@@ -69,15 +72,23 @@ public final class Flex {
69
72
}
70
73
71
74
/**
72
- This method is similar to `addItem(: UIView)` except that it also creates the flex item's UIView. Internally the method creates an
73
- UIView, adds it has subviews and enables flexbox. This is useful to add a flex item/container easily when you don't need to refer to it later.
75
+ Adds a flex item (`UIView`) to the receiver and returns the item's flex interface.
76
+
77
+ This method enables flexbox for `view` and adds it as a subview of the receiver's associated host view.
74
78
75
- - Parameter view: view to add to the flex container
76
- - Returns: The added view flex interface
79
+ Just as views can only have one superview, Yoga nodes should only have one parent node. If `view`
80
+ already has a superview, this method removes `view`'s associated yoga node as a child from the superview's
81
+ associated yoga node.
82
+
83
+ - Parameter view: The view to be added.
84
+ - Returns: The flex interface corresponding to the added view.
77
85
*/
78
86
@discardableResult
79
87
public func addItem( _ view: UIView ) -> Flex {
80
88
if let host = self . view {
89
+ if let superview = view. superview, superview != host && superview. isYogaEnabled {
90
+ YGNodeRemoveChild ( superview. yoga. node, view. yoga. node)
91
+ }
81
92
host. addSubview ( view)
82
93
return view. flex
83
94
} else {
0 commit comments