swiftuiapple-watchwatchos

.searchable modifier not working on watchOS 10.2, 10.3


So, we have a watchOS app in production featuring a list inside a navigation stack and a searchable modifier.

All worked well, but ever since the release of watchOS 10.2, the search bar has stopped working.

You can view, tap, and write a query, but the binding to the state variable does not work and it's impossible to read the user's query.

I've written a very simple demo View that showcases the issue. I tried it on a Series 7 Apple Watch running watchOS 10.2.

struct ContentView: View {

    @State private var searchText = ""
    @State private var showResult = false

    var body: some View {
        NavigationStack {
            List {
                Text("1")
                Text("2")
                Text("3")
                if showResult {
                    Text(searchText)
                }
            }
        }
        .searchable(text: $searchText)
        .onChange(of: searchText) { _, searchText in
            showResult = true
        }
    }
}

By the way, breakpoints on either @State searchText or inside the .onChange modifier are never triggered.

I have three questions:

  1. Am I doing something wrong here? This way of doing a search field worked previously, but maybe I am doing something bad and it shouldn't have worked in the first place.
  2. Have you noticed the issue as well? Is the code I provided also showcase a non-responsive search on your end?
  3. How to make it work?

Solution

  • Apple finally fixed it in watchOS 10.4.