iTranslated by AI
Essential Libraries for Building Social Media Apps
This is an article for Day 14 of the iOS Advent Calendar 2023.
Hello, I'm noppe.
I'm developing an iOS Mastodon client called Nightfox DAWN for mastodon.
Actually, in DAWN, I provide common processes used in Mastodon apps as open-source.
Today, I'll introduce the open-source libraries born from DAWN. All of them are MIT-licensed, so you can use them freely whether it's for a Mastodon app or not.
I've included a section in the READMEs to showcase apps using them, so please let me know if you use them in your app!
DAWNText
DAWNText is a library for using TextKit2 on SwiftUI.
I developed it because SwiftUI's Text doesn't support text selection or embedding emojis with NSTextAttachment.
It also supports self-resizing and can be used with a feel similar to SwiftUI's Text.

The image above is made with SwiftUI using UIHostingConfiguration. Even with SwiftUI, it can render emojis with high performance.
RefreshControl

A high-performance subclass of UIRefreshControl.
While having a modern design, being a subclass means it can be handled the same way as UIRefreshControl.
Since Mastodon responses can sometimes be slow, it also includes a timeover/timeout feature that displays a message after a certain amount of time has passed.
ContinueControl

A control that triggers when you scroll to the bottom.
It also implements haptic feedback, providing an experience close to native components.
It includes a safety mechanism that prevents re-triggering until it has gone off-screen once.
MediaViewer

A preview viewer that can display both videos and images. While many similar libraries only support images, this one also supports video and includes standard implementations for features like seek bars.
AnimatedImage

A library for high-performance rendering of animated images such as GIF, APNG, and WebP.
I'd like to introduce the mechanics behind this in another article in the future.
Swinub
An API library for interacting with the Mastodon API.
It includes API definitions conforming to the Request protocol.
You can make async/await requests with a feel similar to URLSession.
It also includes an implementation of ASAuthorizationSession for authentication.
let authorization = ...
let request = GetV1TimelinesHome(authorization: authorization)
let (statuses, httpResponse) = try await URLSession.shared.response(request)
TabBar
A subclass of UITabBar that allows you to create things like icon-only tab bars.
It's built somewhat roughly. If you find any issues while using it, please send a PR.

SemanticVersioning
A semantic versioning library for parsing things like Mastodon server versions. It is built using Swift's Regex internally.
BuildAtPlugin
A plugin for retrieving the application's build time. Since Xcode occasionally runs old builds, I use this to notice it early.
VideoEditor
A customizable clone of UIVideoEditorController. You can pass the selected range when displaying it.
DrawerPresentation

A drawer menu that can be swiped from the left.
It is implemented as a custom modal animation, so it doesn't pollute the ViewController.
Pager

A UICollectionView-based page controller.
It is easier to customize compared to UIPageViewController.
RelativeDateFormat
Converts relative time into short formats like "1s" or "1m" used in SNS timelines.
SwipePopInteraction
Enables returning to the previous screen using a full-screen swipe.
ConsoleKit
A tool to view OSLogs within the app.
MediaOptimizer
A tool to fit images and videos into optimal sizes and capacities.
EventNotification
A type-safe NotificationCenter.
Conclusion
How was it? In DAWN, we have implemented many improvements to make Mastodon feel more natural to use.

I hope to contribute to the prosperity of Mastodon by exciting not only users but also developers who are building similar Mastodon apps.
Please try building your apps using the libraries introduced here! I'm also looking forward to your GitHub stars!
Discussion