Код: Выделить всё
struct EventSearchView: View {
@State var searchedText = ""
@State var showInspector = false
@State var presentingItemID: Int?
@Namespace var customNamespace
var body: some View {
Group {
// Problem here:
// scroll down and up, you'll see an abnormal jitter
ScrollView {
HStack {
LazyVStack(spacing: 10) {
ForEach(1...50, id: \.self) { id in
Button(action: {
showInspector = false
presentingItemID = id
}, label: {
ZStack {
Rectangle()
.foregroundStyle(colorForNumber(id))
.opacity(0.4)
Text("Lorem Ipsum Dolor Sit Amet #\(id)")
.font(.largeTitle)
}
})
.buttonStyle(.bordered)
.matchedTransitionSource(id: id, in: customNamespace)
.matchedGeometryEffect(id: id, in: customNamespace)
}
}
}
.padding(.horizontal)
}
.navigationDestination(item: $presentingItemID) { id in
#if os(iOS)
// If we put the inspector outside of a NavigationStack.
// The ScrollView works well, but the animation
// here becomes bad.
EventDetailView(id: id)
.navigationTransition(.zoom(sourceID: id, in: customNamespace))
#else
EventDetailView(id: id)
#endif
}
}
.onDisappear {
showInspector = false
}
.searchable(text: $searchedText, prompt: "This Search Does Nothing")
.navigationTitle("Event")
.navigationSubtitle("Subtitle")
.toolbar {
ToolbarItem {
Button(action: {
showInspector = true
}, label: {
Image(systemName: "sidebar.trailing")
})
}
}
.inspector(isPresented: $showInspector) {
InspectorView()
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
.presentationBackgroundInteraction(.enabled)
}
}
}
struct EventDetailView: View {
var id: Int
var body: some View {
ZStack {
// Demonstation Purpose Only. The image can be removed.
Image("Demo-picture")
.resizable()
.scaledToFill()
.opacity(0.4)
Text("Item Detail #\(id)")
.font(.largeTitle)
}
}
}
struct InspectorView: View {
var body: some View {
Form {
Section(content: {
// Inspector items don't have matching relationship with the items in the `LazyVStack`. `1...50` is for demonstation purpose only.
ForEach(1...50, id: \.self) { id in
Text("Item #\(id)")
.font(.largeTitle)
}
})
}
}
}
https://github.com/threemanager785/inspetor-issue написанного/> Мы попробовали много подходов, но не смогли его разрешить. Есть ли способ решить эту проблему?
Подробнее здесь: https://stackoverflow.com/questions/797 ... ion-issues
Мобильная версия