Created
July 8, 2021 14:51
-
-
Save Toni77777/e8c8db9d6f2ee123d5d55fa5f5be2c7e 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 EmptyList<Items: RandomAccessCollection, ListRowView: View, PlaceholderView: View>: View where Items.Element: Identifiable { | |
private let items: Items | |
private let listRowView: (Items.Element) -> ListRowView | |
private let placeholderView: () -> PlaceholderView | |
/// - Parameters: | |
/// - items: Source data for List. Item must implement Identifiable protocol | |
/// - listRowView: View displayed for each source Item | |
/// - placeholderView: Placeholder. View displayed when the items collection isEmpty | |
init(_ items: Items, | |
@ViewBuilder listRowView: @escaping (Items.Element) -> ListRowView, | |
@ViewBuilder placeholderView: @escaping () -> PlaceholderView) { | |
self.items = items | |
self.listRowView = listRowView | |
self.placeholderView = placeholderView | |
} | |
var body: some View { | |
if !items.isEmpty { | |
List { // List countires | |
ForEach(items) { item in | |
self.listRowView(item) | |
} | |
} | |
} else { | |
placeholderView() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment