gontovnik/DGElasticPullToRefresh

The elastic effect getting stuck with a whole or half loading circle when async data.

aloveric opened this issue · 2 comments

I have users reporting this behavior, too. Not sure how to replicate it.

had this bug as well.
You need to separate the API async stuff from the main thread (UI) one

func setupPullToRefresh() {
        let loadingView = DGElasticPullToRefreshLoadingViewCircle()
        loadingView.tintColor = .coralPink
        tableView.dg_addPullToRefreshWithActionHandler({ [weak self] () -> Void in
            guard let self = self else { return }
            self.viewModel.isRefreshing = true
            Task {
                do {
                    try await self.refreshData()
                    self.viewModel.isRefreshing = false
                    DispatchQueue.main.async {
                        self.tableView.dg_stopLoading()
                        self.tableView.reloadData()
                        self.updateUI()
                    }
                } catch {
                    self.tableView.dg_stopLoading()
                    print("error : \(error)")
                    self.viewModel.isRefreshing = false
                }
            }
            
        }, loadingView: loadingView)
        tableView.dg_setPullToRefreshFillColor(AppColor.whiteThree)
        tableView.dg_setPullToRefreshBackgroundColor(tableView.backgroundColor ?? .white)
    }
    
    private func refreshData() async throws {
        try await viewModel.loadUserEvent()
        try await viewModel.fetchDesigns()
        try await viewModel.fetchWinners()
    }