5

I have tried to find a similar problem asked before, but failed.

I have a simple view with list. I am using a ForEach to show 10 iterations of the some list item to create a layout before I will add real data to this list. I have a problem with last 2 rows not rendering correctly. But sometimes it’s other row. I have tested on an iPhone too and sometimes it’s one row, sometimes another. The code for the view with list is this:

import SwiftUI

struct LocksView: View {

    @State private var locksPaid = 0

    var body: some View {
        NavigationView {
            List {
                DateView()
                    .listRowInsets(EdgeInsets())

                Picker(selection: $locksPaid, label: Text("Picker")) {
                    Text("All").tag(0)
                    Text("Not paid (2)").tag(1)
                }
                .pickerStyle(SegmentedPickerStyle())
                .padding(10)

                ForEach(0 ..< 10) {item in
                    LocksItemView()
                }

            }
            .navigationBarTitle(Text("Locks"))
            .navigationBarItems(trailing: EditButton())
        }
    }
}

The code for list items is this:

import SwiftUI

struct LocksItemView: View {

    @State private var paid : Bool = false

    var body: some View {
        HStack {

            Text("L15")
                .font(.title)
                .fontWeight(.heavy)
                .multilineTextAlignment(.center)
                .frame(width: 80)

            VStack(alignment: .leading) {
                Text("nickname")
                    .fontWeight(.bold)
                Text("category")
                Text("4 000 THB")
                    .fontWeight(.bold)
            }

            Spacer()

            Toggle(isOn: self.$paid) {
                Text("Paid")
            }
            .labelsHidden()
        }
    }
}

Why is toggle broken in some rows on my list? Why it moves to the left side?

enter image description here

mallow
  • 2,368
  • 2
  • 22
  • 63

2 Answers2

2

It is not last items. If you set in your ForEach 20 instead of 10 and scroll up & down you'll see much more interesting issue.

I assume the reason, actually List bug, is the same as in this topic.

Workaround If it is not critical to you then use ScrollView instead of List, as tested there is no bug for it. Otherwise, file a Radar and wait for fix.

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • Thanks @Asperi. I am using List, because ScrollView was causing other problems. I think I will stick with the List for a while and try to solve this problem. If not so need to solve other problems with the ScrollView :) – mallow Nov 21 '19 at 03:42
  • BTW, thanks for that observation that it’s not always last 2 rows. I tested again on my phone at sometimes it’s one row sometimes another. I have updated my question – mallow Nov 21 '19 at 03:47
  • Asperi, your workaround works. Just tried. Thanks for this! But as I said I had some issues with ScrollView. And as @Александр found this is probably a bug and I hope it will be solved in next iOS update. If not, I will try to use your workaround and fix issues with scrollview. – mallow Nov 21 '19 at 05:07
1

I tried your code at simulators first and had same issue too. But then I remembered, that there are some problems with 13.2 iOS and tried to run it on my device (iPhone 7, iOS 13.1.1) and everything works fine! I think that is the problem in 13.2 iOS, not in the List. There is sample, how I changed code for demonstration that everything is ok:

import SwiftUI

struct LocksView: View {
    
    @State private var locksPaid = 0

    var body: some View {
        NavigationView {
            List {
                Picker(selection: $locksPaid, label: Text("Picker")) {
                    Text("All").tag(0)
                    Text("Not paid (2)").tag(1)
                }
                .pickerStyle(SegmentedPickerStyle())
                .padding(10)

                ForEach(0 ..< 200) {item in
                    LocksItemView(number: item)
                }

            }
            .navigationBarTitle(Text("Locks"))
            .navigationBarItems(trailing: EditButton())
        }
    }
}

struct LocksItemView: View {

    @State private var paid : Bool = false
    var number: Int

    var body: some View {
        HStack {

            Text("L\(self.number)")
                .font(.title)
                .fontWeight(.heavy)
                .multilineTextAlignment(.center)
                .frame(width: 80)

            VStack(alignment: .leading) {
                Text("nickname")
                    .fontWeight(.bold)
                Text("category")
                Text("4 000 THB")
                    .fontWeight(.bold)
            }

            Spacer()

            Toggle(isOn: self.$paid) {
                Text("Paid")
            }
            .labelsHidden()
        }
    }
}

and on my phone the result is:

enter image description here

so there are bugs in 13.2 version and I hope Apple will fix them all

Community
  • 1
  • 1
Hrabovskyi Oleksandr
  • 3,070
  • 2
  • 17
  • 36
  • Wow! Thank you very much for that observation. How can I file a bug with a SwiftUI? I will try to solve this problem for a while. Maybe adding ID for rows will help? Maybe now the rows are not treated 100% as separate rows? Just a guess. But your discovery shows that even with this exact code is working on previous iOS. Thanks! – mallow Nov 21 '19 at 03:51
  • @mallow, I think https://feedbackassistant.apple.com is right place to file this bug, maybe today later I'll do it too – Hrabovskyi Oleksandr Nov 21 '19 at 04:01
  • Thanks! I will do it it. I have filed few bugs there about macOS or iOS but they were never fixed and very rarely my submissions were answered at all. So I was hoping there is some better way :) – mallow Nov 21 '19 at 04:05
  • @mallow, review sent to Apple, but I think it shouldn't disturb you to do the same =) – Hrabovskyi Oleksandr Nov 21 '19 at 04:31
  • Александр Thank you very much for doing this. I have just submitted the bug by myself as well. I have also installed new Simulator in my Xcode with iOS 13.1 and the same as you told me - everything looks perfect on this. I hope Apple will fix the bug in the next iOS update. – mallow Nov 21 '19 at 05:08
  • 1
    This bug is still present in 13.3. :/ – Stefan Vasiljevic Jan 05 '20 at 20:37