UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Navigating inside a sheet with height animation

Forums > SwiftUI

Is it possible to navigate inside a sheet view and animate its height to adapt to the new sheet height?

Basically what I am looking for is this effect: <img src="https://i.ibb.co/hWH4gnJ/RPReplay-Final1667845678-MP4.gif" alt="RPReplay-Final1667845678-MP4" border="0">

Not sure if this is possible without creating a custom view, and just using the native sheet component from SwiftUI.

I've been trying different approaches and I can't get it to work. If I use isPresented, the view reloads and the sheet panel pops up or down to the new height. If I use item the panel gets dismissed and then reopens again with the new height.

Thanks! Fran

1      

bump! Any idea if this is possible??

1      

Below code does not auto adjust , but if you know how much content you need to show , may be can be useful


import SwiftUI

struct DismissingView1: View {
    @Environment(\.presentationMode) var presentationMode

    var body: some View {
        Button("Dismiss Me") {
            presentationMode.wrappedValue.dismiss()
        }
    }
}

struct DismissingView2: View {
    @Environment(\.presentationMode) var presentationMode

    var body: some View {
        Button("Dismiss Me Now") {
            presentationMode.wrappedValue.dismiss()
        }
    }
}

struct CardView: View {
    @State private var showingDetail = false
    @State private var showingDetail2 = false
    var body: some View {
        Button("Show Detail") {
                   showingDetail = true
               }
               .sheet(isPresented: $showingDetail) {
                   DismissingView1()
                       .presentationDetents([.height(100), .fraction(20), .medium, .large])
                                          .presentationDragIndicator(.hidden) 
                                          .edgesIgnoringSafeArea(.all)
               }

        Button("Show Sheet 2") {
                   showingDetail2 = true
               }
        .sheet(isPresented: $showingDetail2) {
            DismissingView2()
                .presentationDetents([.height(300), .fraction(20), .medium, .large])
                .presentationDragIndicator(.hidden) 
                .edgesIgnoringSafeArea(.all)
        }

    }

}

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.