How to disable vertical bounce in SwiftUI on a single ScrollView

Viewed 2923

I have a half modal view coming from the bottom of the screen with a scrollView, and when there's isn't enough content to scroll I want the drag gesture on the internal scrollView to apply to the modal and expand it or collapse it. I tried using:

init() {
   UIScrollView.appearance().bounces = false
}

And it works fine but this disables the bouncing effect on all the scrollViews in my app. Is there a way to apply this for a single ScrollView or at least a single View?

1 Answers

you can add this to a ViewModifier:

struct SomeModifier: ViewModifier {
    init() {
      UIScrollView.appearance().bounces = false
    }

    func body(content: Content) -> some View {
        return content
    }
}

ScrollView {
  Text("Some scroll view")
}.modifier(SomeModifier()

Related