@@ -26,7 +26,7 @@ import FlexLayoutYogaKit
2626 label.flex.margin(10)
2727 ```
2828 */
29- public final class Flex {
29+ public final class Flex < Base : UIView > {
3030
3131 //
3232 // MARK: Properties
@@ -35,20 +35,22 @@ public final class Flex {
3535 /**
3636 Flex items's UIView.
3737 */
38- public private( set) weak var view : UIView ?
38+ public private( set) weak var base : Base ?
3939 private let yoga : YGLayout
4040
41+ public var view : UIView ? { base }
42+
4143 /**
4244 Item natural size, considering only properties of the view itself. Independent of the item frame.
4345 */
4446 public var intrinsicSize : CGSize {
4547 return yoga. intrinsicSize
4648 }
4749
48- init ( view : UIView ) {
49- self . view = view
50- self . yoga = view . yoga
51-
50+ init ( _ base : Base ) {
51+ self . base = base
52+ self . yoga = base . yoga
53+
5254 // Enable flexbox and overwrite Yoga default values.
5355 yoga. isEnabled = true
5456 }
@@ -66,7 +68,7 @@ public final class Flex {
6668 - Returns: The flex interface corresponding to the added view.
6769 */
6870 @discardableResult
69- public func addItem( ) -> Flex {
71+ public func addItem( ) -> Flex < UIView > {
7072 let view = UIView ( )
7173 return addItem ( view)
7274 }
@@ -80,8 +82,8 @@ public final class Flex {
8082 - Returns: The flex interface corresponding to the added view.
8183 */
8284 @discardableResult
83- public func addItem( _ view: UIView ) -> Flex {
84- if let host = self . view {
85+ public func addItem< Item : UIView > ( _ view: Item ) -> Flex < Item > {
86+ if let host = base {
8587 host. addSubview ( view)
8688 return view. flex
8789 } else {
@@ -1278,7 +1280,7 @@ public final class Flex {
12781280 */
12791281 @discardableResult
12801282 public func backgroundColor( _ color: UIColor ) -> Flex {
1281- if let host = self . view {
1283+ if let host = base {
12821284 host. backgroundColor = color
12831285 return self
12841286 } else {
@@ -1295,7 +1297,7 @@ public final class Flex {
12951297 */
12961298 @discardableResult
12971299 public func cornerRadius( _ value: CGFloat ) -> Flex {
1298- if let host = self . view {
1300+ if let host = base {
12991301 host. layer. cornerRadius = value
13001302 return self
13011303 } else {
@@ -1313,7 +1315,7 @@ public final class Flex {
13131315 */
13141316 @discardableResult
13151317 public func border( _ width: CGFloat , _ color: UIColor ) -> Flex {
1316- if let host = self . view {
1318+ if let host = base {
13171319 host. layer. borderWidth = width
13181320 host. layer. borderColor = color. cgColor
13191321 return self
0 commit comments