Giter Club home page Giter Club logo

easytransitions's Introduction

CocoaPods Carthage Codebeat License

EasyTransitions is a library that helps developers create custom interactive transitions using simple functions defined in a protocol and avoid handling with the mutiple transitions API's in UIKit.

⚠️ This library is a Work In Progress expect many changes until it reaches 1.0 ⚠️

The development roadmap will be documented using Github issues, milestones and project. Contributions are welcome!

🌟 Features

  • Custom transitions simple set up
  • Support for Modal Presentations, UIPresentationController and UINavigationController transitions
  • Interactive transition support in 1 line with multiple pan gesture directions
  • 3 custom transitions as examples
  • iOS & tvOS

📲 Installation

Using CocoaPods

Edit your Podfile and specify the dependency:

pod 'EasyTransitions'

Using Carthage

Edit your Cartfile and specify the dependency:

github "marcosgriselli/EasyTransitions"

👩‍💻 How to use

Transitions

Given that UIViewControllerAnimatedTransitioning works differently for Modal presentations and UINavigationController transitions I've split the functionality in:

  • ModalTransitionConfigurator
  • NavigationTransitionConfigurator

Each of them grabs the available views to perfrom the transition. As read in the docs I avoid grabbing the views directly from the UIViewControllers and access them via UIViewControllerContextTransitioning's view(forKey: UITransitionContextViewKey).

Modal transitions

Designs from Meng To's Design+Code

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 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.

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.

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:

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.
  • Send feedback via twitter.
  • Propose your own fixes, suggestions and open a pull request with the changes.

See all contributors

👨‍💻 Author

Marcos Griselli | @marcosgriselli

Twitter Follow

GitHub Follow

🛡 License

MIT License

Copyright (c) 2018 Marcos Griselli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

easytransitions's People

Contributors

dependabot[bot] avatar julioacarrettoni avatar marcosgriselli avatar spectraldragon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easytransitions's Issues

Build Errors

Hi,

Cool Library. I was able to build with the pod (and adding the files manually) and was able to use the app store animator in my app before the 0.5.4 release, but now I am getting the following errors:

screen shot 2018-08-25 at 1 20 17 pm

screen shot 2018-08-25 at 1 20 33 pm

screen shot 2018-08-25 at 1 20 49 pm

screen shot 2018-08-25 at 1 21 02 pm

Configurable ModalTransitionDelegate

ModalTransitionDelegate should be easy to configure with the behavior we want transition to have in each case. In this way we avoid subclassing when we need a custom presenting flow.

Add multiple examples

Roadmap for transition examples:

  • App Store modal transition
  • UINavigationController swipe back replica
  • Apple Music currently playing animation
  • Bubble style
  • Video player

Support UIScrollView (+subclasses) handling in TransitionInteractiveController

TransitionInteractiveController performs the navigationAction only depending on the swipe velocity. We want to support parameterized handling so we can start the transition only if a requirement is met before swiping.

For example if our presented UIViewController has a UITableView we want to make sure the contentOffset.y is 0 before starting a transition triggered by a Pan.regular(.fromTop).

Configurable NavigationTransitionDelegate

NavigationTransitionDelegate should be easy to configure with the behavior we want transition to have in each case. In this way we avoid subclassing when we need a custom navigation flow.

Interruptible transitions

Use iOS 10 API's to support interruptible transitions in both UIViewControllerAnimatedTransitioning and UIPercentDrivenInteractiveTransition.

Require TransitionInteractiveController gestureRecognizer to fail

There really is now way to do this that I can see. The gestureRecognizer has been marked as private.
I have a horizontal UICollectionViewController. It triggers the dismiss action every time I touch it. Can't move forward until this is fixed or move to a different library.

Do you have any suggestions?

Issue with UITableView as a Detail View in AppStore Transition

Hello!
First of all, great library! I'm experiencing a small issue when using a table view as the detail view in the AppStore transition. When dismissing it - but not completely - and releasing it before it actually dismisses so it returns back to the detail VC, the table view seems to distort. (width decreases it seems)

Use UIScrollView's gesture instead of adding a new UIPanGestureRecognizer

I am using this library to present several UIViewControllers. Many of them have UIScrollView subviews.

ModalTransitionDelegate.interactiveController.gestureRecognizer is private and this makes it impossible for me to tell my views to prefer their gesture recognizers over the interactive controllers gesture recognizer.

What is your recommended way around this?

Animation not working in iOS 13

Hi I am using this library but animation is not work in iOS 13.
can you please update as soon as possible.

Thanks,
Krupa Prajapati.

Simulator Screen Shot - iPhone 11 Pro Max - 2020-02-15 at 23 39 32

Music player like apple music?

Hi Mr. Griselli,
I want to create podcast player like apple music. I use some pods and review example for this. However i can't find any reason for create mini player like apple music. If i use your pod can i create mini player?

Screen Shot 2019-08-21 at 15 04 07

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.