简体   繁体   中英

is iOS 14.2 datePicker broken?

I am encountering a problem with DatePickers() view in iOS 14.2 when they are in Forms when the keyboard opens. Can somebody confirm that it is a swiftUI Bug ? I am quite new to iOS dev.

Here is my view :

struct TestView: View {
    @State private var test = Date()
    var body: some View {
        return
            NavigationView {
                VStack {
                    HStack {
                        Spacer()
                        Capsule()
                            .fill(Color.secondary)
                            .frame(width: 80, height: 5, alignment: .center)
                        Spacer()
                    }.padding()
                    Form {
                        Section(header: Text("sectionTitle")) {
                            Group {
                                Text("something")
                                Text("To")
                                Text("Fill")
                                Text("The")
                                Text("View")
                                Text("Vertically")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")

                            }
                            Group {
                                Text("something")
                                Text("To")
                                Text("Fill")
                                Text("The")
                                Text("View")
                                Text("Vertically")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")

                            }
                            DatePicker("a label",
                                       selection: $test,
                                       displayedComponents: .hourAndMinute)
                        }
                    }
                    .padding()
                }
        
            }
    }
}

What is happening is : When I click on the datePicker -> the picker is showed in a modal (normal behaviour in iOS 14) but when editing it the keyboard shows and disappears immediately, closes the modal. Making the Picker unusable.

This does not happen if I remove the Form view OR if I remove some of the texts field.

I use this view in a sheet() on iOS 14.2 iPhone SE 2020 simulator and real device. Work properly on ios13 (with wheels).

Thanks

This looks like a bug. Based on the print out "Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view", it seems that when you click onto the DatePicker, it's having trouble figuring out the full size of the Form (possibly because it's so close to the bottom of the screen?)

Personally, I would remove the DatePicker from the form to ensure users ever encounter this. But if you need to use the Form, work arounds I found:

  1. Add one of the Groups or additional content after the DatePicker
  2. Add a Spacer(minLength: 200) after the DatePicker
  3. Set the frame's height of the Form

Consider to use GraphicalDatePickerStyle instead of default style.

HStack {
    Text("a Label")
    Spacer()
    DatePicker("", selection: $test, displayedComponents: .hourAndMinute)
        .datePickerStyle(GraphicalDatePickerStyle())
}

I think this is an Apple bug, I'm using the picker this way

Form {
     Section {
        DatePicker(self.label, selection: self.value)
     }
}

and still I have this error

2020-11-29 21:11:08.171127+0100 Budgetify[85909:3309604] [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.ListCoreCellHost: 0x7ffdbc08f800; baseClass = UITableViewCell; frame = (0 123; 788 44); autoresize = W; layer = <CALayer: 0x60000223b960>>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM