From 61dc7bc3f84dc0457d544b194d1145d947c8b56d Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Thu, 12 Feb 2026 00:01:11 +0100 Subject: [PATCH] Implemented the ResignFocusModifier view modifier in the app target. --- .../View Modifiers/ResignFocusModifier.swift | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 App/Sources/View Modifiers/ResignFocusModifier.swift diff --git a/App/Sources/View Modifiers/ResignFocusModifier.swift b/App/Sources/View Modifiers/ResignFocusModifier.swift new file mode 100644 index 0000000..e6ae001 --- /dev/null +++ b/App/Sources/View Modifiers/ResignFocusModifier.swift @@ -0,0 +1,43 @@ +import SwiftUI + +/// A view modifier that resigns the first responder status when the view is tapped. +/// +/// This modifier is useful for dismissing the keyboard or other input controls +/// when the user taps on an area of the view that doesn't have interactive content. +struct ResignFocusModifier: ViewModifier { + + // MARK: Body + + /// The content and behavior of the view modifier. + /// + /// Adds a tap gesture that sends the `resignFirstResponder` action + /// to dismiss any active first responder (such as a text field). + func body(content: Content) -> some View { + content + .onTapGesture { + UIApplication.shared.sendAction( + #selector(UIResponder.resignFirstResponder), + to: nil, + from: nil, + for: nil + ) + } + } + +} + +// MARK: - View Extension + +extension View { + + /// Adds a tap gesture that resigns the first responder when the view is tapped. + /// + /// This is useful for dismissing the keyboard or other input controls + /// when the user taps outside of an interactive element. + /// + /// - Returns: A view that resigns first responder status on tap. + func onResignFocus() -> some View { + modifier(ResignFocusModifier()) + } + +}