NEW: Learn to build the incredible iOS 15 Weather app today! >>

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

Forums > SwiftUI

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. However compare the results in iOS 14 (works) vs iOS 15 (doesn't work):

Expanding and collapsing works okay in iOS 14 The section initially renders okay in iOS 15, but after collapsing and expanding it, nothing gets rendered in the section.

As you can see, in iOS 15 if I collapse the section, it no longer renders when I expand it again.

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?

Question also posted on StackOverflow.

   

Ruuning Xcode 13 iOS 14.4 iPhone 12 Pro Max simulator, this warning was given when expanding the list section.

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.ListCoreCellHost: 0x7f9d5d060200; baseClass = UITableViewCell; frame = (0 81; 388 88.9757); clipsToBounds = YES; autoresize = W; layer = <CALayer: 0x600003d8d8a0>>

Which is the same type of error you get if you add another Text line Text("Other text') to your code.

VStack {
    Text("TextView")
    DatePicker(selection: $selectedDate, displayedComponents: .date) {
        Text("DatePicker")
    }
    Text("Other text")
}

Adding extra text line is not a solution to your problem, maybe a workaround at best, however the text and DatePicker do appear to now work again. (iOS 15.0 iPhone 12 Max Pro).

More usual is you then take this modified code and build for the iPad. Your observed issue return.

I think it is worth raising feedback to Apple, as it might be a bug in the simulators / Xcode in how it handles sidebar, main and detailed views together.

   

Hacking with Swift is sponsored by Sentry

SPONSORED With Sentry’s error and performance monitoring for iOS, you see mobile vitals that actually matter, can solve any latency issues quickly, and learn how each release is performing over time.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.