I'm developing in iOS version 16.0 and I have an issue with refreshing scrollview within SwiftUI. I want to refresh and reload data for ScrollView from CoreData, and the ScrollView Code is written like this.
ScrollView {
Spacer()
.frame(height: 50)
ForEach(viewModel.insightList, id: \.self) { insightData in
InsightListCardView(viewModel: InsightListCardViewModel(insight: insightData))
}
}
.refreshable {
viewModel.getInsightList()
}
And the function getInsightList()
is calling only one function, which is below.
func getAllInsights() -> [InsightData] {
let fetchRequest: NSFetchRequest<InsightData> = InsightData.fetchRequest()
let result = try? context.fetch(fetchRequest)
return result?.reversed() ?? []
}
And the problem is here. When I try to refresh the scrollview with pulling, the content of scrollview is moving down. The start position of scroll Indicator is also moving down, but not the entire scrollview height is decreased, so scrolling up is available.
The strange part is here. When I check the view hierarchy, only the screen is moved and the actual components are stay in the appropriate position. Buttons work not when I click the position on the screen, but when I click the original position.