SLE
SLE

Reputation: 407

Open SwiftUI Sheet to medium, but have option to resize to small/large

So I have the following private function:

private var userCreateAccount: some View {
    VStack(alignment: .center) {
        Text("New MapGliders? [Create Account](user-register)")
            .font(Font.custom("Nunito-Regular", size: 16))
            .multilineTextAlignment(.center)
            .environment(\.openURL, OpenURLAction { url in
                switch url.absoluteString {
                case "user-register":
                    showUserRegisterSheet = true
                    return .handled
                default:
                    return .discarded
                }
            })
            .sheet(isPresented: $showUserRegisterSheet) {
                RegisterUserSheetView()
                    .presentationDetents([.medium, .large])
            }
    }
    .padding(.top, 10)
}

I am using .presentationDetents() to have two sizes for views such as .medium and .large.

Is it possible to load the sheet as .medium by default, but then have the options of using .small and .large for the views?

When I pass in .small inside the presentationDetents, it opens .small by default.

Upvotes: 1

Views: 2521

Answers (1)

matt
matt

Reputation: 535119

You need the big brother of your presentationDetents method, presentationDetents(_:selection:). The second parameter lets you set the current detente (and lets you respond when the user changes detents).

Upvotes: 4

Related Questions