Closed swanfly closed 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") } }
Thank you for opening an issue. The alert should now appear when isPresented is initially true
isPresented
true
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") } }