From d9e984dcf627fe411dda9491a2f53e1a07ace981 Mon Sep 17 00:00:00 2001 From: Luke Redpath Date: Tue, 16 Mar 2021 16:46:05 +0000 Subject: [PATCH] Make sure text field updates when text changes externally. --- Demo Project/ResponsiveTextFieldDemo/ContentView.swift | 4 ++++ Sources/ResponsiveTextField/ResponsiveTextField.swift | 1 + 2 files changed, 5 insertions(+) diff --git a/Demo Project/ResponsiveTextFieldDemo/ContentView.swift b/Demo Project/ResponsiveTextFieldDemo/ContentView.swift index 80c356c..da48b4c 100644 --- a/Demo Project/ResponsiveTextFieldDemo/ContentView.swift +++ b/Demo Project/ResponsiveTextFieldDemo/ContentView.swift @@ -124,6 +124,10 @@ struct ContentView: View { Toggle("Enabled?", isOn: $isEnabled) .padding(.bottom) + Button("Random password") { + password = UUID().uuidString + } + Text("You typed the following email:") .padding(.bottom) diff --git a/Sources/ResponsiveTextField/ResponsiveTextField.swift b/Sources/ResponsiveTextField/ResponsiveTextField.swift index 0e5b673..3b0e183 100644 --- a/Sources/ResponsiveTextField/ResponsiveTextField.swift +++ b/Sources/ResponsiveTextField/ResponsiveTextField.swift @@ -271,6 +271,7 @@ extension ResponsiveTextField: UIViewRepresentable { uiView.isSecureTextEntry = isSecure uiView.returnKeyType = returnKeyType uiView.font = font + uiView.text = text.wrappedValue switch (uiView.isFirstResponder, firstResponderDemand?.wrappedValue) { case (true, .shouldResignFirstResponder):