Created
May 10, 2024 15:54
-
-
Save khanlou/589a52fd7019c081bb311c6bd8e30a6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PaginationModifier: ViewModifier { | |
let metadata: PaginationMetadata? | |
let onBottom: () -> Void | |
func body(content: Content) -> some View { | |
content | |
if let metadata, !metadata.isAtEnd, metadata.items != 0 { | |
VStack { | |
Text("Page \(metadata.page) of \(metadata.pages).") | |
Text("\(metadata.items) total items.") | |
ProgressView() | |
} | |
.onAppear(perform: { onBottom() }) | |
.font(.caption) | |
} | |
} | |
} | |
extension View { | |
func paginate(pagination: PaginationMetadata?, _ perform: @escaping () -> Void) -> some View { | |
self.modifier(PaginationModifier(metadata: pagination, onBottom: perform)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment