Reload the List with updated data from API | SwiftUI Crypto App #16
pullToRefresh
구현VStack {
homeHeader
HomeStatsView(showPortfolio: $showPortfolio)
SearchBarView(searchText: $viewModel.searchText)
columnTitles
if !showPortfolio {
allCoinsList
.transition(.move(edge: .leading))
}
if showPortfolio {
portfolioCoinsList
.transition(.move(edge: .trailing))
}
Spacer(minLength: 0)
}
.refreshable {
viewModel.reloadData()
}
refreshable
메소드를 통해 손쉽게 pullToRefresh
가능 Button {
withAnimation(.linear(duration: 2.0)) {
viewModel.reloadData()
}
} label: {
Image(systemName: "goforward")
}
.rotationEffect(Angle(degrees: viewModel.isLoading ? 360 : 0), anchor: .center)
isLoading
변수를 통해 UI 효과func reloadData() {
isLoading = true
coinDataService
.fetchCoins()
marketDataService
.fetchData()
HapticManager.notification(type: .success)
}