0

When I include a Stepper inside a List with many rows such that it will scroll off the screen when scrolled the layout becomes completely mucked up. See attached image.

Has anybody had this issue and managed to solve it?

Code to reproduce in Xcode 11.3.1 / iOS 13.3

struct Item: Identifiable {
    let id: String
    let name: String

    init(_ name: String) {
        self.id = UUID().uuidString
        self.name = name
    }
}

struct ContentView: View {

    let items: [Item] = [
        Item("Car"),
        Item("Shoe"),
        Item("House"),
        Item("Pencil"),
        Item("Crayon"),
        Item("PC"),
        Item("Spoon"),
        Item("Box"),
        Item("Tennis Racket"),
        Item("Mobile Phone"),
        Item("Hat"),
        Item("Table"),
        Item("Chair"),
        Item("Painting"),
        Item("Couch"),
        Item("Desk"),
        Item("Fireplace"),
        Item("Stove"),
        Item("Kettle"),
        Item("Fork"),
        Item("Knife"),
        Item("Dinner Plate")
    ]

    var body: some View {
        List() {
            ForEach(items) { item in
                ItemRow(item: item)
            }
        }
    }
}

struct ItemRow: View {
    let item: Item

    @State private var quantity: Int = 1

    var body: some View {
        HStack(spacing: 10) {
            Text(item.name)
            Stepper(onIncrement: {
                self.quantity = self.quantity + 1
            }, onDecrement: {
                self.quantity = self.quantity - 1
            }, label: {
                Text("\(quantity)")
                    .padding()
            })
        }
    }
}

Thanks in advance, Matt

Stepper Layout Issue

Sway
  • 1,647
  • 3
  • 16
  • 19

1 Answers1

0

You're not the one with this problem. There is some issue with list, but in canvas only. According to this answer, you can try your list on the real device and it should looks in normal way. So I tried it on iPhone 7:

enter image description here

Hrabovskyi Oleksandr
  • 3,070
  • 2
  • 17
  • 36
  • I'm using an iPad and it still exhibits this problem on the device. Thanks for the link. I've switched to using a ScrollView as suggested in the interim which is working ok for now. – Sway Jan 20 '20 at 00:50