Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
56 lines
1.9 KiB
Swift
Executable File
56 lines
1.9 KiB
Swift
Executable File
// InfiniteScrollFooter — the "load the next page when you reach the bottom"
|
|
// sentinel for the paginated list views (Likes, History, Following, My Tracks,
|
|
// Playlists, Artist panes). Place it as the LAST child of a lazy container
|
|
// (ScrollView { LazyVStack { … } }); because the stack is lazy, the footer is
|
|
// only built when it scrolls near the viewport, so its onAppear is the "reached
|
|
// the bottom" signal. It calls loadMore(), which the view guards against
|
|
// re-entrancy and only runs while there is a next page.
|
|
//
|
|
// One implementation serves iOS and macOS — it is shared CrossSoundKit UI, so
|
|
// "the same on both" is automatic.
|
|
|
|
import Inject
|
|
import RedWhiteUI
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
public struct InfiniteScrollFooter: View {
|
|
@Environment(\.rw) private var p
|
|
|
|
/// True while the API reports another page (next_href present).
|
|
let hasMore: Bool
|
|
/// True while a page fetch is in flight — drives the spinner.
|
|
let isLoading: Bool
|
|
/// Fetch + append the next page. The view must no-op if already loading or
|
|
/// exhausted (this fires on every appearance of the footer).
|
|
let loadMore: () async -> Void
|
|
|
|
public init(hasMore: Bool, isLoading: Bool, loadMore: @escaping () async -> Void) {
|
|
self.hasMore = hasMore
|
|
self.isLoading = isLoading
|
|
self.loadMore = loadMore
|
|
}
|
|
|
|
@ObserveInjection var inject
|
|
|
|
public var body: some View {
|
|
Group {
|
|
// Nothing to show once the list is fully walked — the footer vanishes, so
|
|
// the list simply ends (what "scroll until there's no more" should feel like).
|
|
if hasMore {
|
|
HStack {
|
|
Spacer()
|
|
ProgressView()
|
|
.controlSize(.small)
|
|
.opacity(isLoading ? 1 : 0.35)
|
|
Spacer()
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding(.vertical, 18)
|
|
.onAppear { Task { await loadMore() } }
|
|
}
|
|
}
|
|
.enableInjection()
|
|
}
|
|
}
|