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

Set colors from RichTextContext #184

Open
alelordelo opened this issue Jul 1, 2024 · 3 comments
Open

Set colors from RichTextContext #184

alelordelo opened this issue Jul 1, 2024 · 3 comments
Labels
discussion Discussions not yet turned into an action

Comments

@alelordelo
Copy link

alelordelo commented Jul 1, 2024

I created a func to set colors from RichTextContext:

  // Method to update colors
    public func setColor(_ color: ColorRepresentable, for key: RichTextColor) {
        print("Setting color \(color) for key \(key)")
        colors[key] = color
    }
    

And then I init like this:

                RichTextEditor(text: richText, context: context, config: editorConfig) { _ in
                  context.setAttributedString(to: cell.richText)
                    context.setColor(.purple, for: .foreground)
                }

Prints:
Setting color sRGB IEC61966-2.1 colorspace 0.5 0 0.5 1 for key foreground

But it does not get applied...

Is this correct? Or is there a better way to set a color from the context ?

@alelordelo
Copy link
Author

also tried this, but didn't work...

   RichTextEditor(text: richText, context: context, config: editorConfig) { _ in
                  context.setAttributedString(to: cell.richText)
                  context.colors[.foreground] = .purple
                }

@danielsaidi
Copy link
Owner

Hi @alelordelo - the string needs to be observed in some way for the change to update the UI. You can then use the setColor function in the RichTextContext to update any color.

@danielsaidi danielsaidi added the discussion Discussions not yet turned into an action label Jul 2, 2024
@alelordelo
Copy link
Author

alelordelo commented Jul 2, 2024

Hi @alelordelo - the string needs to be observed in some way for the change to update the UI. You can then use the setColor function in the RichTextContext to update any color.

thanks @danielsaidi

But isn't that what I am doing here? Or maybe I missed something?

        RichTextEditor(text: richText, context: context, config: editorConfig) { _ in
              context.setAttributedString(to: cell.richText)
                context.setColor(.purple, for: .foreground)
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discussions not yet turned into an action
Projects
None yet
Development

No branches or pull requests

2 participants