Reputation: 1
I am using down code for a custom alert, the codes works fine without ScrollView, as long as you use ScrollView in your codes the codes get mixed up and corrupted. the issue is like this with scrollView, it will corrupt the code, without it works fine! how I could solve this strange issue?
the way of code is like this with tap on info button, all screen get blurred out and disabled and custom alert will appear. it works as expected without having ScrollView!
struct ContentView: View {
@State var showCustomAlertView: Bool = Bool()
var body: some View {
ZStack {
VStack {
HStack {
Button(action: {
withAnimation(.easeInOut(duration: 0.35)) { showCustomAlertView.toggle() }
print("info")
}) { Image(systemName: "info.circle") }
Spacer()
}.padding()
Spacer()
if showCustomAlertView { CustomAlertView(showCustomAlertView: $showCustomAlertView); Spacer() }
}
VStack {
VStack { Button("toggle Button1") {
print("toggle Button1")
}.foregroundColor(Color.white).padding(.horizontal,25).padding(.vertical,5).background(Color.blue).cornerRadius(10) }
//ScrollView (showsIndicators: true) {
VStack(spacing: 10) {
Text("Some text here ..." )
Text("Some text here ..." )
Text("Some text here ..." )
Text("Some text here ..." )
}
//}
VStack { Button("toggle Button2") {
print("toggle Button2")
}.foregroundColor(Color.white).padding(.horizontal,25).padding(.vertical,5).background(Color.blue).cornerRadius(10) }
}.blur(radius: showCustomAlertView ? 3 : 0).disabled(showCustomAlertView)
}
}
}
struct CustomAlertView: View {
@Binding var showCustomAlertView: Bool
var body: some View {
VStack { Text("CustomAlertView").bold().padding(); Button("dismiss") { print("dismiss");showCustomAlertView.toggle() } }
}
}
Upvotes: 1
Views: 52
Reputation: 257729
Make view with alert above all others, like (tested with Xcode 12.1 / iOS 14.1)
ZStack {
VStack {
HStack {
Button(action: {
withAnimation(.easeInOut(duration: 0.35)) { showCustomAlertView.toggle() }
print("info")
}) { Image(systemName: "info.circle") }
Spacer()
}.padding()
Spacer()
if showCustomAlertView { CustomAlertView(showCustomAlertView: $showCustomAlertView); Spacer() }
}.zIndex(1) // << here !!
Upvotes: 1