The popup works. But when it pops up, it increases the parent view width and height as well (parent is smaller than pop-up and it's a requirement that parent to be smaller than pop-up). I want the popup to be an independent view. The popup should not affect the size of the parent. How to do that?
import SwiftUI
struct ParentView: View {
@State private var WidgetSelectionShowState: Bool = false
var body: some View {
//Color.purple
ZStack {
Rectangle ()
.fill(.blue)
.zIndex(0) //
Button ("show", action: {
withAnimation {
WidgetSelectionShowState.toggle()
}
})
if (WidgetSelectionShowState) {
popupPage ()
}
} .frame(width: 300, height: 100, alignment: .center)
}
}
struct popupPage: View {
var body: some View {
ZStack {
Text("This is a popup")
Rectangle ()
.fill(.green)
.zIndex(0) //this is the layer order.
}.transition(.asymmetric(insertion: .scale, removal: .opacity))
. frame(width: 200, height: 500, alignment: .center )
}
}