'How to manage custom pop up not native alert popup in swiftUI?
there !
I'm now creating custom pop up in swiftUI using ViewModifer like below:
struct Popup<T: View>: ViewModifier {
let popup: T
let isPresented: Bool
init(isPresented: Bool, @ViewBuilder content: () -> T) {
self.isPresented = isPresented
popup = content()
}
func body(content: Content) -> some View {
content
.overlay(popupContent())
}
@ViewBuilder private func popupContent() -> some View {
GeometryReader { geometry in
if isPresented {
popup
.onAppear(perform: {
FeedbackGenerator.shared.select()
})
.frame(width: geometry.size.width, height: geometry.size.height)
.transition(.opacity.animation(.easeOut(duration:0.2)))
}
}
}
}
But this ViewModifer based custom pop up is just presented on some view(page view) not on screen. Also it can't prevent user's back swipe motion(because pop up just overlay on the page view)
So, I want to create own custom pop up which operates like native alert popup below:
var body: some View {
Button(action: {
self.showingAlert = true
}) {
Text("Show Alert")
}
.alert(isPresented: $showingAlert) {
Alert(title: Text("Title"), message: Text("This is a alert message"), dismissButton: .default(Text("Dismiss")))
}
}
This native alert pop up present on topmost popup and presents on the different layer that it prevents user's back swipe which i want.
So... How do you solve this situation? How to present custom pop up like native alert?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
