File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
Demo Project/ResponsiveTextFieldDemo
Sources/ResponsiveTextField Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ struct ContentView: View {
6464 text: $email,
6565 firstResponderDemand: $emailResponderDemand. animation ( ) ,
6666 configuration: . email,
67- onFirstResponderStateChanged: { isFirstResponder in
67+ onFirstResponderStateChanged: . init { isFirstResponder in
6868 withAnimation {
6969 isEmailFirstResponder = isFirstResponder
7070 }
@@ -90,7 +90,7 @@ struct ContentView: View {
9090 isSecure: hidePassword,
9191 firstResponderDemand: $passwordResponderDemand. animation ( ) ,
9292 configuration: . combine( . password, . lastOfChain) ,
93- onFirstResponderStateChanged: { isFirstResponder in
93+ onFirstResponderStateChanged: . init { isFirstResponder in
9494 withAnimation {
9595 isPasswordFirstResponder = isFirstResponder
9696 }
Original file line number Diff line number Diff line change @@ -10,9 +10,6 @@ import SwiftUI
1010/// A SwiftUI wrapper around UITextField that gives precise control over the responder state.
1111///
1212public struct ResponsiveTextField {
13- /// Communicates the text field's first responder state using a boolean value (is first responder).
14- public typealias FirstResponderStateChangeHandler = ( Bool ) -> Void
15-
1613 /// The text field placeholder string
1714 let placeholder : String
1815
@@ -145,6 +142,23 @@ public struct ResponsiveTextField {
145142
146143// MARK: - Managing the first responder state
147144
145+ public struct FirstResponderStateChangeHandler {
146+ /// A closure that will be called when the first responder state changes.
147+ ///
148+ /// - Parameters:
149+ /// - Bool: A boolean indicating if the text field is now the first responder or not.
150+ ///
151+ public var handleStateChange : ( Bool ) -> Void
152+
153+ public init ( handleStateChange: @escaping ( Bool ) -> Void ) {
154+ self . handleStateChange = handleStateChange
155+ }
156+
157+ func callAsFunction( _ isFirstResponder: Bool ) {
158+ handleStateChange ( isFirstResponder)
159+ }
160+ }
161+
148162/// Represents a request to change the text field's first responder state.
149163///
150164public enum FirstResponderDemand : Equatable {
You can’t perform that action at this time.
0 commit comments