2

I noticed that Xcode shows warning when a view has list with SearchBar and swipe down action leads to it.

The warning message: [Assert] What changed the navigation bar bounds size to something unexpected during the animation if it wasn't a showsScopeBar change?

I created a simple project to reproduce the same behavior (added code below). How we can fix it? Thanks.

enum Route: Hashable {
    case list
}

class ExampleCoordinator: ObservableObject {
    @Published var path = NavigationPath()

    func push(_ route: Route) {
        path.append(route)
    }
}

struct ContentView: View {
    @StateObject private var coordinator = ExampleCoordinator()
    var body: some View {
        ZStack {
            NavigationStack(path: $coordinator.path) {
                VStack(spacing: 40) {
                    Button("Test") {
                        coordinator.push(.list)
                    }
                }
                .navigationTitle("Hello")
                .navigationDestination(for: Route.self) { route in
                    switch route {
                    case .list:
                        ListView()
                    }
                }
            }
        }
    }
}

struct ListView: View {
    @State private var searchableText = ""
    let array: [Int] = {
        var array = [Int]()

        for value in 0...99 {
            array.append(value)
        }
        return array
    }()

    var body: some View {
        list
            .navigationBarTitleDisplayMode(.inline)
            .searchable(text: $searchableText, placement: .toolbar)
            .autocorrectionDisabled(true)
            .scrollDismissesKeyboard(.immediately)
    }

    private var list: some View {
        List {
            ForEach(array, id: \.description) { number in
                Text(number.description)
                    .id(number)
            }
        }
        .listStyle(.plain)
    }

} 

Demo:

enter image description here

Alexander Khitev
  • 6,417
  • 13
  • 59
  • 115
  • I don't see any error message when running your code (Xcode 14.2, iOS 16.2). What message are you seeing? – Ashley Mills Jan 14 '23 at 13:01
  • @AshleyMills I see "[Assert] What changed the navigation bar bounds size to something unexpected during the animation if it wasn't a showsScopeBar change?" in the Xcode console. I also use iOS 16.2 and Xcode Version 14.2 (14C18). – Alexander Khitev Jan 14 '23 at 13:03
  • That's strange. Which device / simulator are you seeing it on? From your question, you're seeing the message when you swipe down to reveal the search box, is that right? – Ashley Mills Jan 14 '23 at 13:35
  • @AshleyMills I use iPhone 12 Pro Max. I see this message when Search Bar is active then I swipe down on list and Search bar become inactive and then I see this message. – Alexander Khitev Jan 14 '23 at 13:39
  • 1
    Thanks, I managed to reproduce it by tapping in the search bar, swiping up and then quickly swiping down again. – Ashley Mills Jan 14 '23 at 13:50

1 Answers1

-1

Setting the placement parameter for searchable to .navigationBarDrawer(displayMode: .always) should solve it.

CrisAhmad
  • 29
  • 5