Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add priority to MinimumSize and use it in ButtonStyle #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Form/ButtonStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ private extension UIButton {
}

func updateMinimumSize(_ minimumSize: MinimumSize) {
updateConstraint(for: widthAnchor, with: minimumSize.width, constraintKey: &widthConstraintKey)
updateConstraint(for: heightAnchor, with: minimumSize.height, constraintKey: &heightConstraintKey)
updateConstraint(for: widthAnchor, with: minimumSize.width, priority: minimumSize.priority, constraintKey: &widthConstraintKey)
updateConstraint(for: heightAnchor, with: minimumSize.height, priority: minimumSize.priority, constraintKey: &heightConstraintKey)
}

func updateConstraint(for anchor: NSLayoutDimension, with value: CGFloat?, constraintKey key: UnsafeRawPointer) {
func updateConstraint(for anchor: NSLayoutDimension, with value: CGFloat?, priority: UILayoutPriority, constraintKey key: UnsafeRawPointer) {
let constant = value ?? 0
let constraint = associatedValue(forKey: key, initial: anchor >= constant)
constraint.priority = .defaultHigh
constraint.priority = priority
constraint.constant = constant
constraint.isActive = (value != nil)
}
Expand Down
4 changes: 3 additions & 1 deletion Form/MinimumSize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import Foundation
public struct MinimumSize: Style {
public var width: CGFloat?
public var height: CGFloat?
public var priority: UILayoutPriority

public init(width: CGFloat? = nil, height: CGFloat? = nil) {
public init(width: CGFloat? = nil, height: CGFloat? = nil, priority: UILayoutPriority = .defaultHigh) {
self.width = width
self.height = height
self.priority = priority
}
}

Expand Down