@@ -301,6 +301,9 @@ private struct Sheet<Content>: UIViewRepresentable where Content: View {
301301 /// A Boolean value indicating whether the sheet was already presenting.
302302 let wasPresenting = rootViewController. presentedViewController != nil
303303
304+ /// A Boolean value indicating whether the hosting controller is being dismissed.
305+ let isHostBeingDismissed = model. hostingController. isBeingDismissed
306+
304307 /// A Boolean value indicating whether the presented view controller is an alert controller.
305308 let isPresentedControllerAlertType = rootViewController. presentedViewController is UIAlertController
306309
@@ -311,12 +314,16 @@ private struct Sheet<Content>: UIViewRepresentable where Content: View {
311314 configureSheetPresentationController ( sheet)
312315 // Presents the hosting controller.
313316 rootViewController. present ( model. hostingController, animated: model. isTransitioningFromPopover ? false : true )
314- } else if !isPresented && wasPresenting && !model . hostingController . isBeingDismissed && !isPresentedControllerAlertType {
317+ } else if !isPresented && wasPresenting && !isHostBeingDismissed && !isPresentedControllerAlertType {
315318 // Dismisses the view controller presented by the root view controller
316319 // if 'isPresented' is false, but was presenting before (popover), is
317320 // not currently being dismissed, and is not an alert.
318321 rootViewController. dismiss ( animated: isPresentedControllerHostingType ? true : false )
319322 model. isTransitioningFromPopover = !isPresentedControllerHostingType
323+ } else if isHostBeingDismissed {
324+ // Sets 'isPresented' to false when the hosting controller is being dismissed.
325+ isPresented = false
326+ model. isTransitioningFromPopover = !isPresentedControllerHostingType
320327 } else if wasPresenting {
321328 // Updates the sheet presentation controller and the root view of the hosting
322329 // controller if the sheet was already presenting.
0 commit comments