SwiftUI How to stop the animation of List in Multi-level NavigationView

☆樱花仙子☆ 提交于 2020-02-05 04:29:46

问题


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

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()
    }
}

回答1:


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



来源:https://stackoverflow.com/questions/59775542/swiftui-how-to-stop-the-animation-of-list-in-multi-level-navigationview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!