diff --git a/SessionUIKit/Components/SessionTextField.swift b/SessionUIKit/Components/SessionTextField.swift index d53d7be84..a688ec9bb 100644 --- a/SessionUIKit/Components/SessionTextField.swift +++ b/SessionUIKit/Components/SessionTextField.swift @@ -1,6 +1,7 @@ // Copyright © 2023 Rangeproof Pty Ltd. All rights reserved. import SwiftUI +import Combine public struct SessionTextField: View { @Binding var text: String @@ -31,14 +32,14 @@ public struct SessionTextField: View { SwiftUI.TextField( "", - text: $text + text: $text.onChange{ value in + if error?.isEmpty == false && text != value { + error = nil + } + } ) .font(.system(size: Values.mediumFontSize)) .foregroundColor(themeColor: (error?.isEmpty == false) ? .danger : .textPrimary) - .onReceive(text.publisher, perform: { _ in - error = nil - }) - } .padding(.horizontal, Values.largeSpacing) .frame( diff --git a/SessionUIKit/Utilities/SwiftUI+Utilities.swift b/SessionUIKit/Utilities/SwiftUI+Utilities.swift index 1c6b7c3a3..0e81f3807 100644 --- a/SessionUIKit/Utilities/SwiftUI+Utilities.swift +++ b/SessionUIKit/Utilities/SwiftUI+Utilities.swift @@ -85,3 +85,15 @@ extension View { ) } } + +extension Binding { + public func onChange(_ handler: @escaping (Value) -> Void) -> Binding<Value> { + Binding( + get: { self.wrappedValue }, + set: { newValue in + handler(newValue) + self.wrappedValue = newValue + } + ) + } +}