我们如何在Medium iOS应用程序中使用SwiftUI

A deep dive into our ever growing SwiftUI usage.

深入了解我们日益增长的SwiftUI使用情况。

In my last article, I had a small section about SwiftUI, but I didn’t really go further into our usage, because it was focused on the architecture as a whole. But the simplicity of SwiftUI plays a big part in this new architecture, as it allows us to build self-contained features more easily.

在我上一篇文章中,我有一个关于SwiftUI的小节,但我没有深入讨论我们的使用,因为它侧重于整体架构。但是SwiftUI的简单性在这种新架构中起着重要作用,因为它使我们能够更轻松地构建自包含的功能。

This story will be focused on SwiftUI and how and why we use it in the Medium iOS application.

本文将重点介绍SwiftUI以及我们在Medium iOS应用程序中使用它的方式和原因。

First and foremost, we’ve been using it for a while, since 2020 actually, and last september, we dropped iOS 13 support, so we’ve been able to adopt SwiftUI faster as iOS 14 & 15 support is far better. We still have to make some compromises on iOS 14, but this represents a very small part of our userbase nowadays. I’ll go into the details of those compromises a bit further down this article.

首先,我们已经使用 SwiftUI 一段时间了,实际上是从 2020 年开始的,去年九月,我们放弃了对 iOS 13 的支持,因此我们能够更快地采用 SwiftUI,因为 iOS 14 和 15 的支持要好得多。尽管我们仍然需要在 iOS 14 上做出一些妥协,但这在我们的用户群中占据了非常小的一部分。我将在本文稍后详细介绍这些妥协的细节。

Lists

列表

The lists feature is a great addition to Medium, it’s a whole new layer we added to the platform, and on iOS we decided to go with SwiftUI. It made a lot of sense, because this is a lot of pretty (and new) UI to wire together, a perfect candidate to use SwiftUI.

列表功能是Medium的一个很好的补充,它是我们在平台上添加的一个全新层次,在iOS上我们决定使用SwiftUI。这是非常合理的,因为这是一种需要将许多漂亮(而且新的)UI组合在一起的工作,是使用SwiftUI的完美候选。

We’ve made various components, like the list preview in the first screen on the left:

我们制作了各种组件,比如左侧第一个屏幕上的列表预览:

We try to keep the body as simple as possible, extracting all views to small computed properties or proper SwiftUI views in other files (when you want to reuse them in other components).

我们尽量保持body尽可能简单,将所有视图提取到小的计算属性或其他文件中的适当的SwiftUI视图中(当您希望在其他组件中重用它们时)。

The code is for displaying the list preview component. Nothing fancy in there, but this is to emphazise my point, the body...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.1. UTC+08:00, 2024-11-22 19:02
浙ICP备14020137号-1 $访客地图$