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

Need help with swiftUI #358

Open
DuoTunlH opened this issue Jan 14, 2025 · 0 comments
Open

Need help with swiftUI #358

DuoTunlH opened this issue Jan 14, 2025 · 0 comments

Comments

@DuoTunlH
Copy link

DuoTunlH commented Jan 14, 2025

I am trying to use the library in SwiftUI and followed the example exactly. However, I am facing an issue where, when I update the attributedText from a button action like this:

ProtonView(attributedText: $att, selectedRange: $selectedRange)
Button("Button") {
    att = att.addingAttributes([.foregroundColor: UIColor.red], to: selectedRange)
}

The attributedText in the EditorView doesn't update as expected. The changes made to the att (such as adding attributes to the text) don't reflect in the EditorView.

In ProtonWrapperView, if I use the following code to update the EditorView:

    func updateUIView(_ view: EditorView, context: Context) {
        view.attributedText = attributedText
    }

The attributedText updates as expected, but I receive the warning:
Modifying state during view update, this will cause undefined behavior.

Can anyone help me figure out how to correctly update attributedText in the EditorView so that changes are reflected?

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