Learn how to present sheets, alerts, and confirmation dialogs using the Navigator
.
navigator.sheet(
content: {
// Sheet content
SheetView()
},
onDismiss: {
// Optional dismissal action
}
)
navigator.sheet(
content: {
VStack {
Text("Sheet Content")
Button(
action: {
navigator.dismiss()
},
label: {
Text("Close")
}
)
}
}
)
navigator.alert(
title: "Alert Title",
message: {
// Alert message view
Text("This is an alert.")
},
actions: {
// Alert actions
NavigatorButton("OK") { $0.dismiss() }
}
)
navigator.alert(
title: "Network Error",
message: {
Text("Unable to connect to the server.")
},
actions: {
NavigatorButton("Retry") {
// Retry action
$0.dismiss()
}
NavigatorButton("Cancel") { $0.dismiss() }
}
)
navigator.confirmDialog(
title: "Confirm Action",
message: {
// Dialog message view
Text("Are you sure you want to proceed?")
},
actions: {
// Dialog actions
NavigatorButton("Yes") { $0.dismiss() }
NavigatorButton("No") { $0.dismiss() }
}
)
navigator.confirmDialog(
title: "Delete Item",
message: {
Text("Are you sure you want to delete this item?")
},
actions: {
NavigatorButton("Delete") {
// Delete action
$0.dismiss()
}
NavigatorButton("Cancel") { $0.dismiss() }
}
)
Use navigator.dismiss()
to close the current modal or alert.
Button(
action: {
navigator.dismiss()
},
label: {
Text("Dismiss")
}
)
Learn how to implement various navigation techniques to enhance your application's user experience.