divadretlaw/CustomAlert

Cannot auto alert when isPresented init true

Closed this issue · 1 comments

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")
}
}

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