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

Commit 303574d

Browse files
author
Jeff Verkoeyen
committed
Merge branch 'release-candidate' into stable
2 parents 8977b27 + 16f329c commit 303574d

9 files changed

+125
-5
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# 1.1.0
2+
3+
This minor release introduces two new features to the Transition protocol family.
4+
5+
## New features
6+
7+
* [Add support for fallback transitioning. (#16)](https://github.com/material-motion/transitioning-objc/commit/e139cc2c5bb7234df6b40cc82bfb81ded57ccbf8) (featherless)
8+
* [Add support for customizing transition durations (#11)](https://github.com/material-motion/transitioning-objc/commit/cf1e7961f51f9f07a252343bf618a45b2a00d707) (Eric Tang)
9+
10+
## API changes
11+
12+
### MDMTransitionWithFallback
13+
14+
*new* protocol: `MDMTransitionWithFallback`
15+
16+
*new* method: `-fallbackTransitionWithContext:` in `MDMTransitionWithFallback`
17+
18+
### MDMTransitionWithCustomDuration
19+
20+
*new* protocol: `MDMTransitionWithCustomDuration`
21+
22+
*new* method: `-transitionDurationWithContext:` in `MDMTransitionWithCustomDuration`
23+
24+
### MDMTransitionController
25+
26+
*new* property: `activeTransition` in `MDMTransitionController`
27+
128
# 1.0.0
229

330
Initial release.

Transitioning.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = "Transitioning"
33
s.summary = "Light-weight API for building UIViewController transitions."
4-
s.version = "1.0.0"
4+
s.version = "1.1.0"
55
s.authors = "The Material Motion Authors"
66
s.license = "Apache 2.0"
77
s.homepage = "https://github.com/material-motion/transitioning-objc"

examples/CustomPresentationExample.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ final class VerticalSheetTransition: NSObject, Transition {
101101
}
102102
}
103103

104-
extension VerticalSheetTransition: TransitionWithPresentation {
104+
extension VerticalSheetTransition: TransitionWithPresentation, TransitionWithFallback {
105+
106+
// We customize the transition going forward but fall back to UIKit for dismissal. Our
107+
// presentation controller will govern both of these transitions.
108+
func fallbackTransition(with context: TransitionContext) -> Transition? {
109+
return context.direction == .forward ? self : nil
110+
}
105111

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

183+
override func dismissalTransitionWillBegin() {
184+
// We fall back to an alongside fade out when there is no active transition instance because
185+
// our start implementation won't be invoked in this case.
186+
if presentedViewController.transitionController.activeTransition == nil {
187+
presentedViewController.transitionCoordinator?.animate(alongsideTransition: { context in
188+
self.dimmingView.alpha = 0
189+
})
190+
}
191+
}
192+
177193
override func dismissalTransitionDidEnd(_ completed: Bool) {
178194
if completed {
179195
dimmingView.removeFromSuperview()
196+
} else {
197+
dimmingView.alpha = 1
180198
}
181199
}
182200

examples/FadeExample.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ - (void)viewDidLoad {
6060

6161
@implementation FadeTransition
6262

63+
- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context {
64+
return 0.3;
65+
}
66+
6367
- (void)startWithContext:(id<MDMTransitionContext>)context {
6468
[CATransaction begin];
6569
[CATransaction setCompletionBlock:^{

src/MDMTransition.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,40 @@ NS_SWIFT_NAME(Transition)
3636

3737
@end
3838

39+
/**
40+
A transition with custom duration is able to override the default transition duration.
41+
*/
42+
NS_SWIFT_NAME(TransitionWithCustomDuration)
43+
@protocol MDMTransitionWithCustomDuration
44+
/**
45+
The desired duration of this transition in seconds.
46+
*/
47+
- (NSTimeInterval)transitionDurationWithContext:(nonnull id<MDMTransitionContext>)context;
48+
@end
49+
50+
/**
51+
A transition can return an alternative fallback transition instance.
52+
*/
53+
NS_SWIFT_NAME(TransitionWithFallback)
54+
@protocol MDMTransitionWithFallback
55+
56+
/**
57+
Asks the receiver to return a transition instance that should be used to drive this transition.
58+
59+
If nil is returned, then the system transition will be used.
60+
If self is returned, then the receiver will be used.
61+
If a new instance is returned and the returned instance also conforms to this protocol, the
62+
returned instance will be queried for a fallback.
63+
64+
Will be queried twice. The first time this method is invoked it's possible to return nil. Doing so
65+
will result in UIKit taking over the transition and a system transition being used. The second time
66+
this method is invoked, the custom transition will already be underway from UIKit's point of view
67+
and a nil return value will be treated equivalent to returning self.
68+
*/
69+
- (nullable id<MDMTransition>)fallbackTransitionWithContext:(nonnull id<MDMTransitionContext>)context;
70+
71+
@end
72+
3973
/**
4074
A transition with presentation is able to customize the overall presentation of the transition,
4175
including adding temporary views and changing the destination frame of the presented view

src/MDMTransitionController.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ NS_SWIFT_NAME(TransitionController)
3838
*/
3939
@property(nonatomic, strong, nullable) id<MDMTransition> transition;
4040

41+
/**
42+
The active transition instance.
43+
44+
This may be non-nil while a transition is active.
45+
*/
46+
@property(nonatomic, strong, nullable, readonly) id<MDMTransition> activeTransition;
47+
4148
@end

src/private/MDMPresentationTransitionController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ - (void)setTransition:(id<MDMTransition>)transition {
5656
}
5757
}
5858

59+
- (id<MDMTransition>)activeTransition {
60+
return _context.transition;
61+
}
62+
5963
#pragma mark - UIViewControllerTransitioningDelegate
6064

6165
// Animated transitions

src/private/MDMViewControllerTransitionContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
- (nonnull instancetype)init NS_UNAVAILABLE;
3535

36+
@property(nonatomic, strong, nullable) id<MDMTransition> transition;
37+
3638
@property(nonatomic, weak, nullable) id<MDMViewControllerTransitionContextDelegate> delegate;
3739

3840
@end

src/private/MDMViewControllerTransitionContext.m

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#import "MDMTransition.h"
2020

2121
@implementation MDMViewControllerTransitionContext {
22-
id<MDMTransition> _transition;
2322
id<UIViewControllerContextTransitioning> _transitionContext;
2423
UIPresentationController *_presentationController;
2524
}
@@ -43,15 +42,22 @@ - (nonnull instancetype)initWithTransition:(nonnull id<MDMTransition>)transition
4342
_backViewController = backViewController;
4443
_foreViewController = foreViewController;
4544
_presentationController = presentationController;
45+
46+
_transition = [self fallbackForTransition:_transition];
47+
}
48+
if (!_transition) {
49+
return nil;
4650
}
4751
return self;
4852
}
4953

5054
#pragma mark - UIViewControllerAnimatedTransitioning
5155

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

@@ -116,6 +122,11 @@ - (void)initiateTransition {
116122
[to.view layoutIfNeeded];
117123
}
118124

125+
id<MDMTransition> fallback = [self fallbackForTransition:_transition];
126+
if (fallback) {
127+
_transition = fallback;
128+
}
129+
119130
[self anticipateOnlyExplicitAnimations];
120131

121132
[CATransaction begin];
@@ -149,4 +160,17 @@ - (void)anticipateOnlyExplicitAnimations {
149160
}];
150161
}
151162

163+
- (id<MDMTransition>)fallbackForTransition:(id<MDMTransition>)transition {
164+
while ([transition respondsToSelector:@selector(fallbackTransitionWithContext:)]) {
165+
id<MDMTransitionWithFallback> withFallback = (id<MDMTransitionWithFallback>)transition;
166+
167+
id<MDMTransition> fallback = [withFallback fallbackTransitionWithContext:self];
168+
if (fallback == transition) {
169+
break;
170+
}
171+
transition = fallback;
172+
}
173+
return transition;
174+
}
175+
152176
@end

0 commit comments

Comments
 (0)