0

I have prepared a simple example. If you tap on the button, a sheet will be presented containing the CustomSheetView. Do not behalf on the design itself it is more about the scrolling behaviour. If I want to scroll the list at first the sheet will be dragged to the top notch and afterwards the list can be scrolled.

In a nutshell... e.g. Instagrams comment section can be scrolled without the sheet (if it is a sheet at all) being dragged to the top notch.

struct CustomSheetView: View {
    
    var body: some View {
        
        VStack {

            SomeView()
            
            Spacer()
            
            List {
                ForEach(1...40, id: \.self) { index in
                    Text("Item \(index)")
                }
            }
            
            Spacer()
            
            SomeOtherView()

        }
    }
}

struct ContentView: View {
    @State private var isSheetVisible = false
    
    var body: some View {
        Button("Open Sheet") {
            isSheetVisible = true
        }
        .sheet(isPresented: $isSheetVisible, content: {
            CustomSheetView()
                .presentationDetents([.fraction(0.8), .large])
        })
    }
}

I tried .allowsHitTesting(false) to somehow tell the UI to not drag the sheet if the list only has to be scrolled.

Dgotin
  • 38
  • 8
  • Set a maximum height frame for the list – Ptit Xav Jun 04 '23 at 10:01
  • This behavior seems to be a result of you providing more than one detent in `.presentationDetents()`. Documentation says: "If you provide more that one detent, people can drag the sheet to resize it." If your design allows it, you could remove one of the detents and make it something like: `.presentationDetents([.fraction(0.8)])` – Baglan Jun 04 '23 at 10:59
  • Setting a max height did not really help as it wont affect anything with gestures. The presentationDetents helped but the sheet is not draggable at all. Testing right now some different approaches maybe I will find a desired solution. – Dgotin Jun 07 '23 at 08:05

1 Answers1

0

https://developer.apple.com/documentation/swiftui/view/presentationcontentinteraction(_:)

On iOS 16.4 or up

    .presentationContentInteraction(.scrolls)

Will make the inner list scroll rather than resize.

Kyle Fang
  • 1,139
  • 6
  • 14