Reputation: 569
I have an ActionSheet and I don't know how to make navigation to another view from the action sheet callback button.
let action = ActionSheet.Button.cancel {
//navigation???
}
ActionSheet(title: Text("some title"), buttons: [action])
I.E: I would like to have this as a chooser when selecting images from different sources: camera or camera roll.
Upvotes: 3
Views: 1515
Reputation: 1443
This is how you can achieve this:
struct ContentView: View {
@State var isSheet: Bool = false
@State var isPresented: Bool = false
var body: some View {
NavigationView {
Button(dict.description) {
self.isSheet = true
}.actionSheet(isPresented: $isSheet) {
ActionSheet(title: Text("Some title"), message: nil, buttons: [
.default(Text("Present view")) {
self.isPresented = true
},
.cancel()
])
}
.navigationBarTitle(Text("Home"))
.sheet(isPresented: $isPresented, content: { Text("This is another view!") })
}
}
}
Instead of .sheet
, you can also use .popover
Upvotes: 4