TacitusMail
All posts
iOS

Rich text composer on iOS with HTML round-tripping

Reply bodies on iOS no longer render as <br>/<div> raw tags. A UITextView wrapper parses the server's HTML, keeps formatting on edit, and serialises back to HTML on send.

Replying to an HTML email on iOS used to dump raw <br> and <div style='...'> tags into a plain TextField. Not great.

The new RichTextEditor is a UIViewRepresentable wrapping UITextView with two-way HTML round-tripping:

  • On first layout it parses the server HTML via NSAttributedString(data:options:) with DocumentType.html, then normalises the typography to the system body font + UIColor.label so the quoted block doesn't render as Times New Roman 12pt on dark mode.
  • allowsEditingTextAttributes = true surfaces the iOS selection menu with Bold / Italic / Underline for free — no custom toolbar needed for MVP.
  • On change, textViewDidChange serialises back to HTML via attributedText.data(from:documentAttributes:) and writes to the SwiftUI binding on the next runloop tick (avoids feedback loops with updateUIView).

The backend /mail/send endpoint already treats the body as HTML, so outgoing mail looks the same whether you composed it on the web or on iPhone.

T
The Tacitus Mail team
Engineering posts and release notes from the people who write the code.

More from the blog