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
14 changes: 7 additions & 7 deletions Sources/AdvancedList/public/Views/AdvancedList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct AdvancedList<Data: RandomAccessCollection, ListView: View, Content
private var data: Data
private var listView: ((Rows) -> ListView)?
private var content: (Data.Element) -> Content
private var listState: Binding<ListState>
private let listState: ListState
private let emptyStateView: () -> EmptyStateView
private let errorStateView: (Error) -> ErrorStateView
private let loadingStateView: () -> LoadingStateView
Expand All @@ -37,11 +37,11 @@ public struct AdvancedList<Data: RandomAccessCollection, ListView: View, Content
/// - data: The data for populating the list.
/// - listView: A view builder that creates a custom list view from the given type erased dynamic view content representing the rows of the list.
/// - content: A view builder that creates the view for a single row of the list.
/// - listState: A binding to a property that determines the state of the list.
/// - listState: A value representing the state of the list.
/// - emptyStateView: A view builder that creates the view for the empty state of the list.
/// - errorStateView: A view builder that creates the view for the error state of the list.
/// - loadingStateView: A view builder that creates the view for the loading state of the list.
public init(_ data: Data, @ViewBuilder listView: @escaping (Rows) -> ListView, @ViewBuilder content: @escaping (Data.Element) -> Content, listState: Binding<ListState>, @ViewBuilder emptyStateView: @escaping () -> EmptyStateView, @ViewBuilder errorStateView: @escaping (Error) -> ErrorStateView, @ViewBuilder loadingStateView: @escaping () -> LoadingStateView) {
public init(_ data: Data, @ViewBuilder listView: @escaping (Rows) -> ListView, @ViewBuilder content: @escaping (Data.Element) -> Content, listState: ListState, @ViewBuilder emptyStateView: @escaping () -> EmptyStateView, @ViewBuilder errorStateView: @escaping (Error) -> ErrorStateView, @ViewBuilder loadingStateView: @escaping () -> LoadingStateView) {
self.data = data
self.listView = listView
self.content = content
Expand All @@ -60,11 +60,11 @@ extension AdvancedList where ListView == List<Never, AnyDynamicViewContent> {
/// - Parameters:
/// - data: The data for populating the list.
/// - content: A view builder that creates the view for a single row of the list.
/// - listState: A binding to a property that determines the state of the list.
/// - listState: A value representing the state of the list.
/// - emptyStateView: A view builder that creates the view for the empty state of the list.
/// - errorStateView: A view builder that creates the view for the error state of the list.
/// - loadingStateView: A view builder that creates the view for the loading state of the list.
public init(_ data: Data, @ViewBuilder content: @escaping (Data.Element) -> Content, listState: Binding<ListState>, @ViewBuilder emptyStateView: @escaping () -> EmptyStateView, @ViewBuilder errorStateView: @escaping (Error) -> ErrorStateView, @ViewBuilder loadingStateView: @escaping () -> LoadingStateView) {
public init(_ data: Data, @ViewBuilder content: @escaping (Data.Element) -> Content, listState: ListState, @ViewBuilder emptyStateView: @escaping () -> EmptyStateView, @ViewBuilder errorStateView: @escaping (Error) -> ErrorStateView, @ViewBuilder loadingStateView: @escaping () -> LoadingStateView) {
self.data = data
self.content = content
self.listState = listState
Expand All @@ -78,7 +78,7 @@ extension AdvancedList where ListView == List<Never, AnyDynamicViewContent> {

extension AdvancedList {
@ViewBuilder public var body: some View {
switch listState.wrappedValue {
switch listState {
case .items:
if !data.isEmpty {
VStack {
Expand Down Expand Up @@ -201,7 +201,7 @@ struct AdvancedList_Previews : PreviewProvider {
NavigationView {
AdvancedList(items, content: { element in
Text(element.id)
}, listState: $listState, emptyStateView: {
}, listState: listState, emptyStateView: {
Text("No data")
}, errorStateView: { error in
VStack {
Expand Down
8 changes: 4 additions & 4 deletions Tests/AdvancedListTests/AdvancedListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class AdvancedListTests: XCTestCase {
private lazy var loadingStateView = Text(loadingStateString)

func testEmptyStateView() {
let emptyListState: Binding<ListState> = .constant(.items)
let emptyListState: ListState = .items

let items: [String] = []

Expand All @@ -41,7 +41,7 @@ final class AdvancedListTests: XCTestCase {
}

func testNotEmptyStateView() {
let itemsListState: Binding<ListState> = .constant(.items)
let itemsListState: ListState = .items

let mockItem1 = "MockItem1"
let mockItem2 = "MockItem2"
Expand Down Expand Up @@ -73,7 +73,7 @@ final class AdvancedListTests: XCTestCase {
}

func testLoadingStateView() {
let loadingListState: Binding<ListState> = .constant(.loading)
let loadingListState: ListState = .loading

let items: [String] = []

Expand All @@ -97,7 +97,7 @@ final class AdvancedListTests: XCTestCase {

func testErrorStateView() {
let error = NSError(domain: "MockDomain", code: 1, userInfo: nil)
let errorListState: Binding<ListState> = .constant(.error(error))
let errorListState: ListState = .error(error)

let items: [String] = []

Expand Down