0

I'm using .searchable to embed a search bar into a list view. However, when the .searchable is nested in a NavigationStack (iOS 16 API), it is twinking when the page is loaded (shows up at first and disappears quickly). I hope both pages have a searchable feature.

I can reproduce this issue both on my device iPhone 12 and the simulator iPhone 14. Am I putting the modifier in an incorrect place?

struct ContentView: View {
    @State private var selection = "2"
    
    @State var items: [String] = ["0", "1", "2", "3", "4"]
    @State var searchText = ""
    
    var body: some View {
        NavigationStack {
            List {
                ForEach(items, id: \.self) { item in
                    NavigationLink {
                        NestedListView(items: items)
                    } label: {
                        Text(item)
                    }
                }
            }
            .searchable(text: $searchText)
        }
    }
}

struct NestedListView: View {
    var items: [String]
    
    @State var searchText = ""

    var body: some View {
        List {
            ForEach(items, id: \.self) { item in
                Text(item)
            }
        }
        .searchable(text: $searchText)
    }
}
Sheffield
  • 355
  • 4
  • 18
  • Finally found it was the SwiftUI bug resulting from the new `NavigationStack`. When I change it back to `NavigationView`. Everything looks good. – Sheffield Feb 13 '23 at 03:41

0 Answers0