Skip to content

Instantly share code, notes, and snippets.

@dfeinzimer
Last active January 11, 2023 02:09
Show Gist options
  • Save dfeinzimer/264740f19c216a68b64ebe4180cbc675 to your computer and use it in GitHub Desktop.
Save dfeinzimer/264740f19c216a68b64ebe4180cbc675 to your computer and use it in GitHub Desktop.
SwiftUI LibraryItem bug reproducer
//
// ContentView.swift
//
// Created by David Feinzimer on 1/10/23.
//
import SwiftUI
struct ContentView: View {
var body: some View {
MyView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct MyView: View {
var action: (() -> Void)?
var body: some View {
Text("MyView")
.onTapGesture {
action?()
}
}
func setAction(_ action: @escaping () -> Void) -> MyView {
var copy = self
copy.action = action
return copy
}
}
struct LibraryContent: LibraryContentProvider {
func modifiers(base: MyView) -> [LibraryItem] {
[
LibraryItem(
base.setAction {
},
title: "MyView - Set action"
)
]
}
}
@dfeinzimer
Copy link
Author

FB11936092

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