danielsaidi / RichTextKit

RichTextKit is a Swift SDK that helps you use rich text in Swift and SwiftUI.
MIT License
949 stars 126 forks source link

Text does not show when updating state #203

Open pkasson opened 1 month ago

pkasson commented 1 month ago

When the text (@State) is updated, the component does not show it:

@State var text = NSAttributedString(string: "Type text here...")

RichTextEditor(text: $text, context: context) .focusedValue(.richTextContext, context) .focused($isFocused)

The initial text works, but when text is updated, it does not get rendered.

danielsaidi commented 1 month ago

Hi @pkasson

That's unfortunately a side-effect of striving for better performance, since the text editor would otherwise be redrawn whenever you type.

I've been thinking about adding an internal binding that always writes out to the external one, but also listen for those changes and update whenever the external one changes.

For now, you can use setter functions in the rich text context, which affect the editor.

pkasson commented 1 month ago

Thanks - that worked. I agree, there is a balancing act on updating content that has rich content and performance

pkasson commented 1 month ago

Next Q - how can I set the BG color - it appears maybe using the Theme, but I can't see how to set it to white.

danielsaidi commented 1 month ago

You can set a color with the rich text action approach.

pkasson commented 1 month ago

How do you do that ?

danielsaidi commented 1 month ago

You can trigger a RichTextAction.

The documentation is a bit fuzzy about this, but you can see some examples in the docs: https://danielsaidi.github.io/RichTextKit/documentation/richtextkit/context-article

pkasson commented 1 month ago

Yes, quite fuzzy - didn't find anything around this ... thanks for trying - will find another RTF editor.