我注意到,当一个视图有一个带有搜索栏的列表,向下滑动操作会导致它出现时,Xcode会显示警告。
- 警告消息:* [Assert]如果不是showsScopeBar更改,是什么在动画期间将导航栏边界大小更改为意外大小?
我创建了一个简单的项目来重现相同的行为(添加了下面的代码)。我们如何修复它?谢谢。
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)
}
}
演示:
1条答案
按热度按时间t40tm48m1#
将searchable的放置参数设置为
.navigationBarDrawer(displayMode: .always)
应该可以解决这个问题。