ListPagination icon indicating copy to clipboard operation
ListPagination copied to clipboard

Example and readMe is not clear!

Open Dave181295 opened this issue 2 years ago • 0 comments

Please make a better example, things are not clear, you init the array first with populated data, then you append it with the fetched one from an API, the first part is not possible, do I need to fetch all the data first? because when trying your code with an empty array (first time its empty) , nothing happens, as the condition isLast in the func listItemAppears is not reached .

     @State  var historyMessages = [Message]()
     @State var isFetching = false
    @State private var page: Int = 0
    private let pageSize: Int = 25

 //Arr is empty here , condition wont met
        if historyMessages.isLastItem(item) {
            self.page += 1
            self.getMoreItems(forPage: self.page, pageSize: self.pageSize) { moreItems  in
            
                historyMessages.append(contentsOf: moreItems)
                
                isFetching = false
                
            }
            
            
        }

    func getMoreItems(
        forPage page: Int,
        pageSize: Int, completion: @escaping ([Message]) -> () )  {
            
            
            let maximum = ((page * pageSize) + pageSize) - 1
            
            let maxCount =  historyMessages.count - maximum
            
            phrasesModel.dbManager.retrieveAllMessage { messages  in
                
                guard let  fetchedMessages = messages else {
                    return
                }
                
                var copyArr = fetchedMessages
                
                for i in historyMessages.count...maxCount {
                    copyArr.remove(at: i)
                }
                
                completion(copyArr)
                
            }
            
        }

Dave181295 avatar May 06 '22 14:05 Dave181295