From c342deb94e7b01b8a0840e76fddc31d343a42fe2 Mon Sep 17 00:00:00 2001 From: Ryan ZHAO <> Date: Thu, 16 May 2024 16:18:17 +1000 Subject: [PATCH] fix input colour after error occured --- SessionUIKit/Components/SwiftUI/SessionTextField.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/SessionUIKit/Components/SwiftUI/SessionTextField.swift b/SessionUIKit/Components/SwiftUI/SessionTextField.swift index 31ffff55e..0a9356086 100644 --- a/SessionUIKit/Components/SwiftUI/SessionTextField.swift +++ b/SessionUIKit/Components/SwiftUI/SessionTextField.swift @@ -8,13 +8,11 @@ public struct SessionTextField: View where ExplanationView: Vie @Binding var text: String @Binding var error: String? @State var previousError: String = "" + @State var textThemeColor: ThemeValue = .textPrimary let explanationView: () -> ExplanationView let placeholder: String let accessibility: Accessibility - var textThemeColor: ThemeValue { - (error?.isEmpty == false) ? .danger : .textPrimary - } var isErrorMode: Bool { guard previousError.isEmpty else { return true } if error?.isEmpty == false { return true } @@ -46,6 +44,7 @@ public struct SessionTextField: View where ExplanationView: Vie alignment: .center, spacing: Values.smallSpacing ) { + // Text input ZStack(alignment: .leading) { if text.isEmpty { Text(placeholder) @@ -122,6 +121,11 @@ public struct SessionTextField: View where ExplanationView: Vie ) .stroke(themeColor: isErrorMode ? .danger : .borderSeparator) ) + .onReceive(Just(error)) { newValue in + textThemeColor = (newValue?.isEmpty == false) ? .danger : .textPrimary + } + + // Error message ZStack { if isErrorMode { Text(error ?? previousError)