Last active
June 22, 2023 02:42
-
-
Save YusukeHosonuma/5634e5b6ea255775a9507c3be64df646 to your computer and use it in GitHub Desktop.
[SwiftUI] PureList
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
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)) | |
} | |
} |
Author
YusukeHosonuma
commented
Dec 23, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment