3

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

5
  • What exactly is your question? Please review How to Ask. Commented Sep 17, 2024 at 11:01
  • I have the same problem: in ios18 my horizontal scroll view also scrolls vertically. Commented Sep 19, 2024 at 23:28
  • Did you find any fix, I have same issue @pwb2103 ? Commented Nov 22, 2024 at 9:54
  • Yeah, much like so many other SwiftUI problems, it was something in a view much higher in the view stack (grand grand parent view?) If you see my answer in my case it was a .refreshable. I suggest testing your view at the very top of your app, confirming it works there (with no parent views to impact it) then working your way down the stack until you find what it breaking it. Commented Nov 23, 2024 at 10:13
  • In my case, the issue was caused by a .refreshable {} modifier applied high up in the view hierarchy (on a NavigationStack). That caused my horizontal ScrollView to also scroll vertically and trigger the refresh indicator. Commented Oct 9 at 23:17

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

this worked for me. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.