-
Notifications
You must be signed in to change notification settings - Fork 12
Rework multi-transition support using a recursive composition API #43
Conversation
d136a15
to
dd3f093
Compare
a5c06fe
to
adf9694
Compare
adf9694
to
82df7ea
Compare
58fd3bc
to
c11ac32
Compare
This reverts the `transitions` API changes introduced in 8653958 and replaces it with a recursive model for transition composition.
eventually invoke transitionDidEnd. Only once both the parent transition and all of its children | ||
(and their children) have completed will the overall view controller transition be completed. | ||
*/ | ||
- (void)composeWithTransition:(nonnull id<MDMTransition>)transition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feedback requested on this API name.
|
||
This may be non-nil while a transition is active. | ||
*/ | ||
@property(nonatomic, strong, nullable, readonly) NSArray<id<MDMTransition>> *activeTransitions; | ||
@property(nonatomic, strong, nullable, readonly) id<MDMTransition> activeTransition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here are mostly reverting the changes introduced in 8653958.
@@ -113,6 +113,8 @@ - (void)startWithContext:(NSObject<MDMTransitionContext> *)context { | |||
|
|||
[UIView animateWithDuration:context.duration animations:^{ | |||
self.scrimView.alpha = context.direction == MDMTransitionDirectionForward ? 1 : 0; | |||
} completion:^(BOOL finished) { | |||
[context transitionDidEnd]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presentation controllers also need to inform the context of completion.
@end | ||
|
||
@protocol MDMViewControllerTransitionContextDelegate <NSObject> | ||
- (void)transitionContextDidEnd:(MDMViewControllerTransitionContext *)context; | ||
@interface MDMViewControllerTransitionContextNode : NSObject <MDMTransitionContext, MDMViewControllerTransitionContextNodeParent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typical parent/node design pattern here. The parent protocol only exposes APIs needed by the child to communicate upwards.
@end | ||
|
||
@implementation MDMViewControllerTransitionContext { | ||
@implementation MDMViewControllerTransitionContextNode { | ||
// Every node points to the same array in memory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a minor simplification: by sharing the same mutable array, every node can add to a single shared pool of completion blocks. The alternative would be to route messages up the parent hierarchy, but given that this is a private implementation detail I wasn't particularly concerned with such an approach.
} | ||
|
||
if (!anyChildActive && _didEnd) { // Inform our parent of completion. | ||
[_parent childNodeTransitionDidEnd:self]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bubbles completion up the tree.
c11ac32
to
d8a081f
Compare
Hi reviewers, I've left some comments to help guide review of the source. |
Gentle ping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And Lo! In the days of [REDACTED], there was a strange silence upon the land, wherein the voices of many were missing or muted. Houses went unbuilt, promises were not kept, and there was a general uneasiness about all.
This largely reworks the changes made in #40.
This new API supports a recursive model for building modular transitions. Every view controller transition is now governed by a single root transition. This root transition can then compose out to child transitions if it so chooses. A view controller transition is complete once every transition in the tree is complete.
This pattern provides clear solutions for how to handle data passing and sharing between modular transitions, as seen most clearly in the
PhotoAlbumTransition
example which makes heavy use of transition composition and view duplication.There are four major parts to this change:
README
The readme's intro tutorial on how to build a transition has been updated.
Updated examples
The photo album transition example has been updated to make use of compositional transitions. Its transition hierarchy looks like so:
Added functionality
The new compositional functionality is made visible to clients through TransitionContext's new API
compose(with:)
. For example:The implementation of the tree-based compositional structure is found in
MDMViewControllerTransitionCoordinator.m
.Added tests
There are new tests for validating certain features of the transitioning stack, including the new compositional APIs.
Future plans
With this architecture in place, we'll be able to start deploying a library of pre-made transitions that clients can piece together to build complex transitions. These transitions will go in a separate MaterialMotion Objective-C library, making use of both MotionTransitioning and MotionAnimator.