[ad_1]
I’ve created a customized popup to make use of everywhere in the app which works wonderful nevertheless it does not cowl full view so I up to date my code to assist fullscreencover. The complete display screen works nevertheless it does not dismiss. Unsure what I am doing flawed right here. Beneath is my code
MyCustomPopup.swift
enum PopupType {
case type1
case none
}
struct MyPopup<Content material>: View the place Content material: View {
@SwiftUI.Surroundings(.presentationMode) var presentation
@ViewBuilder let content material: () -> Content material
@Binding var isPresented: Bool
var title: String
var description: String?
var kind: PopupType
var physique: some View {
content material()
.overlay(isPresented ? popupView : nil)
}
@ViewBuilder
var popupView: some View {
swap kind {
case .type1:
popupView1
case .none:
EmptyView()
}
}
@ViewBuilder
var popupView1: some View {
VStack {
//some code for popup design with title and outline
//Popup dismiss button
Button {
isPresented = false
self.presentation.wrappedValue.dismiss()
} label: {
Textual content("Dismiss")
}
}
}
}
extension View {
func myPopupView(isPresented: Binding<Bool>, popuptypes: PopupType, title: String = "", description: String? = nil) -> some View {
return self.fullScreenCover(isPresented: isPresented, onDismiss: nil) {
MyPopup(content material: { self }, isPresented: isPresented, title: title, description: description, kind: popuptypes)
.animation(.easeOut)
}
// Earlier I used to immediately return Mypopup(..) and the dismiss use to work
}
}
//Most important View
struct MainView: View {
@State var viewState: ViewState = .preliminary
var physique: some View {
VStack {
//Code for major view
}
.myPopupView(isPresented: viewState == .loading ? .fixed(true) : .fixed(false), popuptypes: .type1, title: "Popup Title", description: "Popup description")
}
}
Any assistance is appreciated
[ad_2]
