UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

2      

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.

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.