Skip to content

Presenting view controller from detached view controller is not supported #1

@gregbci

Description

@gregbci

Hello,

Thanks for making this example, I found it very helpful! I was getting the following error in Xcode 15.4 when sheets or fullScreenCovers were displayed on a page:

Presenting view controller <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x103019800> from detached view controller <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x10481a400> is not supported, and may result in incorrect safe area insets and a corrupt root presentation. Make sure <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x10481a400> is in the view controller hierarchy before presenting from it. Will become a hard exception in a future release.

The root cause is applying the .sheet() and .fullScreenCover() modifiers to the page rather than the NavigationStack:

NavigationStack(path: $coordinator.path) {
   coordinator.build(page: .main)
   .navigationDestination(for: AppPages.self) { page in
      coordinator.build(page: page)
   }  
}  <---- applied to navigation stack
.sheet(item: $coordinator.sheet) { sheet in
   coordinator.buildSheet(sheet: sheet)
}               
.fullScreenCover(item: $coordinator.fullScreenCover) { item in
   coordinator.buildCover(cover: item)
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions