Skip to content

Commit

Permalink
0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
nathantannar4 committed Mar 27, 2023
1 parent 5ddeaac commit 5ba91e4
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 44 deletions.
15 changes: 8 additions & 7 deletions Example/Example/VariadicViewExamples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ struct BulletList<Content: View>: View {
@ViewBuilder var content: Content

var body: some View {
VariadicViewAdapter { content in
VariadicViewAdapter {
content
} content: { source in
ForEachSubview(content) { index, subview in
HStack(alignment: .firstTextBaseline) {
Text("\(index + 1).")

subview
}
}
} source: {
content
}
}
}
Expand Down Expand Up @@ -59,9 +59,12 @@ struct PickerView<Selection: Hashable, Content: View>: View {
@ViewBuilder var content: Content

var body: some View {
VariadicViewAdapter { content in
ForEachSubview(content) { index, subview in
VariadicViewAdapter {
content
} content: { source in
ForEachSubview(source) { index, subview in
HStack {
// This works since the ForEach ID is the Fruit (ie Selection) type
let isSelected: Bool = selection == subview.id(as: Selection.self)
if isSelected {
Image(systemName: "checkmark")
Expand All @@ -74,8 +77,6 @@ struct PickerView<Selection: Hashable, Content: View>: View {
}
}
}
} source: {
content
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ public struct VariadicViewAdapter<Source: View, Content: View>: View {
@inlinable
public init(
@ViewBuilder content: @escaping (VariadicView<Source>) -> Content,
@ViewBuilder source: () -> Source
@ViewBuilder source: () -> Source,
@ViewBuilder content: @escaping (VariadicView<Source>) -> Content
)
}
```
Expand Down Expand Up @@ -247,8 +247,10 @@ struct PickerView<Selection: Hashable, Content: View>: View {
@ViewBuilder var content: Content
var body: some View {
VariadicViewAdapter { content in
ForEachSubview(content) { index, subview in
VariadicViewAdapter {
content
} content: { source in
ForEachSubview(source) { index, subview in
HStack {
// This works since the ForEach ID is the Fruit (ie Selection) type
let isSelected: Bool = selection == subview.id(as: Selection.self)
Expand All @@ -263,8 +265,6 @@ struct PickerView<Selection: Hashable, Content: View>: View {
}
}
}
} source: {
content
}
}
}
Expand Down
79 changes: 48 additions & 31 deletions Sources/Engine/Sources/VariadicView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,25 @@ public struct VariadicViewAdapter<Source: View, Content: View>: View {
@usableFromInline
var content: (VariadicView<Source>) -> Content

/*
FB12082130: Xcode 14.3 RC regression, type inference no longer works unless
the `Source` parameter is before the `content`
@inlinable
public init(
@ViewBuilder content: @escaping (VariadicView<Source>) -> Content,
@ViewBuilder source: () -> Source
) {
self.source = source()
self.content = content
}
*/

@inlinable
public init(@ViewBuilder content: @escaping (VariadicView<Source>) -> Content, @ViewBuilder source: () -> Source) {
public init(
@ViewBuilder source: () -> Source,
@ViewBuilder content: @escaping (VariadicView<Source>) -> Content
) {
self.source = source()
self.content = content
}
Expand Down Expand Up @@ -208,70 +225,70 @@ enum PreviewCases: Int, Hashable, CaseIterable {
struct VariadicView_Previews: PreviewProvider {
static var previews: some View {
Group {
VariadicViewAdapter { content in
VariadicViewAdapter {
Text("Line 1").id("1")
Text("Line 2").id("2")
} content: { source in
VStack {
ForEachSubview(content) { index, subview in
ForEachSubview(source) { index, subview in
Text(subview.id(as: String.self) ?? "nil")
}
}
} source: {
Text("Line 1").id("1")
Text("Line 2").id("2")
}

VariadicViewAdapter { content in
VariadicViewAdapter {
ForEach(PreviewCases.allCases, id: \.self) {
Text($0.rawValue.description)
}
} content: { source in
VStack {
ForEachSubview(content) { index, subview in
ForEachSubview(source) { index, subview in
Text("\(subview.id(as: PreviewCases.self)?.rawValue ?? -1)")

Text(String("\(subview.id)"))
}
}
} source: {
ForEach(PreviewCases.allCases, id: \.self) {
Text($0.rawValue.description)
}
}

if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
VariadicViewAdapter { content in
VariadicViewAdapter {
Text("Line 1").tag("1")
Text("Line 2").tag("2")
} content: { source in
VStack {
ForEachSubview(content) { index, subview in
ForEachSubview(source) { index, subview in
Text(subview.tag(as: String.self) ?? "nil")
}
}
} source: {
Text("Line 1").tag("1")
Text("Line 2").tag("2")
}
}

VariadicViewAdapter { content in
VStack {
content
}
} source: {
VariadicViewAdapter {
Text("Line 1")
Text("Line 2")
} content: { source in
VStack {
source
}
}

VariadicViewAdapter { content in
Text(content.children.count.description)
} source: {
VariadicViewAdapter {
EmptyView()
} content: { source in
Text(source.children.count.description)
}

VariadicViewAdapter { content in
Text(content.children.count.description)
} source: {
VariadicViewAdapter {
Text("Line 1")
} content: { source in
Text(source.children.count.description)
}

VariadicViewAdapter { content in
Text(content.children.count.description)
} source: {
VariadicViewAdapter {
Text("Line 1")
Text("Line 2")
} content: { source in
Text(source.children.count.description)
}
}
.padding()
Expand Down

0 comments on commit 5ba91e4

Please sign in to comment.