swiftuibottom-sheet

SwiftUI sheet detents and drag indicator never appear


I have a ForEach loop embedded in a NavigationStack and a List like so:

NavigationStack{
 List{
  Section{
    ForEach(todayItems) { item in
      Button {
       selectedItem = item  // Set the selected item
      } label: {
          ToDoLabel(item: item)
          .foregroundStyle(.myAccent)
      }
      .listRowSeparator(.hidden)     
  }
 }
 .sheet(item: $selectedItem) { item in
      ToDoSummaryView(toDoItem: item, allItems: items)
      .presentationDetents([.medium])
      .presentationDragIndicator(.visible)
 }
}

I'm having an issue with the bottom sheet consistently displaying as .large and not .medium, and the drag indicator not appearing despite setting it as .visible.

I've tried repositioning the .sheet code block under the button and the ForEach, but it hasn't resolved the issue.

Everything else is working fine; the sheet opens and the passed arguments are okay.

Any guidance on how to address this would be greatly appreciated. Thank you in advance.


Solution

  • I found the solution. It turns out the problem wasn't the .sheet position in the code, but rather the fact that my ToDoSummaryView() didn't have a NavigationStack in it. Everything works fine now. I hope this can be useful to someone else!