Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions Sources/AsyncLoad/AsyncLoad/AsyncLoadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ public struct AsyncLoadView<
errorContent = error
}

public init(_ state: AsyncLoad<Item>, @ViewBuilder content: @escaping (Item?) -> Content)
where ErrorContent == Text {
public init(
_ state: AsyncLoad<Item>,
@ViewBuilder content: @escaping (Item) -> Content
) where ErrorContent == Text {
self.state = state
self.content = content

Expand All @@ -46,6 +48,7 @@ public struct AsyncLoadView<
case .loading, .none:
ProgressView()
.frame(maxHeight: .infinity)
.controlSize(.large)
case .loaded:
EmptyView()
case let .error(error):
Expand All @@ -54,4 +57,16 @@ public struct AsyncLoadView<
}
}
}

@available(iOS 17.0, macOS 14.0, watchOS 10.0, *)
#Preview {
@State
@Previewable
var state: AsyncLoad<String> = .loading

AsyncLoadView(state) { test in
Text(test)
}
}

#endif
6 changes: 5 additions & 1 deletion Sources/AsyncLoad/CachedAsyncLoad/CachedAsyncLoad.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public enum CachedAsyncLoad<T: Sendable>: Equatable, Sendable {
switch self {
case let .loaded(item):
item
default:
case let .error(item, _):
item
case let .loading(item):
item
case .none:
nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fileprivate enum CustomError: Error {

ProgressView()
.frame(maxWidth: .infinity)
.controlSize(.large)
}
.padding()
} error: { item, error in
Expand Down