Skip to content

Commit

Permalink
Merge pull request #178 from willonboy/zt/dev
Browse files Browse the repository at this point in the history
Add the `SteviaLayoutConstraint` class to allow the removal of constraints added by Stevia.
  • Loading branch information
s4cha authored Jan 7, 2025
2 parents 74ea064 + 234033e commit 716212a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Sources/Stevia/Stevia+Constraints.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#if canImport(UIKit)
import UIKit

public class SteviaLayoutConstraint: NSLayoutConstraint {
public static defaultPriority:Float = UILayoutPriority.defaultHigh + 1
}


// MARK: - Shortcut

public extension UIView {
Expand Down Expand Up @@ -76,11 +81,11 @@ public extension UIView {
attribute attr2: NSLayoutConstraint.Attribute? = nil, // Not an attribute??
multiplier: Double = 1,
constant: Double = 0) -> NSLayoutConstraint {
let c = NSLayoutConstraint(item: view1, attribute: attr1,
let c = SteviaLayoutConstraint(item: view1, attribute: attr1,
relatedBy: relatedBy,
toItem: view2, attribute: ((attr2 == nil) ? attr1 : attr2! ),
multiplier: CGFloat(multiplier), constant: CGFloat(constant))
c.priority = UILayoutPriority(rawValue: UILayoutPriority.defaultHigh.rawValue + 1)
c.priority = UILayoutPriority(rawValue: SteviaLayoutConstraint.defaultPriority)
return c
}

Expand All @@ -98,8 +103,7 @@ public extension UIView {
*/
var userAddedConstraints: [NSLayoutConstraint] {
return constraints.filter { c in
guard let cId = c.identifier else { return true }
return !cId.contains("UIView-Encapsulated-Layout") && !cId.contains("Margin-guide-constraint")
c is SteviaLayoutConstraint
}
}
}
Expand Down

0 comments on commit 716212a

Please sign in to comment.