Skip to content

Commit c3da503

Browse files
committed
Merge pull request IFTTT#1686 from IFTTT/optimize-filmstrip
Optimize filmstrip
2 parents 43e6d68 + 835ea42 commit c3da503

File tree

10 files changed

+1148
-1147
lines changed

10 files changed

+1148
-1147
lines changed

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Expecta (1.0.0)
3-
- JazzHands (2.0.1)
3+
- JazzHands (2.0.2)
44
- Specta (1.0.2)
55

66
DEPENDENCIES:
@@ -14,7 +14,7 @@ EXTERNAL SOURCES:
1414

1515
SPEC CHECKSUMS:
1616
Expecta: 32604574add2c46a36f8d2f716b6c5736eb75024
17-
JazzHands: 100607fd6de21a830a2028122615098cda3407c3
17+
JazzHands: 088a3949e539480b07ba6ae4877da935efcc061b
1818
Specta: 9cec98310dca411f7c7ffd6943552b501622abfe
1919

2020
COCOAPODS: 0.37.2

Example/Pods/Local Podspecs/JazzHands.podspec.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

+1,118-1,118
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pods-JazzHandsDemo-JazzHands.xcscheme

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/Pods-JazzHandsTests-JazzHands.xcscheme

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-JazzHandsDemo/Pods-JazzHandsDemo-environment.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/Pods-JazzHandsTests/Pods-JazzHandsTests-environment.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JazzHands.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'JazzHands'
3-
s.version = '2.0.1'
3+
s.version = '2.0.2'
44
s.summary = 'Simple keyframe animations for scrolling intros.'
55
s.homepage = 'https://github.com/IFTTT/JazzHands'
66
s.author = {

JazzHands/IFTTTFilmstrip.m

+19-18
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,12 @@ @interface IFTTTKeyframe : NSObject
1717
@property (nonatomic, strong) id<IFTTTInterpolatable> value;
1818
@property (nonatomic, copy) IFTTTEasingFunction easingFunction;
1919

20-
- (instancetype)initWithTime:(CGFloat)time value:(id)value;
2120
- (instancetype)initWithTime:(CGFloat)time value:(id)value easingFunction:(IFTTTEasingFunction)easingFunction;
2221

2322
@end
2423

2524
@implementation IFTTTKeyframe
2625

27-
- (instancetype)initWithTime:(CGFloat)time value:(id)value
28-
{
29-
return [self initWithTime:time value:value easingFunction:IFTTTEasingFunctionLinear];
30-
}
31-
3226
- (instancetype)initWithTime:(CGFloat)time value:(id)value easingFunction:(IFTTTEasingFunction)easingFunction
3327
{
3428
if ((self = [super init])) {
@@ -66,15 +60,15 @@ - (BOOL)isEmpty
6660

6761
- (void)setValue:(id<IFTTTInterpolatable>)value atTime:(CGFloat)time
6862
{
69-
NSUInteger indexAfter = [self indexOfKeyframeAfterTime:time];
70-
IFTTTKeyframe *newKeyframe = [[IFTTTKeyframe alloc] initWithTime:time value:value];
71-
[self.keyframes insertObject:newKeyframe atIndex:indexAfter];
63+
[self setValue:value atTime:time withEasingFunction:IFTTTEasingFunctionLinear];
7264
}
7365

7466
- (void)setValue:(id<IFTTTInterpolatable>)value atTime:(CGFloat)time withEasingFunction:(IFTTTEasingFunction)easingFunction
7567
{
76-
NSUInteger indexAfter = [self indexOfKeyframeAfterTime:time];
68+
NSAssert([self canInterpolateNewValue:value], @"New value must have the same interpolatable type as existing keyframe values.");
69+
7770
IFTTTKeyframe *newKeyframe = [[IFTTTKeyframe alloc] initWithTime:time value:value easingFunction:easingFunction];
71+
NSUInteger indexAfter = [self indexOfKeyframeAfterTime:time];
7872
[self.keyframes insertObject:newKeyframe atIndex:indexAfter];
7973
}
8074

@@ -89,14 +83,7 @@ - (void)setValue:(id<IFTTTInterpolatable>)value atTime:(CGFloat)time withEasingF
8983
IFTTTKeyframe *keyframeBefore = (IFTTTKeyframe *)self.keyframes[indexAfter - 1];
9084
IFTTTKeyframe *keyframeAfter = (IFTTTKeyframe *)self.keyframes[indexAfter];
9185
CGFloat progress = [self progressFromTime:keyframeBefore.time toTime:keyframeAfter.time atTime:time withEasingFunction:keyframeBefore.easingFunction];
92-
if ([keyframeBefore.value respondsToSelector:@selector(interpolateTo:withProgress:)]
93-
&& ([keyframeAfter.value isKindOfClass:[keyframeBefore.value class]]
94-
|| ([keyframeBefore.value isKindOfClass:[UIColor class]]
95-
&& [keyframeAfter.value isKindOfClass:[UIColor class]]))) {
96-
value = [keyframeBefore.value interpolateTo:keyframeAfter.value withProgress:progress];
97-
} else {
98-
value = keyframeBefore.value;
99-
}
86+
value = [keyframeBefore.value interpolateTo:keyframeAfter.value withProgress:progress];
10087
} else {
10188
value = ((IFTTTKeyframe *)self.keyframes.lastObject).value;
10289
}
@@ -122,4 +109,18 @@ - (CGFloat)progressFromTime:(CGFloat)fromTime toTime:(CGFloat)toTime atTime:(CGF
122109
return easingFunction(timeElapsed / duration);
123110
}
124111

112+
- (BOOL)canInterpolateNewValue:(id)newValue
113+
{
114+
if (self.keyframes.count == 0) {
115+
return YES;
116+
}
117+
118+
IFTTTKeyframe *existingKeyframe = (IFTTTKeyframe *)self.keyframes.firstObject;
119+
120+
return ([newValue respondsToSelector:@selector(interpolateTo:withProgress:)]
121+
&& ([newValue isKindOfClass:[existingKeyframe.value class]]
122+
|| ([existingKeyframe.value isKindOfClass:[UIColor class]]
123+
&& [newValue isKindOfClass:[UIColor class]])));
124+
}
125+
125126
@end

0 commit comments

Comments
 (0)