swiftswiftuiios-simulatorios18

iOS 18 SwiftUI ScrollView(.horizontal) how to disable vertical scroll, drag, and refresh


I have a ScrollView that looks like this

ScrollView(.horizontal, showsIndicators: false) {
    HStack(spacing: 0) {
        ForEach(someCollection) { collection in
            CollectionButton(collectionType: collection)
        }
   }
}
.frame(height: 56)

The problem is that when i try to drag it's conent, it's draggable and scrollable vertically. The refresh indicator also appears

This is an iOS 18 only issue. It behaves perfectly on iOS 17.

Tried: replacing .horizontal to .vertical just to test if maybe it's because the HStack has more height than the ScrollView Result: .vertical works properly. no refresh no scrolling horizontally

Tried:

ScrollView(.horizontal, showsIndicators: false) {
    HStack(spacing: 0) {
        ForEach(someCollection) { collection in
            CollectionButton(collectionType: collection)
        }
   }
   .frame(height: 50)
}
.frame(height: 56)

Result: did not work i can still drag vertically and the refresh indicator still comes out


Solution

  • Your HStack showing a refresh indicator means you likely have a .refreshable {} somewhere in a parent view of the code you have shown. Remove that or move it to the appropriate VStack that you actually want to be refreshable and ScrollView(.horizontal) should work as expected again