1

I have a SwiftUI List which should both have a search bar and enable pull to refresh.

In theory, this is very simple. However, there is a search bar bug whenever I update any @Published properties in the .refreshable { } code.

My view looks like this:

struct MyView: View {
    @State var text = ""

    var body: some View {
        NavigationView {
           List {
               Text("hello")
           }
           .refreshable {
               model.prop = "world"
           }
        }
        .searchable(text: $text)
    }
}

And my model looks like this:

class Model: ObservableObject {
    @Published var prop = ""
}

I've tried putting the update in an async block, but it did not solve the problem:

DispatchQueue.main.async {
    model.prop = "world"
}

Any non-ObservableObject-mutating code inside of the .refreshable { } block works perfectly fine.

Am I doing something wrong?

enter image description here

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 31 '23 at 14:15
  • move .searchable to be on the List instead of the NavigationView – malhal Jan 31 '23 at 21:17
  • I've tried putting .searchable both before and after .refreshable on the list, but the problem persists. – IcyHovercraft Jan 31 '23 at 22:15
  • I'm experiencing the same issue but with large naviation bar... https://stackoverflow.com/questions/75718110/swiftui-refreshable-large-navigation-titile-jumps-when-pull-to-refresh-is-eng – kironet Mar 15 '23 at 03:54

0 Answers0