Giter Club home page Giter Club logo

transitions-objc's Introduction

Material Motion Transitions for Apple Devices

Build Status codecov CocoaPods Compatible Platform Docs

Supported languages

  • Swift 3
  • Objective-C

Features

This library makes it possible to create UIViewController transitions using the Material Motion runtime.

Installation

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C and Swift libraries. CocoaPods automates the process of using third-party libraries in your projects. See the Getting Started guide for more information. You can install it with the following command:

gem install cocoapods

Add MaterialMotionTransitions to your Podfile:

pod 'MaterialMotionTransitions'

Then run the following command:

pod install

Usage

Import the framework:

@import MaterialMotionTransitions;

You will now have access to all of the APIs.

Example apps/unit tests

Check out a local copy of the repo to access the Catalog application by running the following commands:

git clone https://github.com/material-motion/transitions-objc.git
cd transitions-objc
pod install
open MaterialMotionTransitions.xcworkspace

Guides

  1. Architecture
  2. How to create a transition director
  3. How to use a director for a view controller transition

Architecture

The core aspects of this library consist of the following:

  • The TransitionDirector protocol
  • The TransitionController object

An object conforming to TransitionDirector is able to describe the plans that should occur during a UIViewController transition.

TransitionController is what allows you to decide which TransitionDirector should govern a particular transition.

How to create a transition director

Transition directors govern both the presentation and dismissal of a given view controller. An instance of a director is created each time a transition is initiated and thrown away upon the transition's completion.

Step 1: Create a new class that conforms to TransitionDirector

Be sure to store the provided MDMTransition object.

Code snippets:

In Objective-C:

@interface <# DirectorName #>TransitionDirector : NSObject <MDMTransitionDirector>
@end

@interface <# DirectorName #>TransitionDirector ()
@property(nonatomic, strong) MDMTransition *transition;
@end

@implementation <# DirectorName #>TransitionDirector

- (instancetype)initWithTransition:(MDMTransition *)transition {
  self = [super init];
  if (self) {
    _transition = transition;
  }
  return self;
}

- (void)setUp {
}

@end

In Swift:

class <# DirectorName #>TransitionDirector: NSObject, TransitionDirector {

  let transition: Transition
  required init(transition: Transition) {
    self.transition = transition
  }

  func setUp() {
  }
}

Step 2: Register motion in setUp

Register plans using the transition object's runtime.

Code snippets:

In Objective-C:

- (void)setUp {
  [self.transition.runtime addPlan:<#(nonnull NSObject<MDMPlan> *)#> to:<#(nonnull id)#>];
}

In Swift:

func setUp() {
  transition.runtime.addPlan(<#T##plan: Plan##Plan#>, to: <#T##Any#>)
}

How to use a director for a view controller transition

Every view controller has an associated mdm_transitionController instance. Set a TransitionDirector class type on the directorClass property. When you present the view controller, an instance of your TransitionDirector class will be created and its setUp method will be invoked.

Code snippets:

In Objective-C:

<#(nonnull UIViewController *)#>.mdm_transitionController.directorClass = [<# TransitionDirector #>TransitionDirector class];
[self presentViewController:<#(nonnull UIViewController *)#> animated:<#(BOOL)#> completion:<#^(void)completion#>];

In Swift:

<# UIViewController instance #>.mdm_transitionController.directorClass = <# TransitionDirector #>TransitionDirector.self
present(<#T##viewControllerToPresent: UIViewController##UIViewController#>, animated: <#T##Bool#>)

Contributing

We welcome contributions!

Check out our upcoming milestones.

Learn more about our team, our community, and our contributor essentials.

License

Licensed under the Apache 2.0 license. See LICENSE for details.

transitions-objc's People

Contributors

jverkoey avatar willlarche avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

carabina

transitions-objc's Issues

Implement a ViewReplicator API

  • Add a settable replicaControllerDelegate API. Setting this property should assign the delegate to the director's private replicaController instance.

Provide a simple "slide in" transition example

Blocked by #2, #3.

This transition should be a simple TransitionDirector instance.

Only one plan should be registered: the right view controller "shifting up" during presentation.

  • Create an MDMSlideTransitionDirector class.
  • Implement the slide transition using the CoreAnimation motion family.

This transition should support any direction of sliding when being presented.

Should only be returning an interaction controller if we intend to be interactive

We currently always treat every transition as an interactive transition. This is somewhat against the intended use of UIKit's transitioning APIs.

What we should be doing is acting as an interactive transition if there is some indication that the transition is, in fact, interactive. One signal we can use to start is whether any gesture recognizers associated with the transition are active.

Until we start working on interactive transitions support (Milestone 2) we may want to consider simplifying the transition controller logic to only implement the animated API variants.

Transition object needs to clear its state in the controller

The controller holds onto a reference of the transition but never releases it. It should release the transition instance when the transition completes.

The transition should provide a delegate that the controller can assign itself to in order to receive a "didFinish" event. The controller should nil out the transition instance when this event is received.

Transitions must set their internal delegate

They are not, currently. This means the transition controller has no way of knowing when the transition has completed. As a result, the activeTransition object is held for much longer than it needs to be.

Add transition controller API for registering gesture recognizer actions

Should be capable of registering gesture recognizers that initiate an action when the gesture recognizer starts.

Example API signature:

typedef NS_ENUM(NSUInteger, MDMTransitionAction) {
  MDMTransitionActionPush,
  MDMTransitionActionPop,
  MDMTransitionActionPresent,
  MDMTransitionActionDismiss
};

- (void)whenGestureRecognizerBegins:(nonnull UIGestureRecognizer *)gestureRecognizer
                      performAction:(MDMTransitionAction)action;

When the gesture recognizer begins the action should be taken, initiating the creation of the relevant Director.

Create the MDMViewControllerTransition type

This is a private API and does not have a spec in the starmap because it is UIKit-specific.

  • Created when a transition begins.
  • Must conform to both UIViewControllerAnimatedTransitioning and UIViewControllerInteractiveTransitioning
  • Must be initialized with an instance of a MDMTransitionDirector, the initial transition direction (to the left/to the right).

Implement UIViewControllerTransitioningDelegate methods in MDMTransitionController

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
                                                                  presentingController:(UIViewController *)presenting
                                                                      sourceController:(UIViewController *)source;

Must return an instance that conforms to UIViewControllerAnimatedTransitioning. This instance should be a separate bridging object that creates the scheduler and director instances and coordinates their overall execution.

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed;

Similar to the above, but requires a bit of shenanigans to infer the sourceViewController.

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id<UIViewControllerAnimatedTransitioning>)animator;

If we're driving this transition, the interaction controller is always the animator instance we returned in the first method.

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator;

If we're driving this transition, the interaction controller is always the animator instance we returned in the first method.

Create a TransitionController type

Spec: https://material-motion.gitbooks.io/material-motion-starmap/content/specifications/transition_controller.html

This controller publicly conforms to UIViewControllerTransitioningDelegate.

Example use:

viewController.mdm_transitionController.directorClass = [PhotoDirector class];

Class prototype:

MDMTransitionController : NSObject <UIViewControllerTransitioningDelegate>

When mdm_transitionController is accessed, an instance of MDMTransitionController should lazily be created and then assigned to the view controller's transitioningDelegate (if one is not already set). This will allow us to hook in to the iOS view controller transitioning APIs.

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.