Reputation: 5
So I'we been stuck on this for a few days and any feedback is very much appreciated!
I have a post option inside a custom camera view which once pressed, presents a sheet with a searchable bar. Problem is, once the post sheet is presented, array for searchable gets called 6+ times. Even when typing on the search bar, each keystroke results in the array getting loaded 6+ times.
I'm thinking loading this sheet whilst inside the camera is causing this sheet to load multiple times or perhaps it's something else. If anyone has experience dealing with this, any input?
Even when dismissing this sheet, on dismiss this array gets called 6+ times :(
(End goal is to use a 3rd party search api to fill the search result, this api gets called hundreds of times per keystroke)
private var posts: [Post] {
print("Array requested")
return viewModel.searchText.isEmpty ? viewModel.posts() : viewModel.filteredPost()
}
VStack{
ScrollView(showsIndicators: false) {
LazyVStack {
ForEach(posts) { post in
PostCell(post: post)
.padding(.leading)
}
}
.searchable(text: $viewModel.searchText, placement: .sidebar, prompt: "Who/What is in this photo?"){
ForEach(posts, id: \.self) { result in
searchCompletion(result)
}
}
}
}
Upvotes: 0
Views: 31