内容简介:We already started collecting our questions for Apple engineers. On the other hand, I decided to share with you myLast year
We already started collecting our questions for Apple engineers. On the other hand, I decided to share with you my SwiftUI wishlist for WWDC20. This week we will talk about possible additions and changes in SwiftUI . I will show you also API that I expect to see during the next release of SwiftUI .
ScrollView
ScrollView has a bunch of bugs right now. I believe Apple will fix all of them, but I also hope for a content offset binding option. There is no way to get or set the current content offset of ScrollView in SwiftUI . We need a way to both assign and read the offset, and it is a perfect use-case for a Binding . Let’s take a look at the quick example.
struct RootView: View { @State private var offset: CGPoint = .zero var body: some View { ScrollView(.vertical, showsIndicators: false, offset: $offset) { Text("Very long text") Button("Jump to top") { self.offset = .zero } } } }
CollectionView and CompositionalLayout
Last year Apple released CompositionLayout that provides us a declarative way of building complex layouts for UICollectionView . The buzzword here is declarative . It feels very natural for SwiftUI to have a similar API , I’m not sure why Apple didn’t release it last year, but I expect to see it soon.
CompositionalLayout introduces a few concepts to manage complex layouts. For example, it has sections, groups, and items. As you know, we already have these concepts in SwiftUI . I think SwiftUI views like Group and Section can behave in another way depending on the context. We already saw that views can behave differently inside a Form or a List . Let’s take a look at how it might work in SwiftUI .
struct AppStoreView: View { let featured: [App] let appsWeLove: [App] var body: some View { CompositionalLayout { Section(.groupPagingCentered) { Group(.horizontal, width: .fractionalWidth(0.5), height: .fractionalHeight(0.5)) { ForEach(featured) { app in FeatureAppView(app: app) } } } Section { Group(.vertical, width: .fractionalWidth(0.9), height: .estimated(200)) { ForEach(appsWeLove) { app in SmallAppView(app: app) } } } } } }
Navigation
As I already said multiple times, Navigation in SwiftUI is really problematic. The main rule behind the SwiftUI framework is “view is a function of some state” . SwiftUI doesn’t apply this rule to Navigation . Navigation in SwiftUI looks like uncontrollable magic. In my opinion, it also should be a function of a state where the state describes a navigation stack. Let’s take a look at the example.
enum Destination { case master case details(Post) } struct RootView: View { @EnvironmentObject var router: Router<Destination> var body: some View { RouterView(router: router) { destination in switch destination { case .master: return PostsView() case .details(let post): return PostDetails(post: post) } } } }
As you can see, RouterView accepts an instance of the Router class, which describes a navigation stack and a ViewBuilder closure that we use to build a view according to the navigation state.
To learn more about @ViewBuilder in SwiftUI , take a look at my “The power of @ViewBuilder in SwiftUI” post.
Appearance API
SwiftUI provides us styling options by introducing a bunch of protocols. For example, ButtonStyle , ToggleStyle , etc. We create a struct that conforms to the ButtonStyle protocol. After that, we can put it into the environment, and all views inside the environment gain particular styling. I appreciate the way styling works in SwiftUI right now, but we need to expand it to support more views like Form and NavigationView .
To learn more about styling in SwiftUI , take a look at my “Composable styling in SwiftUI” post.
Missing views
SwiftUI provides us a set of very basic views that we can use to build our apps. There are a lot of views that we don’t have in SwiftUI . I hope to see a bunch of new views coming in the next weeks. For example, SearchBar , TextView , RefreshControl , etc.
Conclusion
This week, I share my vision and expectations with you about the future of the SwiftUI framework that we hopefully will see later this month. I hope you enjoy the post. Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading, and see you next week!
以上所述就是小编给大家介绍的《SwiftUI wishlist for WWDC20》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
数据库系统实现
加西亚-莫利纳(Hector Garcia-Molina)、Jeffrey D.Ullman、Jennifer Widom / 杨冬青、吴愈青、包小源 / 机械工业出版社 / 2010-5 / 59.00元
《数据库系统实现(第2版)》是斯坦福大学计算机科学专业数据库系列课程第二门课的教科书。书中对数据库系统实现原理进行了深入阐述,并具体讨论了数据库管理系统的三个主要成分——存储管理器、查询处理器和事务管理器的实现技术。此外,第2版充分反映了数据管理技术的新进展,对内容进行了扩充,除了在第1版中原有的“信息集成”一章(第10章)中加入了新的内容外,还增加了两个全新的章:“数据挖掘”(第11章)和“数据......一起来看看 《数据库系统实现》 这本书的介绍吧!