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

SwiftUI Text Binding One-Way Only #37

Open
badepaz opened this issue Nov 21, 2024 · 0 comments
Open

SwiftUI Text Binding One-Way Only #37

badepaz opened this issue Nov 21, 2024 · 0 comments

Comments

@badepaz
Copy link

badepaz commented Nov 21, 2024

Really love this framework; great job on it! I have an app that I'm building that displays some JSON return values from API calls. It's sort of like a native iOS/macOS demo app to show off the features of a backend API service. So my need wasn't really an editor but a pretty printed JSON output view. The app is SwiftUI based, and I noticed that the binding for the text only works one way. If I change the @State string in the SwiftUI view programmatically (such as when my API call returns with the JSON data and puts it in the state property) the SourceCodeTextEditor view doesn't update.

struct AppRootView: View {
  
   @State private var editorText = ""

   var body: some View {
      VStack {
         Button("Insert JSON") { 
            editorText = "{ \"value\": \"Hello, World!\"}" 
            // Does not update the contents of the SourceCodeTextEditor
         }
      
         SourceCodeTextEditor(text: $editorText)
      }
   }

}

It would appear that there is no observer attached to the binding on the UIKit/AppKit side of the bridge to synchronize the underlying NS(UI)TextView.

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