Having more control over scroll views
Controlling and observing scroll view behavior was part of the reason why UIKit developers hadn’t moved to SwiftUI yet.
Scroll views are crucial in mobile apps, not just because of the small screen, which often requires the user to scroll for more content, but also because they help reuse visible content to minimize memory usage or adjust our UI based on scroll position.
However, why is handling scroll views in SwiftUI more complex than in UIKit? We can think of two reasons:
- SwiftUI is relatively new: SwiftUI is still considered to be a new framework. Think how much time it took for UIKit to become a mature framework. Obviously, we can achieve this in several years and 17 years of development.
- Flexibility: Due to the imperative approach, UIKit gives us direct control over views. This means that we can adjust particular view parameters based on the scroll state. SwiftUI’s declarative nature sometimes makes achieving...