MacOS上的SwiftUI NavigationView将填充留在列表上方

时间:2020-07-22 11:59:57

标签: macos swiftui swiftui-list swiftui-navigationlink

我有一个NavigationView,它在NavigationLink的列表上方留了一些填充,但我不知道如何摆脱它? Weird NavigationView bug

以下是调用NavigationView的视图:

struct SearchView: View {
    @EnvironmentObject var networkManager:NetworkManager
    
    var body: some View {
        VStack {
            SearchBar()//<- This view houses the content above the list but contains no padding after the divider and when the filesToDisplay is false it shrinks to the divider as expected
            if networkManager.filesToDisplay {
                ResultsView()
            }
        }
    }
}

这是NavigationView:

struct ResultsView: View {
    @EnvironmentObject var networkManager:NetworkManager
    var body: some View {
        NavigationView {
            List {
                ForEach(networkManager.FileList!.items) { file in
                    NavigationLink(destination: FileDetail(fileDetail: file)) {
                        FileRow(fileRow: file)
                    }
                }
            }
            Rectangle().frame(maxWidth: 0, maxHeight: .infinity)
            }.frame(minHeight:500, idealHeight: 550, maxHeight: .infinity)
    }
}

我认为问题可能与navigationBarTitle有关,但MacOS似乎没有使用它吗?我已经尝试了各种不同的padding和listRowInsets,但是没有任何效果。

1 个答案:

答案 0 :(得分:3)

添加显式间距

VStack(spacing: 0) {   // << here !!
    SearchBar()
    if networkManager.filesToDisplay {
        ResultsView()
    }
}