Can't render a Text view and DatePicker together in a sidebar list section in iOS 15

Consider the following SwiftUI View:

struct ContentView: View {
  @State private var selectedDate = Date()
  var body: some View {
      List {
        Section(header: Text("TextView and DatePicker")) {
          VStack {
            Text("TextView")
            DatePicker(selection: $selectedDate, displayedComponents: .date) {
              Text("DatePicker")
            }
          }
        }
      }
      .listStyle(.sidebar)
  }
}

With the sidebar list style, I should be able to collapse and expand list sections. This works in iOS 14. However in iOS 15 the section initially renders okay, but after collapsing and expanding it, nothing gets rendered in the section.

The problem seems very specific to having both Text and DatePicker views inside the section. Any other combinations seem to work okay.

Am I doing something wrong here? Or is there a bug in iOS 15? Are there any workarounds if I need to render this?

I get the same bug. Even adding a second section with EmptyView() or adding an EmptyView in First section do not change anything.

I get the following error message in log when keeping datePicker alone and collapsing and restoring:

2021-10-04 08:21:45.040407+0200 SwiftUI 00 - zeroth for basic test[11653:339461] [Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and using standard height instead. Cell: <SwiftUI.ListTableViewCell: 0x7fbf19824400; baseClass = UITableViewCell; frame = (0 40; 350 54.3333); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x6000013bcee0>>

I set a frame size and it works OK:

struct ContentView: View {
  @State private var selectedDate = Date()
  var body: some View {
      List {
        Section(header: Text("TextView and DatePicker")) {
          VStack {
            Text("TextView")
            DatePicker(selection: $selectedDate, displayedComponents: .date) {
              Text("DatePicker")
            }
          }
          .frame(height: 50)       // <<-- ADDED
        }
      }
      .listStyle(.sidebar)
  }
}

I tried with minHeight:

          .frame(minHeight: 50)

But it doesn't work.

This works, but will it fit your need ?

          .frame(minHeight: 50, idealHeight: 50)

It is probably the same constraint as frame(height).

Could you compute the needed height ? Read this for help:

h t t p s : / / newbedev.com/swiftui-hstack-with-wrap-and-dynamic-height

In any case, that seems to be a bug in iOS that needs to be corrected. You should file a bug report.

Can't render a Text view and DatePicker together in a sidebar list section in iOS 15
 
 
Q