Home > Software engineering >  SwiftUI: ScrollView that drags bottom sheet with it
SwiftUI: ScrollView that drags bottom sheet with it

Time:10-20

I'm trying to create a SwiftUI Scrollview that drags its container like this: https://drive.google.com/file/d/1O92DgsVI1OjM1HEUXUwVywB8gcdShOP-/view?usp=sharing

Many Apple apps use this (Apple Maps, Music, Wallet, etc) but I haven't found an easy way to do it wit SwiftUI. What do you think is the best way to implement this simply?

I've looked at most libraries here https://github.com/search?q=swiftui drawer but none of them implements their drawer with a ScrollView in it that can drag the view.

I also tried implementing a custom UIScrollView as UIViewRepresentable and I tried to tweak the scrollViewWillBeginDragging() but I could not make it work.

CodePudding user response:

Following to apply throughout the application

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { UIScrollView.appearance().bounces = false }

CodePudding user response:

struct ContentView: View {
init() {
    UIScrollView.appearance().bounces = false
}
var body: some View {
    ZStack {
        DraggableView()
        ScrollView {
            LazyVStack {
                Text("Hello World")
            }
        }
    }
}
}
  • Related