-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Sheet): Fix dismissal bug and TestUI in Sheet
- Loading branch information
1 parent
669d73d
commit 427d1dd
Showing
98 changed files
with
690 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Sources/Mistica/Components/Sheet/SheetTransition/SheetPresentationAnimator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// SheetPresentationAnimator.swift | ||
// | ||
// Made with ❤️ by Novum | ||
// | ||
// Copyright © Telefonica. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
/** | ||
Basically the animator will animate the new View Controller showing it from the bottom. | ||
It will be dismissed in the opposite direction. | ||
*/ | ||
class SheetPresentationAnimator: NSObject { | ||
private let isPresentation: Bool | ||
init(isPresentation: Bool) { | ||
self.isPresentation = isPresentation | ||
} | ||
} | ||
|
||
extension SheetPresentationAnimator: UIViewControllerAnimatedTransitioning { | ||
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { | ||
UIView.defaultAnimationDuration | ||
} | ||
|
||
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { | ||
let key = isPresentation ? UITransitionContextViewControllerKey.to : UITransitionContextViewControllerKey.from | ||
guard let controller = transitionContext.viewController(forKey: key) else { return } | ||
let animationDuration = transitionDuration(using: transitionContext) | ||
|
||
let presentedFrame = transitionContext.finalFrame(for: controller) | ||
var dismissedFrame = presentedFrame | ||
dismissedFrame.origin.y = transitionContext.containerView.frame.size.height | ||
|
||
let initialFrame: CGRect | ||
let finalFrame: CGRect | ||
let options: UIView.AnimationOptions | ||
|
||
if isPresentation { | ||
transitionContext.containerView.addSubview(controller.view) | ||
initialFrame = dismissedFrame | ||
finalFrame = presentedFrame | ||
options = .curveEaseOut | ||
} else { | ||
initialFrame = presentedFrame | ||
finalFrame = dismissedFrame | ||
options = .curveEaseIn | ||
} | ||
|
||
controller.view.frame = initialFrame | ||
UIView.animate(withDuration: animationDuration, delay: 0, options: options, animations: { | ||
controller.view.frame = finalFrame | ||
}) { _ in | ||
transitionContext.completeTransition(!transitionContext.transitionWasCancelled) | ||
} | ||
} | ||
} |
Oops, something went wrong.