# EasyTransitions **Repository Path**: WWDC14/EasyTransitions ## Basic Information - **Project Name**: EasyTransitions - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-03-13 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
Designs from [Meng To](https://twitter.com/mengto)'s [Design+Code](https://designcode.io)
```swift
public protocol ModalTransitionAnimator {
var duration: TimeInterval { get }
var onDismissed: (() -> Void)? { get set }
var onPresented: (() -> Void)? { get set }
func layout(presenting: Bool,
modalView: UIView,
in container: UIView)
func animate(presenting: Bool,
modalView: UIView,
in container: UIView)
}
```
During a modal transition we should only manage the view that is being presented modaly (modalView). We can inject animations on the root controller anyway.
The `ModalTransitionAnimator` is a really straight forward protocol. Just layout the views ready to be animated on `layout` function and perform the animations on `animate`. You can check the [AppStoreAnimator](https://github.com/marcosgriselli/EasyTransitions/blob/master/EasyTransitions/Classes/Animators/AppStoreAnimator.swift) for a basic example.
#### UINavigationController transitions
`UINavigationController` have a slightly different approach. Both the _from_ and _to_ view are accessible using `view(forKey: UITransitionContextViewKey)` so we add them to the protocol functions.
```swift
public protocol NavigationTransitionAnimator {
var duration: TimeInterval { get }
var auxAnimations: (Bool) -> [AuxAnimation] { get set }
func layout(presenting: Bool, fromView: UIView,
toView: UIView, in container: UIView)
func animations(presenting: Bool,
fromView: UIView, toView: UIView,
in container: UIView)
}
```
I've added the auxiliary animations as part of the protocol but expect multiple changes in this area.
#### UIPresentationController transitions
`UIPresentationController` follows the same approach as Modal presentations. The only thing you need to call is `func set(presentationController: UIPresentationController?)` on your `ModalTransitionDelegate` object.
### Interaction
`TransitionInteractiveController` handles wiring a `UIPanGestureRecognizer` to the current `UIViewController`. This works for any action as we should set the `navigationAction: () -> Void` for the interaction to work. This let's us use the same `TransitionInteractiveController` class for Modal, `UINavigationController` or even `UITabBarController` transitions.
It's wiring takes a `UIViewController` and a `Pan` object. EasyTransitions handles the swiping automatically. It responds to velocity and completness percentage to finish the transition. I plan to support configuring this.
Right now the transition will complete if we stop swiping when it's over 50% or if we swipe fast or release. It will cancel it self if we swipe fast and release in the oposite direction.
#### Pan
The `Pan` enum is a simple way to unify `UIPanGestureRecognizer` and `UIScreenEdgePanGestureRecognizer`. Internally EasyTransitions uses `TransitionPanGestureRecognizer` and `TransitionEdgePanGestureRecognier` to support a `PanGesture` protocol which calculates velocity and translation for each gesture and the correct sign they should have.
```swift
public enum Pan {
case regular(PanDirection)
case edge(UIRectEdge)
}
```
### Example
There's an example on `TodayCollectionViewController` but there should't be many changes on other implementations. Here's a generic example:
```swift
class MainViewController: UIViewController {
var modalTransitionDelegate = ModalTransitionDelegate()
func showDetailViewController() {
let detailController = DetailViewController()
let animator = MyAnimator() // ModalTransitionAnimator
modalTransitionDelegate.set(animator: animator)
modalTransitionDelegate.wire(viewController: detailController,
with: .regular(.fromTop),
navigationAction: {
detailController.dismiss(animated: true, completion: nil)
})
detailController.transitioningDelegate = modalTransitionDelegate
detailController.modalPresentationStyle = .custom
present(detailController, animated: true, completion: nil)
}
```
## ❤️ Contributing
This is an open source project, so feel free to contribute. How?
- Open an [issue](https://github.com/marcosgriselli/EasyTransitions/issues/new).
- Send feedback via [twitter](https://twitter.com/marcosgriselli).
- Propose your own fixes, suggestions and open a pull request with the changes.
See [all contributors](https://github.com/marcosgriselli/EasyTransitions/graphs/contributors)
[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/0)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/1)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/2)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/3)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/4)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/5)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/6)[](https://sourcerer.io/fame/marcosgriselli/marcosgriselli/EasyTransitions/links/7)
## 👨💻 Author
Marcos Griselli |