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 does not ignore safe area #21

Closed PhilipDukhov closed 8 months ago

PhilipDukhov commented 8 months ago

I need to fill background, including safe area - I'm doing it manually because we use material in real world, so it cannot be passed with options.

This bug reproduces only with some strict layout conditions - removing title, spacing or minHeight "solves" the problem

ZStack {}
    .presentation(
        transition: .sheet(
            options: .init(
                detents: [.ideal],
                options: .init()
            )
        ),
        isPresented: .constant(true)
    ) {
        ZStack {

        }
        .presentation(
            transition: .sheet(
                options: .init(
                    detents: [.ideal],
                    options: .init()
                )
            ),
            isPresented: .constant(true)
        ) {
            VStack(spacing: 12) {
                Text("title")
                Button {

                } label: {
                    Text("buttonText")
                }
                .frame(minHeight: 30)
            }
            .background(Color.red.ignoresSafeArea(edges: .all))
        }
    }
nathantannar4 commented 8 months ago

You're missing making the content flexible. So the background modifier never proposes a view frame that would overlap with the safe area.

Add .frame(maxWidth: .infinity, maxHeight: .infinity) before the background modifier.

Or even better, use the preferredPresentationBackgroundColor option for the presentation transition and the color will be applied to the background of the presented UIViewController, guaranteeing it spans the entire background without needing to fuss with SwiftUI layout

options: .init(preferredPresentationBackgroundColor: .red)