Hey, I want to implement a rich-text-editor in com...
# compose
t
Hey, I want to implement a rich-text-editor in compose supporting text formatting options with inline images. After exploration, it seems BasicTextField does not support inline contents unlike BasicText. I have been exploring @mohamed rejeb’s compose-rich-text-editor library but it also doesn’t support the inline contents in the editor. wanted some suggestions on how to think and go about it ? 1. Should I think of customising CoreTextField internal class, wondering what all blockers I can have in that. 2. Should I not think about a compose solution at all ?
s
Hi. I had a similar issue, and I believe the best approach is to use Android’s standard EditText wrapped in an AndroidView, as long as you’re only targeting Android. Modifying the source code of core components can lead to a complicated and time-consuming process.
a
@Tanvi Goyal afaik BasicTextField supports AnnotatedString. havent done rich text editor but i would imagine that I could somehow host my own content there. is that not possible?
a
No,
AnnotatedString
itself does only support Text-rendering. But there is a Compose-library that is capable of rendering styled text, paragraphs, tables and even Images: https://github.com/jeziellago/compose-markdown
s
@Alex Styl AFAIK it still has the same state https://kotlinlang.slack.com/archives/CJLTWPH7S/p1657572646560099
👍 1
t
Thanks @Sergey Y., did you tried out the native EditText approach, would be helpful if you can point out to some resources.
@Alex Styl, yes BasicTextField supports AnnotatedString but that only renders the text inside, BTF internally has a TextDelegate that takes a placeholder attribute but I would need to do a custom implementation of CoreTextField used by BTF to access that.
today i learned 1
s
Yes I did. If all you need is a rich text editor, you can explore the many libraries already available. After over a decade of EditText’s existence, there are plenty of reliable options to choose from. If you’re looking for a custom implementation, EditText supports plenty of span classes, offering various editing capabilities. It’s incredibly flexible, allowing you to achieve whatever functionality you need. https://developer.android.com/develop/ui/views/text-and-emoji/spans
thank you color 1
✔️ 1
k
i am working on a similar thing and had to build everything from the ground up and afaik there isnt anything like that available because this has so many cases that only a purpose built library can handle it
t
are you trying it out in compose @Kashismails ?
t
@Kashismails in regards to managing the complexities of packaging UI components for reuse, can you or anyone else point me to practical examples of Compose Multiplatform artifact management (is there an equivalent to the Dotnet Class Library)? Any documentation on this, for example, if I wanted to package all of my custom UI components into a reusable library that I could Reference?
k
@Tyler Maginnis didnt exactly get your point, are you asking about creating reusable components in compose?
@Tanvi Goyal yes
thank you color 1