nathantannar4 / Transmission

Bridges UIKit presentation APIs to a SwiftUI API so you can use presentation controllers, interactive transitions and more.
BSD 2-Clause "Simplified" License
378 stars 13 forks source link

Nested presentation animation issue #11

Closed PhilipDukhov closed 10 months ago

PhilipDukhov commented 10 months ago

When I have one fullscreen presentation view, and open an other fullscreen presentation from it, during second screen appearance first screen has strange jumpy animation

It looks like it gets scaled up without animation, and then during transition gets scaled back to expected value

res

struct ContentView: View {
    @State var isSheetShown = false
    @State var isSecondSheetShown = false

    var body: some View {
        NavigationStack {
            Button {
                withAnimation {
                    isSheetShown = true
                }
            } label: {
                Text("Show sheet")
                    .foregroundStyle(.gray)
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
            .background(Color.blue)
            .presentationSheet(
                isPresented: $isSheetShown
            ) {
                Button {
                    withAnimation{
                        isSecondSheetShown = true
                    }
                } label: {
                    Text("First sheet")
                        .foregroundStyle(.white)
                }
                .navigationDestination(for: String.self) { item in
                    Text(item)
                }
                .frame(maxWidth: .infinity, maxHeight: .infinity)
                .background {
                    Image(systemName: "photo.artframe")
                        .resizable()
                        .scaledToFit()
                        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
                }
                .presentationSheet(
                    isPresented: $isSecondSheetShown
                ) {
                    Text("Second sheet")
                }
            }
        }
    }
}

extension View {
    func presentationSheet<Destination: View>(
        isPresented: Binding<Bool>,
        @ViewBuilder destination: () -> Destination
    ) -> some View {
        presentation(
            transition: .slide(
                options: .init(
                    edge: .bottom,
                    prefersScaleEffect: true,
                    isInteractive: true,
                    options: .init(
                        shouldAutomaticallyDismissDestination: false,
                        modalPresentationCapturesStatusBarAppearance: true,
                        preferredPresentationBackgroundColor: .gray
                    )
                )
            ),
            isPresented: isPresented
        ) {
            destination()
        }
    }
}
nathantannar4 commented 10 months ago

Will be fixed in 0.1.28 release. For now the patch is available on main