How can I present a small page sheet with SwiftUI?
Asked Answered
B

1

6

I'm developing an app for iPad with SwiftUI. I want to present a page sheet but with a smaller size. I'm using but I can't change the width of the page sheet.

.sheet(
    isPresented: self.$isEditing,
) {
    Text("My page sheet view")
}

The result is :

My app page sheet

How can I have the Apple shortcut app modal size ?

Shortcut app

Maybe it's a proprietary custom view from Apple not available with UIKit... Thank you very much

Bandmaster answered 23/4, 2020 at 14:53 Comment(3)
you have Text("My page sheet view") in your code but its not showing in your example? Do you have any other code that you have yet to showRiddle
No, I used a navigation view in my picture. I preferred simplify the example.Bandmaster
Look at popoversRugging
F
0

At the moment, you can use an actionSheet (iOS 14 or earlier) / confirmationDialog (iOS 15 or later) which is much smaller or you can create your own custom-made sheet maybe with usage of SheeKit.

For the case that an actionSheet / confirmationDialog is enough:

Screenshot of the actionSheet

@State private var showingConfirm: Bool = false
@State private var actionSelection = ""
.. 

Group {
    Button(action: {
            showingConfirm.toggle()
        }, label: {
            Label("Demo")
        })
 }
// iOS 14 
.actionSheet(isPresented: $showingConfirm, content: {

        let action1 = ActionSheet.Button.default(Text("First action")) {
            actionSelection = "First"
        }

        let action2 = ActionSheet.Button.default(Text("Second action")) {
            actionSelection = "Second"
        }

        return ActionSheet(title: Text("Action Sheet"), message: Text("Message"), buttons: [action1, action2])
 })

 // or for iOS 15
 .confirmationDialog("Action Sheet", isPresented: $showingConfirm, titleVisibility: .visible) {
        Button("First action") {
            actionSelection = "First"
        }

        Button("Second action") {
            actionSelection = "Second"
        }

    }
Feld answered 11/5, 2022 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.