Open source

Introducing Twitter Text Editor

By
Monday, 25 January 2021

Twitter Text Editor is a standalone, flexible API that provides a full-featured rich text editor for iOS applications. We use this for Tweet composers on Twitter for iOS.

Today we’re happy to share Twitter Text Editor so iOS developers outside Twitter can add robust text editing to their applications.

Why Twitter Text Editor?

Text editing is one of those common tasks in iOS applications which looks easy but can be unexpectedly complicated. Twitter Text Editor aims to solve common text editing problems that can be hard for developers to get right, like syntax highlighting and text content filtering.

Apple provides a set of high-level and low-level APIs for text editing, but developers are often left to fill the gap. The high-level APIs don’t always offer enough power or control to create a truly great in-app experience. Meanwhile, the lower level APIs require a lot of knowledge about how text editing works in a variety of languages, including support for bidirectional scripts, alternative input methods (like those used for East Asian languages), and assistive technology like braille keyboards.

We’ve learned a lot about text editing while working to address these problems over the last few years, and we hope Twitter Text Editor helps you improve your applications’ text editing experience.

What does Twitter Text Editor offer?

Twitter Text Editor features:

  • Easy delegate-based APIs
    Twitter Text Editor’s delegate-based APIs are designed to be similar to many common UIKit APIs.
  • Robust text-attribute update logic
    Twitter Text Editor offers simple callback APIs for parsing text content and updating text attributes in the background, making it possible to implement features like syntax highlighting.
  • Additional text editing events
    Twitter Text Editor offers extra events such as Primary Language Change and Base Writing Direction Change that applications can use to update UIs.
  • Safe event handling for text input
    Twitter Text Editor offers event callbacks that are only called when it is safe for an application to filter text or update a related user interface. That’s normally hard to get right.
  • Support for recent versions of iOS
    Twitter Text Editor supports iOS 11.0 and above, so you can make your application available to practically all iOS users.

Twitter Text Editor also comes with a sample application, written in both Swift and Objective-C, that demonstrates how to implement a text editor with multiple rich editing features, including syntax highlighting.

The design

Twitter Text Editor is implemented as a Swift Package that you can easily add to your project in Xcode. It’s also possible to use via CocoaPods. It doesn’t have any dependencies beyond iOS system frameworks.

Twitter Text Editor encapsulates UITextView and provides familiar delegate-based APIs like many common UIKit APIs. It extends LayoutManager and TextStorage to provide custom text attributes, including attributes for presenting custom emoji. Twitter Text Editor has event schedulers to process events, providing consistent delegate callback order to your code.

This post is unavailable
This post is unavailable.

Who is Twitter Text Editor for?

Twitter Text Editor is useful to developers who wants to add flexible rich text editing to their iOS application without worrying about the pitfalls of Apple’s APIs. Its delegate methods allow you to focus on what your application provides to your users.

Where can I find Twitter Text Editor?

Twitter Text Editor project can be found on Twitter’s GitHub page.

Check out our other iOS open source projects, including Twitter Image Pipeline, Twitter Network Layer, and Twitter Logging Service.

Contribution?

We would love to get contributions from you! Please refer CONTRIBUTING.md for the details.

Editor's Note: This article has been modified to remove a reference to Fleets. We said goodbye to Fleets on August 3, 2021. We are grateful to you for being part of this community. Keep the conversation going on Twitter. Go to Twitter.

This post is unavailable
This post is unavailable.