I’ve created PopupView like this:
import SwiftUI
struct PopupView<Content material>: View the place Content material: View {
@Binding var isPresented: Bool
@Binding var viewForPresentation: Content material
var content material: () -> Content material
var physique: some View {
ZStack(alignment: .backside) {
content material()
.blur(radius: isPresented ? 3 : 0)
.disabled(isPresented)
HStack {
viewForPresentation
}
.opacity(isPresented ? 1 : 0)
}
}
}
Now I want to use it inside one other view the next means:
struct ServiceEditView: View {
@State var isPopupPresented: Bool
@State var viewForPopupPresentation: any View
personal var firstView: some View {
Button {
isPopupPresented = false
} label: {
Textual content("First View")
}
}
personal var secondView: some View {
Button {
isPopupPresented = false
} label: {
Textual content("Second View")
}
}
var physique: some View {
PopupView(isPresented: $isPopupPresented, viewForPresentation: $viewForPopupPresentation) {
// ❌ Kind 'any View' can't conform to 'View'
HStack {
Button {
viewForPopupPresentation = firstView
isPopupPresented = true
} label: {
Textual content("1st")
}
Button {
viewForPopupPresentation = secondView
isPopupPresented = true
} label: {
Textual content("2nd")
}
}
}
}
}
Is it doable in any respect to current one other View utilizing Binding to property of View Kind?
I want to use the identical one single mechanizm to current totally different view relying on the place it comes from.