I have a view FooView in a navigation stack presented via a NavigationLink.
Now FooView has a button that will trigger a ActionSheet:
struct FooView: View {
@State private var showActions = false
var body: some View {
<snip>
Button(action: {
showActions = true
}) {
Image(systemName: "arrow.up.circle")
}
.actionSheet(isPresented: $showActions) {
ActionSheet(title: Text("Actions"),
message: nil,
buttons: [
.default(Text("Option 1")) {
// TODO
},
.default(Text("Option 2")) {
// TODO
},
.cancel()
])
}
The problem is: when the ActionSheet is dismissed (either cancelled or selected option), its parent view, i.e. FooView is also dismissed, i.e. pops up from the navigation stack.
Is there a way to prevent it doing that?
More importantly, why is this happening? What triggers FooView going away?
iOS version: iOS 15 on iPhone
XCode: 14.2




