divadretlaw / CustomAlert

🔔 Custom Alert for SwiftUI
MIT License
190 stars 18 forks source link

Cannot auto alert when isPresented init true #1

Closed swanfly closed 2 years ago

swanfly commented 2 years ago

Use SwiftUI API can auto alert when page first loaded, but your code cannot.

SwiftUI API code: @State private var showAlert = true VStack(spacing: 0) { Text("首次启动弹出弹窗") } .alert("title", isPresented: $showAlert, actions: { Button("取消", role: .cancel, action: {}) }, message: { Text("Message") })

Your code: @State private var showAlert = true VStack(spacing: 0) { Text("首次启动弹出弹窗") } .customAlert("Some Fancy Alert", isPresented: $showAlert) { Text("I'm a custom Message") .font(.custom("Noteworthy", size: 24)) Image(systemName: "swift") .resizable() .scaledToFit() .frame(maxHeight: 100) .foregroundColor(.blue) } actions: { Button { // some Action } label: { Label("Swift", systemImage: "swift") } Button(role: .cancel) { // some Action } label: { Text("Cancel") } }

divadretlaw commented 2 years ago

Thank you for opening an issue. The alert should now appear when isPresented is initially true