1

I just want to stop the animation when I have a multi List in multi-level NavigationView. Maybe this is not "ANIMATION", I just want to fix that.

On Xcode Version 11.3.1 (11C504) + iOS 13.2

enter image description here

The code is simple and you can find out it's wired.

import SwiftUI

struct TestView: View {
    var body: some View {
        NavigationView {
            List {
                ForEach(1...4, id: \.self) {_ in
                    NavigationLink(destination: AView()) {
                        Text("root")
                    }
                }
            }
        }
    }
}

struct AView: View {
    var body: some View {
        List {
            ForEach(1...4, id: \.self) {_ in
                NavigationLink(destination: BView()) {
                    Text("aview")
                }
            }
        }
    }
}

struct BView: View {
    var body: some View {
        List {
            ForEach(1...4, id: \.self) {_ in
                NavigationLink(destination: BView()) {
                    Text("bview")
                }
            }
        }
    }
}

struct TestView_Previews: PreviewProvider {
    static var previews: some View {
        TestView()
    }
}
GuoJing
  • 13
  • 1
  • 1
  • 11
  • If you mean those `springs` at the end of transition (on your screen recording) then such is not observed at my side. Tested with Xcode 11.2 / iOS 13.2. – Asperi Jan 16 '20 at 19:26
  • @Asperi My environment is Xcode Version 11.3.1 (11C504) / iOS 13.2. :( – GuoJing Jan 17 '20 at 02:09
  • This is known bug in swiftUI. You can see question here - [https://stackoverflow.com/questions/58505286/how-to-get-rid-off-animation-glitch-when-navigating-to-another-view-in-swiftui] – shraddha11 Jan 21 '20 at 10:52
  • Have you tried on real device? Sometimes it happens that such issues are Xcode only. – Asperi Jan 21 '20 at 10:59
  • @Asperi yes, of course, I tried on the real device. – GuoJing Jan 21 '20 at 12:28

1 Answers1

2

Ok... I've installed this bad-luck Xcode 11.3.1... and here is a solution (or workaround, anyway) - use explicit .listRowInsets as in below example (btw, insets can be any value)

List {
    ForEach(1...1000, id: \.self) {_ in
        NavigationLink(destination: BView()) {
            Text("bview")
        }
    }
    .listRowInsets(EdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20))
}

Works for any dynamic List

Asperi
  • 228,894
  • 20
  • 464
  • 690