Created
April 28, 2023 15:20
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
// TODO docs | |
public typealias SubviewProxy = _VariadicView.Children | |
// TODO docs | |
public struct SubviewReader<Children, Content>: View where Children: View, Content: View { | |
var children: Children | |
var content: (SubviewProxy) -> Content | |
// TODO docs | |
public init(_ children: Children, @ViewBuilder content: @escaping (SubviewProxy) -> Content) { | |
self.children = children | |
self.content = content | |
} | |
public var body: some View { | |
_VariadicView.Tree(Layout(content: content)) { | |
children | |
} | |
} | |
struct Layout: _VariadicView.MultiViewRoot { | |
var content: (SubviewProxy) -> Content | |
func body(children: SubviewProxy) -> Content { | |
content(children) | |
} | |
} | |
} | |
public struct Divided<Content>: View where Content: View { | |
var content: Content | |
public init(@ViewBuilder content: () -> Content) { | |
self.content = content() | |
} | |
public var body: some View { | |
SubviewReader(content) { children in | |
ForEach(children) { view in | |
view | |
if view.id != children.last?.id { | |
Divider() | |
} | |
} | |
} | |
} | |
} | |
struct Divided_Previews: PreviewProvider { | |
static var previews: some View { | |
VStack(alignment: .leading) { | |
Divided { | |
Text("Milk") | |
Text("Eggs") | |
Text("Cheese") | |
} | |
} | |
.padding() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment