Detect SwiftUI modal style presentation

Hi:

I want to detect if a view has been presented with a fullscreen cover or with a sheet style. I have to get this info from inside the view that has been presented as a sheet or full screen.

Is there any way to achieve it?

Thanks in advance.

Answered by JesusMG in 744742022

Hi everyone.

I found a solution.

In a full-screen cover presentation, always a top safe area is not equal to zero. In a usual sheet, the top safe area is always zero. (I didn't test it with detents and a drag indicator, in the last case logically the safe area should be different from zero),

The workaround is to use a geometry reader to get the safe area and then apply a conditional view o whatever you need.

I hope it helps you.

Accepted Answer

Hi everyone.

I found a solution.

In a full-screen cover presentation, always a top safe area is not equal to zero. In a usual sheet, the top safe area is always zero. (I didn't test it with detents and a drag indicator, in the last case logically the safe area should be different from zero),

The workaround is to use a geometry reader to get the safe area and then apply a conditional view o whatever you need.

I hope it helps you.

Detect SwiftUI modal style presentation
 
 
Q