-2

Hey iOS developers,

I want to use only one component to list everything, therefore, I created a list of advantages and disadvantages of List and ScrollView and they depend on my experiences.

Do you have any advice or solutions for their disadvantages and what do you think about List and ScrollView? Which one do you prefer?

  • List

    • Advantages:
      • Supports pull-to-refresh on iOS 15
      • Performs better but not noticeable
      • Supports swipe actions like onDelete, onMove (they are ForEach feature but swipe to delete is not working on ScrollView)
    • Disadvantages:
      • Extra spacing above sections (They are not removable)
      • There is a default height for the section header on iOS 15, it causes overlapping header and items if the header's height is bigger than default. (To fix that reduce header height or update defaultMinListHeaderHeight environment)
      • No background (Can be updated the List background on iOS 16 by adding .background(.pink) and .scrollContentBackground(.hidden))
        • No background when empty
        • Shows cell background when not empty
      • Shows unwanted spaces when progress view is used for an item
      • No hide option for separator on iOS 14 (public func listRowSeparator(_ visibility: Visibility, edges: VerticalEdge.Set = .all) -> some View on iOS 15 or later)
      • No support for horizontal scroll
      • No support to use LazyVStack / LazyHStack / LazyGrid
      • All section headers should be sticky when .listStyle(.plain) (Headers are not sticky when .listStyle(.insetGrouped) but the design of the listing is too restricted)
      • Scrolls top when listing array is changed (adding new an item)
  • ScrollView

    • Advantages:
      • Supports horizontal and vertical scroll
      • Supports to use LazyVStack/ LazyHStack/LazyGrid and more
      • Supports updating background without using cell background
      • No extra spaces between sections
      • No default height for section header
      • Has the option to set section headers sticky or not. (it is a LazyVStack/ LazyHStack/LazyGrid feature)
      • Preserves the scroll position (adding new an item)
    • Disadvantages:

UIScrollView can be used before iOS 16 (Haven't tried it yet but there are some solutions on the web - Start SwiftUI implementation of UIScrollView at specific scroll and zoom, LegacyScrollView) and ScrollView can be used on iOS 16 and later to make almost the same design for every iOS version.

Custom pull-to-refresh logic can be added to ScrollView before iOS 16 and the design can be the same for all iOS versions (Pull down to refresh data in SwiftUI).

  • This is very opinion based. But from my experience list until iOS 16 was very buggy, limited configuration options and so on. So I do everything with `ScrollView { LazyVStack {` combo while I have to support iOS 15 and below. From iOS 16 it seems the list was much improved, so I will consider migrating to it once older versions EOL – timbre timbre Sep 01 '23 at 15:09

0 Answers0