The simplest TabView inside a List in SwiftUI seems to break the constraints. I get a warning in the simulator and it looks fine but on real devices each cell overlaps each other because of these issues. If I replace the TabView with a simple red square everything works fine, so I've definitely narrowed it down. This seems like something that should be possible. I need the TabView to have an aspect ratio, but again, just giving it a fixed size still makes the List (tableview) complain about ambiguous constraints.
struct TestView: View {
@ObservedObject var viewModel: FeedCardViewModel
@State private var selectedItem = 1
var body: some View {
TabView(selection: $selectedItem) {
ForEach(Array(viewModel.images.enumerated()), id: \.element) { (_, _) in
Rectangle()
.fill(Color.red)
.frame(width: 200, height: 200)
}
}
.tabViewStyle(.page)
.indexViewStyle(.page(backgroundDisplayMode: .always))
.frame(width: 200, height: 200)
.padding()
}
}
Log Warning:
[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: 0x118148800; baseClass = UITableViewCell; frame = (0 220; 428 244); autoresize = W; layer = <CALayer: 0x10d415a40>>