I am facing an issue while implementing NavigationView with list and LazyVGrid. In the first switch statement I am using TabView to display horizontal views,and in the second switch statement I am using lazyVGrid to display Vertical Grid. The problem is that when I click on horizontalView(TabView) it works fine and navigate to another screen but when I click on the GridItem to navigate to another screen it makes the background grey and pause the whole UI.
Here is my code,
struct BreakingNewsView: View {
@StateObject private var viewModel = BreakingNewsViewModel(networkController: NetworkController())
private let columns = [GridItem(.flexible(), spacing: 20), GridItem(.flexible(), spacing: 20)]
var body: some View {
NavigationView {
List {
//Horizontal
switch viewModel.GNewsHorizontal {
case .notStarted:
EmptyView()
case .loading:
ProgressView()
case .success(let data):
BreakingNewsHorizontalView(articles: data.gArticles!)
.frame(height: 250)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
case .error(let error):
let nm = print(error)
}
//Vertical
switch viewModel.NewsApiVertical {
case .notStarted:
EmptyView()
case .loading:
ProgressView()
case .success(let data):
LazyVGrid(columns: columns, spacing: 15) {
ForEach(data.newsArticles!, id: .id) { article in
BreakingNewsVerticalListItem(article: article)
.background(
NavigationLink(destination: NewsDetailView(url: URL(string: article.url ?? "https://www.google.com")!)) {
EmptyView()
}
.opacity(0.0)
)
}
}
.padding(.horizontal, 0)
case .error(let error):
let nm = print(error)
}
}//: LIST
.listStyle(PlainListStyle())
.navigationTitle("Breaking News")
}
.task {
print("startFetching")
await viewModel.getHorizontalNews()
}
//: NAVIGATIONVIEW
}
}