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

Commit

Permalink
Merge branch 'release-candidate' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Verkoeyen committed Jun 6, 2017
2 parents 8977b27 + 16f329c commit 303574d
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 5 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
# 1.1.0

This minor release introduces two new features to the Transition protocol family.

## New features

* [Add support for fallback transitioning. (#16)](https://github.com/material-motion/transitioning-objc/commit/e139cc2c5bb7234df6b40cc82bfb81ded57ccbf8) (featherless)
* [Add support for customizing transition durations (#11)](https://github.com/material-motion/transitioning-objc/commit/cf1e7961f51f9f07a252343bf618a45b2a00d707) (Eric Tang)

## API changes

### MDMTransitionWithFallback

*new* protocol: `MDMTransitionWithFallback`

*new* method: `-fallbackTransitionWithContext:` in `MDMTransitionWithFallback`

### MDMTransitionWithCustomDuration

*new* protocol: `MDMTransitionWithCustomDuration`

*new* method: `-transitionDurationWithContext:` in `MDMTransitionWithCustomDuration`

### MDMTransitionController

*new* property: `activeTransition` in `MDMTransitionController`

# 1.0.0

Initial release.
Expand Down
2 changes: 1 addition & 1 deletion Transitioning.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = "Transitioning"
s.summary = "Light-weight API for building UIViewController transitions."
s.version = "1.0.0"
s.version = "1.1.0"
s.authors = "The Material Motion Authors"
s.license = "Apache 2.0"
s.homepage = "https://github.com/material-motion/transitioning-objc"
Expand Down
20 changes: 19 additions & 1 deletion examples/CustomPresentationExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ final class VerticalSheetTransition: NSObject, Transition {
}
}

extension VerticalSheetTransition: TransitionWithPresentation {
extension VerticalSheetTransition: TransitionWithPresentation, TransitionWithFallback {

// We customize the transition going forward but fall back to UIKit for dismissal. Our
// presentation controller will govern both of these transitions.
func fallbackTransition(with context: TransitionContext) -> Transition? {
return context.direction == .forward ? self : nil
}

// This method is invoked when we assign the transition to the transition controller. The result
// is assigned to the view controller's modalPresentationStyle property.
Expand Down Expand Up @@ -174,9 +180,21 @@ final class DimmingPresentationController: UIPresentationController {
}
}

override func dismissalTransitionWillBegin() {
// We fall back to an alongside fade out when there is no active transition instance because
// our start implementation won't be invoked in this case.
if presentedViewController.transitionController.activeTransition == nil {
presentedViewController.transitionCoordinator?.animate(alongsideTransition: { context in
self.dimmingView.alpha = 0
})
}
}

override func dismissalTransitionDidEnd(_ completed: Bool) {
if completed {
dimmingView.removeFromSuperview()
} else {
dimmingView.alpha = 1
}
}

Expand Down
4 changes: 4 additions & 0 deletions examples/FadeExample.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ - (void)viewDidLoad {

@implementation FadeTransition

- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context {
return 0.3;
}

- (void)startWithContext:(id<MDMTransitionContext>)context {
[CATransaction begin];
[CATransaction setCompletionBlock:^{
Expand Down
34 changes: 34 additions & 0 deletions src/MDMTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ NS_SWIFT_NAME(Transition)

@end

/**
A transition with custom duration is able to override the default transition duration.
*/
NS_SWIFT_NAME(TransitionWithCustomDuration)
@protocol MDMTransitionWithCustomDuration
/**
The desired duration of this transition in seconds.
*/
- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context;
@end

/**
A transition can return an alternative fallback transition instance.
*/
NS_SWIFT_NAME(TransitionWithFallback)
@protocol MDMTransitionWithFallback

/**
Asks the receiver to return a transition instance that should be used to drive this transition.
If nil is returned, then the system transition will be used.
If self is returned, then the receiver will be used.
If a new instance is returned and the returned instance also conforms to this protocol, the
returned instance will be queried for a fallback.
Will be queried twice. The first time this method is invoked it's possible to return nil. Doing so
will result in UIKit taking over the transition and a system transition being used. The second time
this method is invoked, the custom transition will already be underway from UIKit's point of view
and a nil return value will be treated equivalent to returning self.
*/
- (nullable id<MDMTransition>)fallbackTransitionWithContext:(nonnull id<MDMTransitionContext>)context;

@end

/**
A transition with presentation is able to customize the overall presentation of the transition,
including adding temporary views and changing the destination frame of the presented view
Expand Down
7 changes: 7 additions & 0 deletions src/MDMTransitionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ NS_SWIFT_NAME(TransitionController)
*/
@property(nonatomic, strong, nullable) id<MDMTransition> transition;

/**
The active transition instance.
This may be non-nil while a transition is active.
*/
@property(nonatomic, strong, nullable, readonly) id<MDMTransition> activeTransition;

@end
4 changes: 4 additions & 0 deletions src/private/MDMPresentationTransitionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ - (void)setTransition:(id<MDMTransition>)transition {
}
}

- (id<MDMTransition>)activeTransition {
return _context.transition;
}

#pragma mark - UIViewControllerTransitioningDelegate

// Animated transitions
Expand Down
2 changes: 2 additions & 0 deletions src/private/MDMViewControllerTransitionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

- (nonnull instancetype)init NS_UNAVAILABLE;

@property(nonatomic, strong, nullable) id<MDMTransition> transition;

@property(nonatomic, weak, nullable) id<MDMViewControllerTransitionContextDelegate> delegate;

@end
Expand Down
30 changes: 27 additions & 3 deletions src/private/MDMViewControllerTransitionContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#import "MDMTransition.h"

@implementation MDMViewControllerTransitionContext {
id<MDMTransition> _transition;
id<UIViewControllerContextTransitioning> _transitionContext;
UIPresentationController *_presentationController;
}
Expand All @@ -43,15 +42,22 @@ - (nonnull instancetype)initWithTransition:(nonnull id<MDMTransition>)transition
_backViewController = backViewController;
_foreViewController = foreViewController;
_presentationController = presentationController;

_transition = [self fallbackForTransition:_transition];
}
if (!_transition) {
return nil;
}
return self;
}

#pragma mark - UIViewControllerAnimatedTransitioning

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
// TODO(featherless): Expose a TransitionWithTiming protocol that allows the transition to
// customize this value.
if ([_transition respondsToSelector:@selector(transitionDurationWithContext:)]) {
id<MDMTransitionWithCustomDuration> withCustomDuration = (id<MDMTransitionWithCustomDuration>)_transition;
return [withCustomDuration transitionDurationWithContext:self];
}
return 0.35;
}

Expand Down Expand Up @@ -116,6 +122,11 @@ - (void)initiateTransition {
[to.view layoutIfNeeded];
}

id<MDMTransition> fallback = [self fallbackForTransition:_transition];
if (fallback) {
_transition = fallback;
}

[self anticipateOnlyExplicitAnimations];

[CATransaction begin];
Expand Down Expand Up @@ -149,4 +160,17 @@ - (void)anticipateOnlyExplicitAnimations {
}];
}

- (id<MDMTransition>)fallbackForTransition:(id<MDMTransition>)transition {
while ([transition respondsToSelector:@selector(fallbackTransitionWithContext:)]) {
id<MDMTransitionWithFallback> withFallback = (id<MDMTransitionWithFallback>)transition;

id<MDMTransition> fallback = [withFallback fallbackTransitionWithContext:self];
if (fallback == transition) {
break;
}
transition = fallback;
}
return transition;
}

@end

0 comments on commit 303574d

Please sign in to comment.