Skip to content

Instantly share code, notes, and snippets.

@YusukeHosonuma
Last active June 22, 2023 02:42
Show Gist options
  • Save YusukeHosonuma/5634e5b6ea255775a9507c3be64df646 to your computer and use it in GitHub Desktop.
Save YusukeHosonuma/5634e5b6ea255775a9507c3be64df646 to your computer and use it in GitHub Desktop.
[SwiftUI] PureList
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
PureList {
Text("Apple")
.border(.red)
Color.clear
.frame(height: 0)
Text("Orange")
.border(.blue)
Spacer()
.frame(height: 0)
Text("Banana")
.border(.green)
}
}
}
}
struct PureList<Content: View>: View {
@ViewBuilder var content: () -> Content
var body: some View {
List {
content()
.listRowSeparator(.hidden)
.listRowInsets(EdgeInsets())
}
.listStyle(.plain)
.listMinRowHeight(0)
}
}
extension View {
func listMinRowHeight(_ height: CGFloat) -> some View {
environment(\.defaultMinListRowHeight, height)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.padding()
.previewLayout(.fixed(width: 100, height: 100))
}
}
@YusukeHosonuma
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment