SwiftUI Picker does not respect frame size on device

115 Views Asked by At

My Picker view goes beyond the frame size only on device, while works fine in simulator. This view is not a part of a Form or List, just inside a VStack

var body: some View {
    HStack {
        Text(title)
            .foregroundColor(.gray)
        Spacer()
        
        if isEditing {
            Picker(selection: $value) {
                Section {
                    Text("None").tag("None")
                }
                Section {
                    ForEach(Countries.all, id: \.self) { i in
                        Text(i).tag(i)
                    }
                }
            } label: {}
            .frame(height: DocumentPage.rowHeight) // <-- This is ignored 
        } else {
            // View when not editing
        }
        
    }
    .frame(height: DocumentPage.rowHeight) // <-- And this is ignored
}

On the Simulator vs. on device

1

There are 1 best solutions below

0
Grant Oganyan On

Using .layoutPriority(1) on the Picker() and .fixedSize() on the Text() helped.