Commit dcbefb87 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Adds PropertyAnimatorGroup

This CL adds a leightweight construct for managing groups of property
animators.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I875abe271a1eadc36e7d012e8c03117b12ac3f8c
Reviewed-on: https://chromium-review.googlesource.com/1118261
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571892}
parent 28dbc883
......@@ -29,6 +29,8 @@ source_set("util") {
"optional_property_animator.mm",
"pasteboard_util.h",
"pasteboard_util.mm",
"property_animator_group.h",
"property_animator_group.mm",
"relaxed_bounds_constraints_hittest.h",
"snapshot_util.h",
"snapshot_util.mm",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_UTIL_PROPERTY_ANIMATOR_GROUP_H_
#define IOS_CHROME_BROWSER_UI_UTIL_PROPERTY_ANIMATOR_GROUP_H_
#import <UIKit/UIKit.h>
// A group of UIViewPropertyAnimators, which can be run (and stopped) together.
// This class is functionally convenience wrappers around the
// UIViewImplicitlyAnimating API that will map those method calls to all of the
// animators in a group. Since instances of this class conform to that protocol,
// in most cases an animator group can be used where a single property animator
// would be (provided that the call sites want a id<UIViewImplicitlyAnimating>).
// Protocol methods that mutate the reciever are sequentially appiled to all of
// the animators in the group (this include -startAnimation, -stopAnimation:,
// and so on). -addAnimations:, -addCompletion:, and similar methods are just
// applied to the first animator in the group. Methods (and property getters)
// that return a value return the value of the first animator in the group, on
// the assumption that all of them have the same value.
// It is assumed that all of the animators in the group have the same duration
// and delay. This is enforced by -addAnimator:
@interface PropertyAnimatorGroup : NSObject<UIViewImplicitlyAnimating>
// The animators in this group.
@property(nonatomic, readonly) NSArray<UIViewPropertyAnimator*>* animators;
// Adds |animator|, checking that it matches duration and delay with the other
// animators in the group.
- (void)addAnimator:(UIViewPropertyAnimator*)animator;
@end
#endif // IOS_CHROME_BROWSER_UI_UTIL_PROPERTY_ANIMATOR_GROUP_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/util/property_animator_group.h"
#import "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation PropertyAnimatorGroup {
NSMutableArray<UIViewPropertyAnimator*>* _animators;
}
@synthesize animators = _animators;
- (instancetype)init {
if (self = [super init]) {
_animators = [[NSMutableArray alloc] init];
}
return self;
}
- (void)addAnimator:(UIViewPropertyAnimator*)animator {
DCHECK(self.animators.count == 0 ||
animator.duration == self.animators[0].duration);
DCHECK(self.animators.count == 0 ||
animator.delay == self.animators[0].delay);
[_animators addObject:animator];
}
#pragma mark UIViewAnimating
- (void)startAnimation {
for (UIViewPropertyAnimator* animator in self.animators)
[animator startAnimation];
}
- (void)startAnimationAfterDelay:(NSTimeInterval)delay {
for (UIViewPropertyAnimator* animator in self.animators)
[animator startAnimationAfterDelay:delay];
}
- (void)pauseAnimation {
for (UIViewPropertyAnimator* animator in self.animators)
[animator pauseAnimation];
}
- (void)stopAnimation:(BOOL)withoutFinishing {
for (UIViewPropertyAnimator* animator in self.animators)
[animator stopAnimation:withoutFinishing];
}
- (void)finishAnimationAtPosition:(UIViewAnimatingPosition)finalPosition {
for (UIViewPropertyAnimator* animator in self.animators)
[animator finishAnimationAtPosition:finalPosition];
}
- (CGFloat)fractionComplete {
return self.animators[0].fractionComplete;
}
- (void)setFractionComplete:(CGFloat)fractionComplete {
for (UIViewPropertyAnimator* animator in self.animators)
animator.fractionComplete = fractionComplete;
}
- (BOOL)isReversed {
return self.animators[0].reversed;
}
- (void)setReversed:(BOOL)reversed {
for (UIViewPropertyAnimator* animator in self.animators)
animator.reversed = reversed;
}
- (UIViewAnimatingState)state {
return self.animators[0].state;
}
- (BOOL)isRunning {
return self.animators[0].running;
}
#pragma mark UIViewImplicitlyAnimating
- (void)addAnimations:(void (^)())animation {
[self.animators[0] addAnimations:animation];
}
- (void)addAnimations:(void (^)())animation delayFactor:(CGFloat)delayFactor {
[self.animators[0] addAnimations:animation delayFactor:delayFactor];
}
- (void)addCompletion:(void (^)(UIViewAnimatingPosition))completion {
[self.animators[0] addCompletion:completion];
}
- (void)continueAnimationWithTimingParameters:
(id<UITimingCurveProvider>)parameters
durationFactor:(CGFloat)durationFactor {
[self.animators[0] continueAnimationWithTimingParameters:parameters
durationFactor:durationFactor];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment