As custom Popup view is showing perfectly But navigation view back button is also enable while showing popup view. So, Is it possible to show custom popup view on top of view hierarchy like we normally do in swift like this
guard let window : UIWindow = UIApplication.shared.windows.filter({$0.isKeyWindow}).first else {return}
var presentVC = window.rootViewController
while let next = presentVC?.presentedViewController {
presentVC = next
}
Source Code:
struct LogInView: View {
@State private var email: String = ""
@State private var isShowPopup: Bool = false
@Binding var showSelfView: Bool
var body: some View {
ZStack {
VStack(alignment: .leading, spacing: 30) {
// Top
VStack(alignment: .leading, spacing: 10) {
Text("Login")
.font(.title).bold()
.foregroundColor(Design.Theme.PrimaryTextColor)
Text("Please enter your password to log in to your VaultsPay account")
.font(.headline)
.fontWeight(.regular)
.foregroundColor(Design.Theme.SecondaryTextColor)
}
// TextFields
VStack(spacing: 15) {
TextField("Email", text: $email)
.keyboardType(.emailAddress)
.textFieldStyle(.plain)
.padding(.horizontal, 12)
.frame(height: 55)
.background(
Design.Theme.TextFieldBackgroundColor.cornerRadius(15)
)
TextField("Password", text: $email)
.keyboardType(.emailAddress)
.textFieldStyle(.plain)
.frame(height: 55)
.padding(.horizontal, 12)
.background(
Design.Theme.TextFieldBackgroundColor.cornerRadius(15)
)
}
Button(action: {
withAnimation {
self.isShowPopup.toggle()
}
}) {
Text("Login")
.font(.title3).bold()
.foregroundColor(Design.Theme.WhiteTextColor)
.frame(height: 55)
.frame(maxWidth: .infinity)
.background(Design.Theme.SecondaryBackgroundColor)
.cornerRadius(15)
.opacity(0.4)
}
HStack(alignment: .center) {
Button(action: {
self.showSelfView = false
}) {
Text("Forgot Password?")
.font(.headline).bold()
.foregroundColor(Design.Theme.TertiaryTextColor)
.frame(width: 200, height: 25)
}
.frame(maxWidth: .infinity)
}
Spacer()
} //: Main VSTACK
.padding(.horizontal)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
Image(Design.Icon.AppLogo)
.scaledToFit()
}
}
if self.isShowPopup {
GeometryReader { _ in
ConfirmationDialog()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal, 35)
}
.background(
Color.black.opacity(0.65)
.edgesIgnoringSafeArea(.all)
.onTapGesture {
withAnimation {
self.isShowPopup.toggle()
}
}
)
}
}
}
Source code to handle custom Popup view:
if self.isShowPopup {
GeometryReader { _ in
ConfirmationDialog()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal, 35)
}
.background(
Color.black.opacity(0.65)
.edgesIgnoringSafeArea(.all)
.onTapGesture {
withAnimation {
self.isShowPopup.toggle()
}
}
)
}
Problem Screenshot:
Thanks in advance. Looking forward to your help.
CodePudding user response:
At the bottom of the VStack
, add the modifier .navigationBarBackButtonHidden()
.
...
} //: Main VSTACK
.padding(.horizontal)
.navigationBarBackButtonHidden(isShowPopup) // <- Here
.navigationBarTitleDisplayMode(.inline)
.toolbar {
...