[Solved] iOS Sheet Detents (presentation detents) not working after updating from iOS 15 to iOS 16 – Swift

Ali Hasan
ios16 swift-concurrency swiftui-animation swiftui-sheet

Quick Fix: If you face issues with iOS Sheet Detents after updating from iOS 15 to iOS 16, check for circular dependencies within your project. Specifically, look for libraries or components that were updated and might cause navigation stack state instability.

The Problem:

In a SwiftUI project, after updating from iOS 15.3 to iOS 16.4, the presentationDetents property for sheets is not working as expected. The sheets are not showing the detents and are not resizable, despite being set to have medium detents. This issue persists in the preview, simulator, and on a real device, suggesting that it is not a platform-specific problem. The same code works as expected when the project is initially set up with iOS 16.4, indicating that the issue may be related to the iOS update.

The Solutions:

Solution 1: Check for Circular Dependencies

Title: Verify the Absence of Circular Dependencies

Solution:Scrutinize your project for potential circular dependencies. Thesedependencies often manifest when utilizing external libraries or complex navigation schemas. Specifically, ensure that your project doesn’t include a scenario where a library imports your code, which, in turn, imports the same library. Such circular dependencies can lead to unpredictable behaviors and unexpected outcomes, including the malfunctioning of UI elements like presentation detents.

Eliminating Circular Dependencies:Eradicate circular dependencies within your project by restructuring code organization and library utilization. If a library necessitates importing your code, avoid incorporating it directly into your project. Instead, create a separate module or package solely for the library and import that module into the project. This segregation prevents circular references and maintains a clean and well-structured code architecture.

Let’s consider a simplified illustration of a circular dependency:

Project A (SwiftUI App)
- Imports Library B

Library B
- Imports Project A

To resolve this situation, create a new module called “SharedComponents” and move the code that’s imported by Library B into “SharedComponents”. Then, import “SharedComponents” into both Project A and Library B.

Project A (SwiftUI App)
- Imports SharedComponents

Library B
- Imports SharedComponents

- Contains the code that was previously imported by Library B

By implementing this restructuring, you successfully eliminate the circular dependency while maintaining the necessary functionality.


Why is my presentationDetents property ignored?

Check if you have any circular dependency within your project.

What impact does circular dependency have on presentation detents?

It can cause unexpected behavior, like ignoring presentation detents.

Video Explanation:

The following video, titled "BottomSheets and PresentationDetents in SwiftUI - YouTube", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

... sheet presentationDetents modifier that was introduced in iOS 16 ... Fraction and Height Detents 13:20 Multi Sheet presentations 16:59 Custom ...