Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Add support for fallback transitions.
Browse files Browse the repository at this point in the history
Summary:
This new API allows transitions to fallback to other transition types in certain contexts. For example, a full-screen fab transition might choose to fall back to a modal slide transition when being dismissed.

In order to check sameness we had to make Transition a class protocol. This doesn't affect any existing transition implementations because they are all classes in practice.

Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, randcode-generator

Reviewed By: randcode-generator

Tags: #material_motion

Differential Revision: http://codereview.cc/D3228
  • Loading branch information
Jeff Verkoeyen committed May 16, 2017
1 parent 4ad2c55 commit 12acff9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/transitions/Transition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import UIKit
A transition is responsible for describing the motion that will occur during a UIViewController
transition.
*/
public protocol Transition {
public protocol Transition: class {
/**
Invoked on initiation of a view controller transition.

Expand All @@ -30,6 +30,20 @@ public protocol Transition {
func willBeginTransition(withContext ctx: TransitionContext, runtime: MotionRuntime) -> [Stateful]
}

/**
A transition can return an alternative fallback transition instance.
*/
public protocol TransitionWithFallback: Transition {
/**
Invoked before the transition begins.

If the returned instance also conforms to TransitionWithFallback, then the returned instance's
fallback will be queried. This repeats until a returned instance does not conform to
TransitionWithFallback or it returns self.
*/
func fallbackTansition(withContext ctx: TransitionContext) -> Transition
}

/**
A transition is responsible for describing the motion that will occur during a UIViewController
transition.
Expand Down
8 changes: 8 additions & 0 deletions src/transitions/TransitionContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public final class TransitionContext: NSObject {
self.transition = transition

super.init()

while let fallbackTransition = self.transition as? TransitionWithFallback {
let fallback = fallbackTransition.fallbackTansition(withContext: self)
if fallback === self.transition {
break
}
self.transition = fallback
}
}

fileprivate let initialDirection: TransitionDirection
Expand Down

0 comments on commit 12acff9

Please sign in to comment.