         transitionContext.completeTransition(true)
         self.bubble.isHidden = true
         fromViewController?.endAppearanceTransition()
-        toViewController?.endAppearanceTransition()
+        if toViewController?.modalPresentationStyle == .custom {
+          toViewController?.endAppearanceTransition()
+        }
       })
     } else {
+      if fromViewController?.modalPresentationStyle == .custom {
+        fromViewController?.beginAppearanceTransition(false, animated: true)
+      }
+      toViewController?.beginAppearanceTransition(true, animated: true)
+      
       let key = (transitionMode == .pop) ? UITransitionContextViewKey.to : UITransitionContextViewKey.from
       let returningControllerView = transitionContext.view(forKey: key)!
       let originalCenter = returningControllerView.center

    let fromViewController = transitionContext.viewController(forKey: .from)
    let toViewController = transitionContext.viewController(forKey: .to)
    
    fromViewController?.beginAppearanceTransition(false, animated: true)
    toViewController?.beginAppearanceTransition(true, animated: true)
    
    if transitionMode == .present {
      let presentedControllerView = transitionContext.view(forKey: UITransitionContextViewKey.to)!
      let originalCenter = presentedControllerView.center
      let originalSize = presentedControllerView.frame.size

        self.bubble.removeFromSuperview()
        transitionContext.completeTransition(true)
        
        if fromViewController?.modalPresentationStyle == .custom {
          fromViewController?.endAppearanceTransition()
        }
        toViewController?.endAppearanceTransition()
      })
    }
