diff --git a/Sources/Layout/Layout.swift b/Sources/Layout/Layout.swift index 9f04f44d..fc9cd6c4 100644 --- a/Sources/Layout/Layout.swift +++ b/Sources/Layout/Layout.swift @@ -11,36 +11,10 @@ import UIKit -/// API for adding subviews and constraints to a view. -/// -/// - Important: -/// * Views are added to view hierarchy in reverse order. The last item in layout call will be at the front. -/// * Must call `.activate()` for constraints to become active. -/// * Activating/Deactivating an instance will only affect the constraints attached to that instance. -/// * Deactivating the instance does not remove or hide views. -/// - Note: -/// * A view can have multiple Layout instances, useful for when a view has different states. -/// * Preferred format for adding one view with one constraint -/// ```` -/// view1.layout(view2.pin()).activate() -/// ```` -/// * Preferred format for adding multiple views or constraints -/// ```` -/// view1.layout( -/// view2 -/// .to([.leading, .top, .trailing]), -/// view3 -/// .pad() -/// .to(.bottom) -/// ) -/// .vertical([view2, view3]) -/// .activate() -/// ```` @preconcurrency @MainActor public final class Layout { // swiftlint:disable:this type_body_length - /// View of the Layout public weak var view: UIView? public let metrics: [String: Any] @@ -86,9 +60,6 @@ public final class Layout { // swiftlint:disable:this type_body_length addItems(items) } - /// Adds constraints to Layout - /// - /// - Parameter constraints: constraints to add @discardableResult public func adding( @ConstraintsBuilder constraints: () -> [NSLayoutConstraint] @@ -96,17 +67,11 @@ public final class Layout { // swiftlint:disable:this type_body_length adding(constraints()) } - /// Adds constraints to Layout - /// - /// - Parameter constraints: constraints to add @discardableResult public func adding(_ constraints: NSLayoutConstraint...) -> Layout { adding(constraints) } - /// Adds constraints to Layout - /// - /// - Parameter constraints: constraints to add @discardableResult public func adding(_ constraints: [NSLayoutConstraint]) -> Layout { self.constraints += constraints @@ -115,12 +80,6 @@ public final class Layout { // swiftlint:disable:this type_body_length // swiftlint:disable discouraged_optional_collection - /// Adds constraints using vertical vfl - /// - /// - Parameters: - /// - format: vertical vfl - /// - metrics: (optional) metrics for vfl - /// - options: (optional) options @discardableResult public func vertical( _ format: String, @@ -130,12 +89,6 @@ public final class Layout { // swiftlint:disable:this type_body_length vfl(axis: .vertical, format: format, metrics: metrics, options: options) } - /// Adds constraints using horizontal vfl - /// - /// - Parameters: - /// - format: horizontal vfl - /// - metrics: (optional) metrics for vfl - /// - options: (optional) options @discardableResult public func horizontal( _ format: String, @@ -169,16 +122,6 @@ public final class Layout { // swiftlint:disable:this type_body_length // swiftlint:disable function_default_parameter_at_end - /// Constrains two anchors to each other. Constrains the corresponding `targetAttribute` if `attribute` is nil - /// - /// - Parameters: - /// - view: subview to constrain - /// - attribute: (optional) attribute to constrain - /// - relation: (optional) relationship between anchors - /// - targetAttribute: attribute to constrain to - /// - targetView: subview to constrain to - /// - multiplier: (optional) multiplier - /// - constant: (optional) constant @discardableResult public func constrain( _ view: UIView, @@ -197,16 +140,6 @@ public final class Layout { // swiftlint:disable:this type_body_length constant: constant)) } - /// Constrains two anchors to each other - /// - /// - Note: - /// Equation: view1.attribute = multiplier × view2.attribute + constant - /// - Parameters: - /// - anchor: anchor to constrain - /// - relation: (optional) relationship between anchors - /// - targetAnchor: anchor to constrain to - /// - constant: (optional) constant - /// - priority: (optional) priority of constraint @discardableResult public func constrain( _ anchor: NSLayoutAnchor, @@ -233,15 +166,6 @@ public final class Layout { // swiftlint:disable:this type_body_length return adding(constraint.withPriority(priority)) } - /// Constrains two dimension attributes to each other - /// - /// - Parameters: - /// - anchor: anchor to constrain - /// - relation: (optional) relationship between dimensions - /// - targetAnchor: anchor to constrain to - /// - multiplier: (optional) multiplier - /// - constant: (optional) constant - /// - priority: (optional) priority of constraint @discardableResult public func constrain( _ anchor: NSLayoutDimension, @@ -273,13 +197,6 @@ public final class Layout { // swiftlint:disable:this type_body_length return adding(constraint.withPriority(priority)) } - /// Constrains the width or height of a subview to a constant - /// - /// - Parameters: - /// - anchor: dimension to constrain - /// - relation: relationship to `constant` - /// - constant: size of dimension - /// - priority: (optional) priority of constraint @discardableResult public func constrain( _ anchor: NSLayoutDimension, @@ -301,12 +218,6 @@ public final class Layout { // swiftlint:disable:this type_body_length return adding(constraint.withPriority(priority)) } - /// Constrains the edges of a subview to another - /// - /// - Parameters: - /// - view1: subview to constrain - /// - view2: subview to constrain - /// - insets: (optional) insets of `view1` @discardableResult public func constrain( _ view1: UIView, @@ -320,12 +231,6 @@ public final class Layout { // swiftlint:disable:this type_body_length .constrain(view1.bottom, to: view2.bottom, constant: -insets.bottom) } - /// Constrains the edges of a subview to another - /// - /// - Parameters: - /// - view1: subview to constrain - /// - view2: subview to constrain - /// - insets: (optional) insets of `view1` @discardableResult public func constrain( _ view1: UIView, @@ -339,12 +244,6 @@ public final class Layout { // swiftlint:disable:this type_body_length .constrain(view1.bottom, to: view2.bottom, constant: -insets.bottom) } - /// Constrains the edges of a subview to another - /// - /// - Parameters: - /// - view1: subview to constrain - /// - view2: subview to constrain - /// - inset: inset of `view1` @discardableResult public func constrain( _ view1: UIView, @@ -356,11 +255,6 @@ public final class Layout { // swiftlint:disable:this type_body_length insets: UIEdgeInsets(top: inset, left: inset, bottom: inset, right: inset)) } - /// Constrains the corresponding `attribute` of the `views` to each other - /// - /// - Parameters: - /// - attribute: attribute to constrain - /// - views: subviews to constrain @discardableResult public func equal( _ attribute: NSLayoutConstraint.Attribute, @@ -369,9 +263,6 @@ public final class Layout { // swiftlint:disable:this type_body_length equal([attribute], views) } - /// Constrains the width and height of the `views` to each other - /// - /// - Parameter views: subviews to constrain @discardableResult public func equalSize( _ views: [UIView] @@ -379,11 +270,6 @@ public final class Layout { // swiftlint:disable:this type_body_length equal([.height, .width], views) } - /// Constrains the corresponding `attributes` of the `views` to each other - /// - /// - Parameters: - /// - attributes: attributes to constrain - /// - views: subviews to constrain @discardableResult public func equal( _ attributes: [NSLayoutConstraint.Attribute], @@ -398,16 +284,6 @@ public final class Layout { // swiftlint:disable:this type_body_length return self } - /// Constrains each view's trailing/right to the leading/left of the following view. - /// - /// - Note: - /// - the default `direction` is .leadingToTrailing - /// - Parameters: - /// - views: subviews to constrain - /// - spacing: (optional) spacing between `views` - /// - direction: (optional) determines if the views change direction with respect to the language - /// - priority: (optional) priority of the constraint, defaults to .required - /// - alignment: Y﹘Axis attributes to align @discardableResult public func horizontal( _ views: [UIView], @@ -443,12 +319,6 @@ public final class Layout { // swiftlint:disable:this type_body_length return self } - /// Constrains each view's bottom to the top of the following view - /// - /// - Parameters: - /// - views: subviews to constrain - /// - spacing: spacing between views - /// - alignment: X﹘Axis attributes to align @discardableResult public func vertical( _ views: [UIView], @@ -476,46 +346,6 @@ public final class Layout { // swiftlint:disable:this type_body_length // swiftlint:enable function_default_parameter_at_end - /// Horizontally centers the view between two anchors. - /// - /// - Parameters: - /// - view - /// - between: the leading most attribute (1) - /// - and: the trailing most attribute (2) - /// - Example: - /// ``` - /// view.layout( - /// label.to(.centerY), - /// siblingView.square(50).center() - /// ) - /// .center(label, between: siblingView.trailing, and: view.safeAreaLayoutGuide.trailing) - /// .activate() - /// - /// +-----------------------------------------+ - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | +------+ | - /// | | | | - /// | | (1) label (2) - /// | | | | - /// | +------+ | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// +-----------------------------------------+ - /// ``` @discardableResult public func center( _ view: UIView, @@ -534,46 +364,6 @@ public final class Layout { // swiftlint:disable:this type_body_length ]) } - /// Vertically centers the view between two anchors. - /// - /// - Parameters: - /// - view - /// - between: the top most attribute (1) - /// - and: the bottom most attribute (2) - /// - Example: - /// ``` - /// view.layout( - /// label.to(.centerX), - /// siblingView.square(50).center() - /// ) - /// .center(label, between: view.safeAreaLayoutGuide.top, and: siblingView.top) - /// .activate() - /// - /// +------------------(1)--------------------+ - /// | | - /// | | - /// | | - /// | | - /// | label | - /// | | - /// | | - /// | | - /// | | - /// | +-(2)--+ | - /// | | | | - /// | | | | - /// | | | | - /// | +------+ | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// | | - /// +-----------------------------------------+ - /// ``` @discardableResult public func center( _ view: UIView, @@ -592,15 +382,6 @@ public final class Layout { // swiftlint:disable:this type_body_length ]) } - /// Adds LayoutItems - /// - /// - Note: - /// Constraints attached to the LayoutItem will be to the Layout's view - /// ```` - /// let item = view1.pin() - /// mainView.layout().addItems(item) - /// ```` - /// - Parameter items: LayoutItems to add @discardableResult public func addItems( _ items: LayoutItem... @@ -608,15 +389,6 @@ public final class Layout { // swiftlint:disable:this type_body_length addItems(items) } - /// Adds LayoutItems - /// - /// - Note: - /// Constraints attached to the LayoutItem will be to the Layout's view - /// ```` - /// let items = [view1.pin(), view2.pad()] - /// mainView.layout().addItems(items) - /// ```` - /// - Parameter items: LayoutItems to add @discardableResult public func addItems( _ items: [LayoutItem] @@ -635,30 +407,24 @@ public final class Layout { // swiftlint:disable:this type_body_length return self } - /// Assigns a `priority` to _ALL_ the constraints attached to the instance - /// - /// - Parameter priority: priority for constraints @discardableResult public func withPriority(_ priority: UILayoutPriority) -> Layout { constraints.prioritize(priority) return self } - /// Activates all constraints of instance @discardableResult public func activate() -> Layout { constraints.activate() return self } - /// Deactivates all constraints of instance @discardableResult public func deactivate() -> Layout { constraints.deactivate() return self } - /// Updates all constraints attached to the Layout's view public func update() { view?.setNeedsUpdateConstraints() view?.updateConstraintsIfNeeded() diff --git a/Sources/Layout/LayoutItem.swift b/Sources/Layout/LayoutItem.swift index b9f95079..04b63333 100644 --- a/Sources/Layout/LayoutItem.swift +++ b/Sources/Layout/LayoutItem.swift @@ -13,22 +13,12 @@ import UIKit public typealias SuperviewConstraints = (LayoutItem) -> [NSLayoutConstraint] -/// Items to be used with the `Layout` API -/// -/// - Note: -/// Constraints from LayoutItem methods cannot be activated until the LayoutItem is attached to a `.layout()` call -/// ```` -/// let item = view1.pin() -/// mainView.layout(item).activate() -/// ```` @preconcurrency @MainActor public protocol LayoutItem: AnyObject, LayoutBoundary, LayoutCenter, LayoutSize, LayoutBaseline { - /// View of the LayoutItem var layoutItemView: UIView { get } - /// Constraints to the superview var superviewConstraints: SuperviewConstraints { get } } @@ -57,9 +47,6 @@ extension LayoutItem { return superview.safeAreaLayoutGuide } - /// Adds an identifier - /// - /// - Parameter identifier: identifier public func id(_ identifier: String) -> Self { self.identifier = identifier return self @@ -73,12 +60,6 @@ extension LayoutItem { } } - /// Constrains the width and height - /// - /// - Parameters: - /// - width: width constraint - /// - height: height constraint - /// - priority: (optional) priority of constraint public func size( width: CGFloat, height: CGFloat, @@ -90,11 +71,6 @@ extension LayoutItem { } } - /// Constrains the size - /// - /// - Parameters: - /// - size: size constraint - /// - priority: (optional) priority of constraint public func size( _ size: CGSize, priority: UILayoutPriority = .required @@ -104,12 +80,6 @@ extension LayoutItem { // swiftlint:disable function_default_parameter_at_end - /// Constrains the width - /// - /// - Parameters: - /// - relation: (optional, default `.equal`) relationship (=, ≤, ≥) - /// - width: width constraint - /// - priority: (optional) priority of constraint public func size( is relation: NSLayoutConstraint.Relation = .equal, width: CGFloat, @@ -120,12 +90,6 @@ extension LayoutItem { } } - /// Constrains the height - /// - /// - Parameters: - /// - relation: (optional, default `.equal`) relationship (=, ≤, ≥) - /// - height: height constraint - /// - priority: (optional) priority of constraint public func size( is relation: NSLayoutConstraint.Relation = .equal, height: CGFloat, @@ -138,16 +102,10 @@ extension LayoutItem { // swiftlint:enable function_default_parameter_at_end - /// Constrains the width to the height public func square() -> LayoutItem { aspectRatio(1) } - /// Constrains the width and height to the same value - /// - /// - Parameters: - /// - length: width and height constraint - /// - priority: (optional) priority of constraint public func square( _ length: CGFloat, priority: UILayoutPriority = .required @@ -158,11 +116,6 @@ extension LayoutItem { } } - /// Constrains the width to the height by a `ratio` - /// - /// - Parameters: - /// - ratio: ratio constraint, width:height - /// - priority: (optional) priority of constraint public func aspectRatio( _ ratio: CGFloat, priority: UILayoutPriority = .required @@ -174,11 +127,6 @@ extension LayoutItem { } } - /// Centers the view in the superview with an `offset` - /// - /// - Parameters: - /// - offset: (optional) offset from superview - /// - priority: (optional) priority of constraint public func center( offset: UIOffset = .zero, priority: UILayoutPriority = .required @@ -188,12 +136,6 @@ extension LayoutItem { } } - /// Centers the view on `axis` of the superview with an `offset` - /// - /// - Parameters: - /// - axis: axis to center view on - /// - offset: (optional) offset from superview - /// - priority: (optional) priority of constraint public func center( _ axis: NSLayoutConstraint.Axis, offset: CGFloat = 0, @@ -203,33 +145,6 @@ extension LayoutItem { to(axis.attribute, multiplier: multiplier, constant: offset, priority: priority) } - /// Vertically centers the view between two anchors. - /// - /// - Parameters: - /// - between: the top layout anchor (1) - /// - and: the bottom layout anchor (2) - /// - Example: - /// ``` - /// view.layout( - /// label - /// .to(.centerX) - /// .center(between: view.safeAreaLayoutGuide.top, and: siblingView.top), - /// siblingView.center() - /// ).activate() - /// - /// +---------(1)---------+ - /// | | - /// | label | - /// | | - /// | +--(2)--+ | - /// | | | | - /// | | | | - /// | | | | - /// | +-------+ | - /// | | - /// | | - /// +---------------------+ - /// ``` public func center( between top: NSLayoutYAxisAnchor, and bottom: NSLayoutYAxisAnchor @@ -248,32 +163,6 @@ extension LayoutItem { } } - /// Horizontally centers the view between two anchors. - /// - /// - Parameters: - /// - between: the leading layout anchor (1) - /// - and: the trailing layout anchor (2) - /// - Example: - /// ``` - /// view.layout( - /// label - /// .to(.centerY) - /// .center(between: siblingView.trailing, and: view.safeAreaLayoutGuide.trailing), - /// siblingView.center().square(50) - /// ).activate() - /// - /// +------------------------------+ - /// | | - /// | | - /// | +------+ | - /// | | | | - /// | | (1) label (2) - /// | | | | - /// | +------+ | - /// | | - /// | | - /// +------------------------------+ - /// ``` public func center( between leading: NSLayoutXAxisAnchor, and trailing: NSLayoutXAxisAnchor @@ -292,16 +181,6 @@ extension LayoutItem { } } - /// Constrains the `attribute` to the superview's corresponding `attribute` - /// - /// - Note: - /// Equation: view.attribute = multiplier × superview.attribute + constant - /// - Parameters: - /// - attribute: attribute to constrain - /// - relation: (optional) relationship (=, ≤, ≥) - /// - multiplier: (optional) multiplier - /// - constant: (optional) constant - /// - priority: (optional) priority of constraint public func to( _ attribute: NSLayoutConstraint.Attribute, is relation: NSLayoutConstraint.Relation = .equal, @@ -320,14 +199,6 @@ extension LayoutItem { } } - /// Constrains the `attributes` to the superview's corresponding `attributes` - /// - /// - Note: - /// Equation: view.attribute = superview.attribute + constant - /// - Parameters: - /// - attributes: attributes to constrain - /// - constant: (optional) constant - /// - priority: (optional) priority of constraint public func to( _ attributes: [NSLayoutConstraint.Attribute], constant: CGFloat = 0, @@ -343,13 +214,6 @@ extension LayoutItem { } } - /// Constrains the view's directional edges to the superview's edges with insets. - /// - /// - Parameters: - /// - insets: The directional edge insets - /// - priority: The priority of the constraints - /// - /// - Returns: The LayoutItem public func toEdges( insets: DirectionalInsets, priority: UILayoutPriority = .required @@ -363,13 +227,6 @@ extension LayoutItem { } } - /// Constrains the view's canonical edges to the superview's edges with insets. - /// - /// - Parameters: - /// - insets: The canonical edge insets - /// - priority: The priority of the constraints - /// - /// - Returns: The LayoutItem public func toEdges( insets: CanonicalInsets, priority: UILayoutPriority = .required @@ -383,14 +240,6 @@ extension LayoutItem { } } - /// Constrains the view's directional edges to the superview's edges with an inset. - /// - /// - Parameters: - /// - edges: The edges to constrain - /// - inset: The inset distance - /// - priority: The priority of the constraint(s) - /// - /// - Returns: The LayoutItem public func toEdges( _ edges: [DirectionalEdge], inset: CGFloat = 0, @@ -405,14 +254,6 @@ extension LayoutItem { } } - /// Constrains the view's canonical edges to the superview's edges with an inset. - /// - /// - Parameters: - /// - edges: The edges to constrain - /// - inset: The inset distance - /// - priority: The priority of the constraint(s) - /// - /// - Returns: The LayoutItem public func toEdges( canonical edges: [CanonicalEdge] = CanonicalEdge.allCases, inset: CGFloat = 0, @@ -427,13 +268,6 @@ extension LayoutItem { } } - /// Constrains the view's leading and trailing edges to the superview's edges with an inset. - /// - /// - Parameters: - /// - inset: The inset distance - /// - priority: The priority of the constraints - /// - /// - Returns: The LayoutItem public func toSideEdges( inset: CGFloat = 0, priority: UILayoutPriority = .required @@ -441,13 +275,6 @@ extension LayoutItem { toEdges(canonical: [.left, .right], inset: inset, priority: priority) } - /// Constrains the view's directional edges to the superview's margins with insets. - /// - /// - Parameters: - /// - insets: The directional insets - /// - priority: The priority of constraints - /// - /// - Returns: The LayoutItem public func toMargins( insets: DirectionalInsets, priority: UILayoutPriority = .required @@ -461,13 +288,6 @@ extension LayoutItem { } } - /// Constrains the view's canonical edges to the superview's margins with insets. - /// - /// - Parameters: - /// - insets: The canonical insets - /// - priority: The priority of the constraints - /// - /// - Returns: The LayoutItem public func toMargins( insets: CanonicalInsets, priority: UILayoutPriority = .required @@ -481,14 +301,6 @@ extension LayoutItem { } } - /// Constrains the view's directional edges to the superview's margins with an inset. - /// - /// - Parameters: - /// - edges: The edges to constrain - /// - inset: The inset distance - /// - priority: The priority of the constraint(s) - /// - /// - Returns: The LayoutItem public func toMargins( _ edges: [DirectionalEdge], inset: CGFloat = 0, @@ -503,14 +315,6 @@ extension LayoutItem { } } - /// Constrains the view's canonical edges to the superview's margins with an inset. - /// - /// - Parameters: - /// - edges: The edges to constrain - /// - inset: The inset distance - /// - priority: The priority of the constraint(s) - /// - /// - Returns: The LayoutItem public func toMargins( canonical edges: [CanonicalEdge] = CanonicalEdge.allCases, inset: CGFloat = 0, @@ -525,11 +329,6 @@ extension LayoutItem { } } - /// Constrains the view's side edges to the superview's margins with an inset. - /// - /// - Parameters: - /// - inset: (optional) The inset distance. - /// - priority: (optional) The priority of constraints. public func toSideMargins( inset: CGFloat = 0, priority: UILayoutPriority = .required @@ -537,15 +336,6 @@ extension LayoutItem { toMargins(canonical: [.left, .right], inset: inset, priority: priority) } - /// Constrains the `bottom` to the bottom margin with a minimum bottom inset - /// Useful for bottom-aligned elements on iPhoneX family devices that require - /// an additional bottom margin on non-iPhoneX devices. - /// - /// - Parameters: - /// - minInset: minimum bottom inset on non-iPhoneX devices. A positive - /// minInset will set your view's bottom above the superview's bottom visually. - /// A negative minInset will do the opposite. - /// - priority: (optional) priority of constraint public func toBottomMargin( minInset: CGFloat, priority: UILayoutPriority = .required @@ -567,13 +357,6 @@ extension LayoutItem { } } - /// Constrains the view's directional edges to the superview's safe area with insets. - /// - /// - Parameters: - /// - insets: The directional insets - /// - priority: The priority of the constraints - /// - /// - Returns: The LayoutItem public func toSafeArea( insets: DirectionalInsets, priority: UILayoutPriority = .required @@ -587,13 +370,6 @@ extension LayoutItem { } } - /// Constrains the view's canonical edges to the superview's safe area with insets. - /// - /// - Parameters: - /// - insets: The canonical insets - /// - priority: The priority of the constraints - /// - /// - Returns: The LayoutItem public func toSafeArea( insets: CanonicalInsets, priority: UILayoutPriority = .required @@ -607,14 +383,6 @@ extension LayoutItem { } } - /// Constrains the view's directional edges to the superview's safe area with an inset. - /// - /// - Parameters: - /// - edges: The edges to constrain - /// - inset: The inset distance - /// - priority: The priority of the constraint(s) - /// - /// - Returns: The LayoutItem public func toSafeArea( _ edges: [DirectionalEdge], inset: CGFloat = 0, @@ -629,14 +397,6 @@ extension LayoutItem { } } - /// Constrains the view's canonical edges to the superview's safe area with an inset. - /// - /// - Parameters: - /// - edges: The edges to constrain - /// - inset: The inset distance - /// - priority: The priority of the constraint(s) - /// - /// - Returns: The LayoutItem public func toSafeArea( canonical edges: [CanonicalEdge] = CanonicalEdge.allCases, inset: CGFloat = 0, diff --git a/Sources/Layout/Swift/Collection.swift b/Sources/Layout/Swift/Collection.swift index ac35825f..1575792f 100644 --- a/Sources/Layout/Swift/Collection.swift +++ b/Sources/Layout/Swift/Collection.swift @@ -9,14 +9,12 @@ extension Collection where Element == Layout { - /// Activates all constraints of each instance @preconcurrency @MainActor public func activate() { forEach { $0.activate() } } - /// Deactivates all constraints of each instance @preconcurrency @MainActor public func deactivate() { diff --git a/Sources/Layout/UIKit/UIView+Layout.swift b/Sources/Layout/UIKit/UIView+Layout.swift index f5f52972..590eac0e 100644 --- a/Sources/Layout/UIKit/UIView+Layout.swift +++ b/Sources/Layout/UIKit/UIView+Layout.swift @@ -11,31 +11,6 @@ import UIKit extension UIView { - /// Adds constraints to a view. - /// - /// - Note: - /// * Views are added to view hierarchy in reverse order. The last item in layout call will be at the front. - /// * Must call `.activate()` for constraints to become active. - /// * Activating/Deactivating an instance will only affect the constraints attached to that instance. - /// * Deactivating the instance does not remove or hide views. - /// * A view can have multiple Layout instances, useful for when a view has different states. - /// * Preferred format for adding one view with one constraint - /// ```` - /// view1.layout(view2.pin()).activate() - /// ```` - /// * Preferred format for adding multiple views or constraints - /// ```` - /// view1.layout { - /// view2 - /// .to([.leading, .top, .trailing]) - /// view3 - /// .pad() - /// .to(.bottom) - /// } - /// .vertical([view2, view3]) - /// .activate() - /// ```` - /// - Parameter metrics: (optional) metrics for VFL public func layout( metrics: [String: Any] = [:] ) -> Layout { @@ -44,33 +19,6 @@ extension UIView { // swiftlint:disable function_default_parameter_at_end - /// Adds a subview and constraints to a view. - /// - /// - Note: - /// * Views are added to view hierarchy in reverse order. The last item in layout call will be at the front. - /// * Must call `.activate()` for constraints to become active. - /// * Activating/Deactivating an instance will only affect the constraints attached to that instance. - /// * Deactivating the instance does not remove or hide views. - /// * A view can have multiple Layout instances, useful for when a view has different states. - /// * Preferred format for adding one view with one constraint - /// ```` - /// view1.layout(view2.pin()).activate() - /// ```` - /// * Preferred format for adding multiple views or constraints - /// ```` - /// view1.layout { - /// view2 - /// .to([.leading, .top, .trailing]) - /// view3 - /// .pad() - /// .to(.bottom) - /// } - /// .vertical([view2, view3]) - /// .activate() - /// ```` - /// - Parameters: - /// - metrics: (optional) metrics for VFL - /// - item: item to be included in Layout public func layout( metrics: [String: Any] = [:], _ item: LayoutItem @@ -80,33 +28,6 @@ extension UIView { // swiftlint:enable function_default_parameter_at_end - /// Adds subviews and constraints to a view. - /// - /// - Note: - /// * Views are added to view hierarchy in reverse order. The last item in layout call will be at the front. - /// * Must call `.activate()` for constraints to become active. - /// * Activating/Deactivating an instance will only affect the constraints attached to that instance. - /// * Deactivating the instance does not remove or hide views. - /// * A view can have multiple Layout instances, useful for when a view has different states. - /// * Preferred format for adding one view with one constraint - /// ```` - /// view1.layout(view2.pin()).activate() - /// ```` - /// * Preferred format for adding multiple views or constraints - /// ```` - /// view1.layout { - /// view2 - /// .to([.leading, .top, .trailing]) - /// view3 - /// .pad() - /// .to(.bottom) - /// } - /// .vertical([view2, view3]) - /// .activate() - /// ```` - /// - Parameters: - /// - metrics: (optional) metrics for VFL - /// - items: items to be included in Layout public func layout( metrics: [String: Any] = [:], @LayoutBuilder items: () -> [LayoutItem]