@@ -108,22 +108,6 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
108108 self . downstream. transform ( environment. diffableTextField_onUpdate)
109109 }
110110
111- //=--------------------------------------------------------------------=
112- // MARK: Events
113- //=--------------------------------------------------------------------=
114-
115- @inlinable public func textFieldDidBeginEditing( _ textField: UITextField ) {
116- synchronize ( )
117- }
118-
119- @inlinable public func textFieldDidEndEditing( _ textField: UITextField ) {
120- synchronize ( )
121- }
122-
123- @inlinable public func textFieldShouldReturn( _ textField: UITextField ) -> Bool {
124- downstream. transform ( environment. diffableTextField_onSubmit) ; return true
125- }
126-
127111 //=--------------------------------------------------------------------=
128112 // MARK: Events
129113 //=--------------------------------------------------------------------=
@@ -178,6 +162,24 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
178162 }
179163 }
180164
165+ //=--------------------------------------------------------------------=
166+ // MARK: Events
167+ //=--------------------------------------------------------------------=
168+
169+ @inlinable public func textFieldShouldReturn( _ textField: UITextField ) -> Bool {
170+ downstream. transform ( environment. diffableTextField_onSubmit)
171+ downstream. wrapped. resignFirstResponder ( )
172+ return true
173+ }
174+
175+ @inlinable public func textFieldDidBeginEditing( _ textField: UITextField ) {
176+ synchronize ( )
177+ }
178+
179+ @inlinable public func textFieldDidEndEditing( _ textField: UITextField ) {
180+ synchronize ( )
181+ }
182+
181183 //=--------------------------------------------------------------------=
182184 // MARK: Synchronization
183185 //=--------------------------------------------------------------------=
@@ -232,22 +234,24 @@ public struct DiffableTextField<Style: DiffableTextStyle>: UIViewRepresentable {
232234// MARK: * DiffableTextField x ID
233235//*============================================================================*
234236
235- public struct DiffableTextFieldID { public static let diffableTextField = Self ( ) }
237+ public struct DiffableTextFieldID {
238+ public static let diffableTextField = Self ( )
239+ }
236240
237241//*============================================================================*
238242// MARK: * DiffableTextField x Environment
239243//*============================================================================*
240244
241- @usableFromInline enum DiffableTextField_OnSetup : EnvironmentKey {
242- @usableFromInline static let defaultValue : ( ProxyTextField ) -> Void = { _ in }
245+ @usableFromInline enum DiffableTextField_OnSetup : EnvironmentKey {
246+ @usableFromInline static let defaultValue = Trigger < ProxyTextField > ( )
243247}
244248
245249@usableFromInline enum DiffableTextField_OnUpdate : EnvironmentKey {
246- @usableFromInline static let defaultValue : ( ProxyTextField ) -> Void = { _ in }
250+ @usableFromInline static let defaultValue = Trigger < ProxyTextField > ( )
247251}
248252
249253@usableFromInline enum DiffableTextField_OnSubmit : EnvironmentKey {
250- @usableFromInline static let defaultValue : ( ProxyTextField ) -> Void = { _ in }
254+ @usableFromInline static let defaultValue = Trigger < ProxyTextField > ( )
251255}
252256
253257//*============================================================================*
@@ -260,19 +264,19 @@ extension EnvironmentValues {
260264 // MARK: Accessors
261265 //=------------------------------------------------------------------------=
262266
263- @inlinable var diffableTextField_onSetup : ( ProxyTextField ) -> Void {
264- get { self [ DiffableTextField_OnSetup . self] }
265- set { self [ DiffableTextField_OnSetup . self] = newValue }
267+ @inlinable var diffableTextField_onSetup : Trigger < ProxyTextField > {
268+ get { self [ DiffableTextField_OnSetup . self] }
269+ set { self [ DiffableTextField_OnSetup . self] + = newValue }
266270 }
267271
268- @inlinable var diffableTextField_onUpdate : ( ProxyTextField ) -> Void {
272+ @inlinable var diffableTextField_onUpdate : Trigger < ProxyTextField > {
269273 get { self [ DiffableTextField_OnUpdate . self] }
270- set { self [ DiffableTextField_OnUpdate . self] = newValue }
274+ set { self [ DiffableTextField_OnUpdate . self] + = newValue }
271275 }
272276
273- @inlinable var diffableTextField_onSubmit : ( ProxyTextField ) -> Void {
277+ @inlinable var diffableTextField_onSubmit : Trigger < ProxyTextField > {
274278 get { self [ DiffableTextField_OnSubmit . self] }
275- set { self [ DiffableTextField_OnSubmit . self] = newValue }
279+ set { self [ DiffableTextField_OnSubmit . self] + = newValue }
276280 }
277281}
278282
@@ -286,19 +290,19 @@ public extension View {
286290 // MARK: Transformations
287291 //=------------------------------------------------------------------------=
288292
289- @inlinable func onSetup( of view: DiffableTextFieldID ,
293+ @inlinable func onSetup( of view: DiffableTextFieldID ,
290294 _ action: @escaping ( ProxyTextField ) -> Void ) -> some View {
291- environment ( \. diffableTextField_onSetup, action)
295+ environment ( \. diffableTextField_onSetup, Trigger ( action) )
292296 }
293297
294298 @inlinable func onUpdate( of view: DiffableTextFieldID ,
295299 _ action: @escaping ( ProxyTextField ) -> Void ) -> some View {
296- environment ( \. diffableTextField_onUpdate, action)
300+ environment ( \. diffableTextField_onUpdate, Trigger ( action) )
297301 }
298302
299303 @inlinable func onSubmit( of view: DiffableTextFieldID ,
300304 _ action: @escaping ( ProxyTextField ) -> Void ) -> some View {
301- environment ( \. diffableTextField_onSubmit, action)
305+ environment ( \. diffableTextField_onSubmit, Trigger ( action) )
302306 }
303307}
304308
0 commit comments