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 areForEach
feature but swipe to delete is not working onScrollView
)
- 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)
- Advantages:
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:
- Supports pull-to-refresh on iOS 16
- No native support for swipe actions like
onDelete
,onMove
(Some solutions: Deleting rows inside LazyVStack and ForEach in SwiftUI, Swipe to delete function)
- Advantages:
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) andScrollView
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).