From 77ea56a4595eb39c4e74da0693573a130652284d Mon Sep 17 00:00:00 2001 From: Charlie Scheer Date: Mon, 22 Jul 2024 13:56:44 -0600 Subject: [PATCH] Extracted finding constraints from nsview --- Simplenote/NSView+Simplenote.swift | 6 ++++++ Simplenote/SPNavigationController.swift | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Simplenote/NSView+Simplenote.swift b/Simplenote/NSView+Simplenote.swift index b7cebdcb6..7d27fe74c 100644 --- a/Simplenote/NSView+Simplenote.swift +++ b/Simplenote/NSView+Simplenote.swift @@ -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 }) + } } diff --git a/Simplenote/SPNavigationController.swift b/Simplenote/SPNavigationController.swift index fdb8667bc..221ee3001 100644 --- a/Simplenote/SPNavigationController.swift +++ b/Simplenote/SPNavigationController.swift @@ -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 }