Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB16555225: SwiftUI TextField optional Binding crash #612

Open
malhal opened this issue Feb 22, 2025 · 0 comments
Open

FB16555225: SwiftUI TextField optional Binding crash #612

malhal opened this issue Feb 22, 2025 · 0 comments

Comments

@malhal
Copy link

malhal commented Feb 22, 2025

This code with optional Binding and TextField crashes:

struct ContentView: View {
    @State var optionalText: String?
    
    var body: some View {
        
        Button(optionalText == nil ? "Show" : "Hide") {
            optionalText = optionalText == nil ? "Text" : nil
        }
        if let $text = Binding($optionalText) {
            TextField("", text: $text)
        }
    }
}

This workaround thanks to @iampatbrown prevents the crash:

TextField("", text: $text)
    .transition(.identity) // workaround thanks to @iampatbrown

So it seems the crash is related to animation. It seems FB8367784 - a crash with optional Binding and Toggle was reported before and fixed. Hopefully it can be fixed for TextField too, and all the other controls that take bindings.

Xcode Version 16.2 (16C5032a)
iOS simulator 18.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant