1

SwiftUI has these two modifiers:

.actionSheet(isPresented: $showActionPurchase) { () -> ActionSheet in

and

.sheet(isPresented: $showAlert,

one presents an action sheet and the other presents a sheet (?)

Why? What is the difference between these elements, if any?

Ronnie
  • 332
  • 2
  • 11

1 Answers1

5

sheet used for showing some view modal-way, but actionSheet is kind of alert view! they are very diffrent topic!

    import SwiftUI

struct ContentView: View {
    
    @State var showSheet = false
    @State var showActionSheet = false
    
    let appActionSheet = ActionSheet(title: Text("ActionSheet"), message: Text("I am an ActionSheet"), buttons: [
        .default(Text("some text")),
        .cancel()
    ])
    
    
    var body: some View {

        VStack
        {
            
            Button("show sheet") {showSheet.toggle()}.padding()
            
            Button("show actionSheet") {showActionSheet.toggle()}.padding()
            
            
        }.font(Font.title.bold())
        .sheet(isPresented: $showSheet, content: {sheetView()})
        .actionSheet(isPresented: $showActionSheet, content: {appActionSheet})

    }
}



struct sheetView: View {
    var body: some View {
        
        ZStack
        {
            Color.red
            Text("I am sheet view")
        }.ignoresSafeArea()
    }
}

enter image description here

enter image description here

ios coder
  • 1
  • 4
  • 31
  • 91
  • 1
    ahhhh, thanks. I am still trying to figure out some error on the code that will lead to show that. You are amazing. Other people here thinks everyone have to know everything, so they express their hate by downvoting everybody that is not at the same level. Let them. I am on my first weeks learning swiftui. Thanks. – Ronnie Nov 08 '20 at 19:23
  • 1
    no big deal, if you saw that massage or error kind in console, you can ignore that, it is because of SwiftUI using UIKit component and constraints in wrong way! but no problem I think apple will debug it in future. – ios coder Nov 08 '20 at 19:30