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

Rework multi-transition support using a recursive composition API #43

Merged
merged 1 commit into from
Sep 27, 2017

Conversation

jverkoey
Copy link
Contributor

@jverkoey jverkoey commented Sep 13, 2017

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:

  1. Updated the README documentation.
  2. Updated the examples.
  3. Added the functionality.
  4. Added more tests.

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:

transitions

Added functionality

The new compositional functionality is made visible to clients through TransitionContext's new API compose(with:). For example:

context.compose(with: FadeTransition(target: .foreView, style: .fadeIn))
context.compose(with: SpringFrameTransition(target: .target(snapshotContextView),
                                            size: fitSize))

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.

@jverkoey jverkoey force-pushed the composition branch 4 times, most recently from a5c06fe to adf9694 Compare September 21, 2017 16:55
@jverkoey jverkoey changed the title WIP of composition API. Rework multi-transition support using a recursive composition API Sep 21, 2017
@jverkoey jverkoey force-pushed the composition branch 7 times, most recently from 58fd3bc to c11ac32 Compare September 22, 2017 22:18
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;
Copy link
Contributor Author

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;
Copy link
Contributor Author

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];
Copy link
Contributor Author

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>
Copy link
Contributor Author

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.
Copy link
Contributor Author

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];
Copy link
Contributor Author

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.

@jverkoey
Copy link
Contributor Author

Hi reviewers, I've left some comments to help guide review of the source.

@jverkoey
Copy link
Contributor Author

Gentle ping.

Copy link

@ajsecord ajsecord left a 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.

@jverkoey jverkoey merged commit 0b57361 into develop Sep 27, 2017
@jverkoey jverkoey deleted the composition branch September 27, 2017 19:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants