Implementing infinite scrolling with async await
Infinite scrolling is a technique that loads data when the scrolling reaches the end of the List
view. It is particularly useful when the list is backed by a paginated resource.
In this recipe, we'll use a remote API that returns paginated results. Every time the user scrolls to the end of the list, we load the next page, until we have loaded all the data.
For this recipe, we will use a pretty famous service for searching animated gifs called Giphy (https://giphy.com). Giphy provides a powerful API (https://developers.giphy.com), which we'll use to search and fetch a few animated gifs to present in a SwiftUI view.
Getting ready
Create an iOS 15 SwiftUI project called CoolGifList
.
Since the AsyncImage
SwiftUI component doesn't support animated gifs, we will use an external package called NukeUI. You can add it via SPM to the project with the following address (https://github.com/kean/NukeUI):