iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🦣

Essential Libraries for Building Social Media Apps

に公開

This is an article for Day 14 of the iOS Advent Calendar 2023.
https://qiita.com/advent-calendar/2023/ios


Hello, I'm noppe.
I'm developing an iOS Mastodon client called Nightfox DAWN for mastodon.
https://apps.apple.com/jp/app/nightfox-dawn-for-mastodon/id1668645019

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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/SemanticVersioning

A semantic versioning library for parsing things like Mastodon server versions. It is built using Swift's Regex internally.

BuildAtPlugin

https://github.com/noppefoxwolf/BuildAtPlugin

A plugin for retrieving the application's build time. Since Xcode occasionally runs old builds, I use this to notice it early.

VideoEditor

https://github.com/noppefoxwolf/VideoEditor

A customizable clone of UIVideoEditorController. You can pass the selected range when displaying it.

DrawerPresentation

https://github.com/noppefoxwolf/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

https://github.com/noppefoxwolf/Pager

A UICollectionView-based page controller.
It is easier to customize compared to UIPageViewController.

RelativeDateFormat

https://github.com/noppefoxwolf/RelativeDateFormat

Converts relative time into short formats like "1s" or "1m" used in SNS timelines.

SwipePopInteraction

https://github.com/noppefoxwolf/SwipePopInteraction

Enables returning to the previous screen using a full-screen swipe.

ConsoleKit

https://github.com/noppefoxwolf/ConsoleKit

A tool to view OSLogs within the app.

MediaOptimizer

https://github.com/noppefoxwolf/MediaOptimizer

A tool to fit images and videos into optimal sizes and capacities.

EventNotification

https://github.com/noppefoxwolf/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!

https://apps.apple.com/jp/app/nightfox-dawn-for-mastodon/id1668645019

Discussion