Skip to content

Commit

Permalink
Extracted finding constraints from nsview
Browse files Browse the repository at this point in the history
  • Loading branch information
charliescheer committed Jul 22, 2024
1 parent 80335d1 commit 77ea56a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Simplenote/NSView+Simplenote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ extension NSView {
let effectiveResponder = fieldEditor?.delegate as? NSControl
return effectiveResponder == self
}

/// Returns first layout constraint found for attribute type
///
func firstContraint(firstView: NSView, firstAttribute: NSLayoutConstraint.Attribute) -> NSLayoutConstraint? {
constraints.first(where: { $0.firstItem as? NSView == firstView && $0.firstAttribute == firstAttribute })
}
}
4 changes: 2 additions & 2 deletions Simplenote/SPNavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class SPNavigationController: NSViewController {
}

private func animateTransition(slidingView: NSView, fadingView: NSView?, direction: AnimationDirection, onCompletion: @escaping () -> Void) {
guard let leadingConstraint = view.constraints.first(where: { $0.firstItem as? NSView == slidingView && $0.firstAttribute == .leading }),
let trailingConstraint = view.constraints.first(where: { $0.firstItem as? NSView == slidingView && $0.firstAttribute == .trailing }) else {
guard let leadingConstraint = view.firstContraint(firstView: slidingView, firstAttribute: .leading),
let trailingConstraint = view.firstContraint(firstView: slidingView, firstAttribute: .trailing) else {
return
}

Expand Down

0 comments on commit 77ea56a

Please sign in to comment.