diff --git a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissInteraction.swift b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissInteraction.swift index e7d1ee36..3bff7aef 100644 --- a/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissInteraction.swift +++ b/Packages/GalleryVC/Sources/GalleryVC/GalleryDismissInteraction.swift @@ -53,12 +53,35 @@ class GalleryDismissInteraction: NSObject { let translation = recognizer.translation(in: viewController.view) let velocity = recognizer.velocity(in: viewController.view) - dismissVelocity = velocity - dismissTranslation = translation - viewController.dismiss(animated: true) + let translationMagnitude = sqrt(translation.x.magnitudeSquared + translation.y.magnitudeSquared) + let velocityMagnitude = sqrt(velocity.x.magnitudeSquared + velocity.y.magnitudeSquared) + + if translationMagnitude < 150 && velocityMagnitude < 500 { + isActive = false + + let spring = UISpringTimingParameters(mass: 1, stiffness: 439, damping: 42, initialVelocity: .zero) + let animator = UIViewPropertyAnimator(duration: 0.2, timingParameters: spring) + animator.addAnimations { + self.content!.view.frame = self.origContentFrameInGallery! + self.viewController.currentItemViewController.setControlsVisible(self.origControlsVisible!, animated: false, dueToUserInteraction: false) + } + animator.addCompletion { _ in + self.content!.view.removeFromSuperview() + self.viewController.currentItemViewController.addContent() + self.content = nil + self.origContentFrameInGallery = nil + self.origControlsVisible = nil + } + animator.startAnimation() - // don't unset this until after dismiss is called, so that the dismiss animation controller can read it - isActive = false + } else { + dismissVelocity = velocity + dismissTranslation = translation + viewController.dismiss(animated: true) + + // don't unset this until after dismiss is called, so that the dismiss animation controller can read it + isActive = false + } default: break