Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 42f770f

Browse files
author
Adam Bell
authored
Merge pull request #354 from zats/master
Add convenience initializer for custom animation
2 parents 68796e3 + 139d854 commit 42f770f

12 files changed

+111
-59
lines changed

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ SPEC CHECKSUMS:
99

1010
PODFILE CHECKSUM: 06e2f62938dff5782de5abf2adf6966a85f24637
1111

12-
COCOAPODS: 1.0.0
12+
COCOAPODS: 1.1.1

pop.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Pod::Spec.new do |spec|
77
spec.summary = 'Extensible animation framework for iOS and OS X.'
88
spec.source = { :git => 'https://github.com/facebook/pop.git', :tag => '1.0.9' }
99
spec.source_files = 'pop/**/*.{h,m,mm,cpp}'
10-
spec.public_header_files = 'pop/{POP,POPAnimatableProperty,POPAnimation,POPAnimationEvent,POPAnimationExtras,POPAnimationTracer,POPAnimator,POPBasicAnimation,POPCustomAnimation,POPDecayAnimation,POPDefines,POPGeometry,POPLayerExtras,POPPropertyAnimation,POPSpringAnimation}.h'
10+
spec.public_header_files = 'pop/{POP,POPAnimatableProperty,POPAnimatablePropertyTypes,POPAnimation,POPAnimationEvent,POPAnimationExtras,POPAnimationTracer,POPAnimator,POPBasicAnimation,POPCustomAnimation,POPDecayAnimation,POPDefines,POPGeometry,POPLayerExtras,POPPropertyAnimation,POPSpringAnimation}.h'
1111
spec.requires_arc = true
1212
spec.social_media_url = 'https://twitter.com/fbOpenSource'
1313
spec.library = 'c++'

pop.xcodeproj/project.pbxproj

Lines changed: 43 additions & 35 deletions
Large diffs are not rendered by default.

pop/POP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#import <pop/POPDefines.h>
1414

1515
#import <pop/POPAnimatableProperty.h>
16+
#import <pop/POPAnimatablePropertyTypes.h>
1617
#import <pop/POPAnimation.h>
1718
#import <pop/POPAnimationEvent.h>
1819
#import <pop/POPAnimationExtras.h>

pop/POPAnimatableProperty.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <Foundation/NSObject.h>
1313

1414
#import <pop/POPDefines.h>
15+
#import <pop/POPAnimatablePropertyTypes.h>
1516

1617
@class POPMutableAnimatableProperty;
1718

@@ -46,12 +47,12 @@
4647
/**
4748
@abstract Block used to read values from a property into an array of floats.
4849
*/
49-
@property (readonly, nonatomic, copy) void (^readBlock)(id obj, CGFloat values[]);
50+
@property (readonly, nonatomic, copy) POPAnimatablePropertyReadBlock readBlock;
5051

5152
/**
5253
@abstract Block used to write values from an array of floats into a property.
5354
*/
54-
@property (readonly, nonatomic, copy) void (^writeBlock)(id obj, const CGFloat values[]);
55+
@property (readonly, nonatomic, copy) POPAnimatablePropertyWriteBlock writeBlock;
5556

5657
/**
5758
@abstract The threshold value used when determining completion of dynamics simulations.
@@ -73,12 +74,12 @@
7374
/**
7475
@abstract A read-write version of POPAnimatableProperty readBlock property.
7576
*/
76-
@property (readwrite, nonatomic, copy) void (^readBlock)(id obj, CGFloat values[]);
77+
@property (readwrite, nonatomic, copy) POPAnimatablePropertyReadBlock readBlock;
7778

7879
/**
7980
@abstract A read-write version of POPAnimatableProperty writeBlock property.
8081
*/
81-
@property (readwrite, nonatomic, copy) void (^writeBlock)(id obj, const CGFloat values[]);
82+
@property (readwrite, nonatomic, copy) POPAnimatablePropertyWriteBlock writeBlock;
8283

8384
/**
8485
@abstract A read-write version of POPAnimatableProperty threshold property.

pop/POPAnimatableProperty.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@
166166
typedef struct
167167
{
168168
NSString *name;
169-
pop_animatable_read_block readBlock;
170-
pop_animatable_write_block writeBlock;
169+
POPAnimatablePropertyReadBlock readBlock;
170+
POPAnimatablePropertyWriteBlock writeBlock;
171171
CGFloat threshold;
172172
} _POPStaticAnimatablePropertyState;
173173
typedef _POPStaticAnimatablePropertyState POPStaticAnimatablePropertyState;
@@ -1144,12 +1144,12 @@ - (NSString *)name
11441144
return _state->name;
11451145
}
11461146

1147-
- (pop_animatable_read_block)readBlock
1147+
- (POPAnimatablePropertyReadBlock)readBlock
11481148
{
11491149
return _state->readBlock;
11501150
}
11511151

1152-
- (pop_animatable_write_block)writeBlock
1152+
- (POPAnimatablePropertyWriteBlock)writeBlock
11531153
{
11541154
return _state->writeBlock;
11551155
}
@@ -1167,15 +1167,15 @@ - (CGFloat)threshold
11671167
Concrete immutable property class.
11681168
*/
11691169
@interface POPConcreteAnimatableProperty : POPAnimatableProperty
1170-
- (instancetype)initWithName:(NSString *)name readBlock:(pop_animatable_read_block)read writeBlock:(pop_animatable_write_block)write threshold:(CGFloat)threshold;
1170+
- (instancetype)initWithName:(NSString *)name readBlock:(POPAnimatablePropertyReadBlock)read writeBlock:(POPAnimatablePropertyWriteBlock)write threshold:(CGFloat)threshold;
11711171
@end
11721172

11731173
@implementation POPConcreteAnimatableProperty
11741174

11751175
// default synthesis
11761176
@synthesize name, readBlock, writeBlock, threshold;
11771177

1178-
- (instancetype)initWithName:(NSString *)aName readBlock:(pop_animatable_read_block)aReadBlock writeBlock:(pop_animatable_write_block)aWriteBlock threshold:(CGFloat)aThreshold
1178+
- (instancetype)initWithName:(NSString *)aName readBlock:(POPAnimatablePropertyReadBlock)aReadBlock writeBlock:(POPAnimatablePropertyWriteBlock)aWriteBlock threshold:(CGFloat)aThreshold
11791179
{
11801180
self = [super init];
11811181
if (nil != self) {

pop/POPAnimatablePropertyTypes.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
Copyright (c) 2014-present, Facebook, Inc.
3+
All rights reserved.
4+
5+
This source code is licensed under the BSD-style license found in the
6+
LICENSE file in the root directory of this source tree. An additional grant
7+
of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
typedef void (^POPAnimatablePropertyReadBlock)(id obj, CGFloat values[]);
11+
typedef void (^POPAnimatablePropertyWriteBlock)(id obj, const CGFloat values[]);

pop/POPAnimationRuntime.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#import <objc/runtime.h>
1111

12+
#import <CoreGraphics/CoreGraphics.h>
1213
#import <Foundation/Foundation.h>
1314

15+
#import "POPAnimatablePropertyTypes.h"
1416
#import "POPVector.h"
1517

1618
enum POPValueType
@@ -77,16 +79,10 @@ extern id POPBox(VectorConstRef vec, POPValueType type, bool force = false);
7779
*/
7880
extern VectorRef POPUnbox(id value, POPValueType &type, NSUInteger &count, bool validate);
7981

80-
/**
81-
Read/write block typedefs for convenience.
82-
*/
83-
typedef void(^pop_animatable_read_block)(id obj, CGFloat *value);
84-
typedef void(^pop_animatable_write_block)(id obj, const CGFloat *value);
85-
8682
/**
8783
Read object value and return a Vector4r.
8884
*/
89-
NS_INLINE Vector4r read_values(pop_animatable_read_block read, id obj, size_t count)
85+
NS_INLINE Vector4r read_values(POPAnimatablePropertyReadBlock read, id obj, size_t count)
9086
{
9187
Vector4r vec = Vector4r::Zero();
9288
if (0 == count)

pop/POPAnimator.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void updateAnimatable(id obj, POPPropertyAnimationState *anim, bool shoul
179179
return;
180180

181181
if (anim->hasValue()) {
182-
pop_animatable_write_block write = anim->property.writeBlock;
182+
POPAnimatablePropertyWriteBlock write = anim->property.writeBlock;
183183
if (NULL == write)
184184
return;
185185

@@ -191,7 +191,7 @@ static void updateAnimatable(id obj, POPPropertyAnimationState *anim, bool shoul
191191
// if avoiding extraneous writes and we have a read block defined
192192
if (shouldAvoidExtraneousWrite) {
193193

194-
pop_animatable_read_block read = anim->property.readBlock;
194+
POPAnimatablePropertyReadBlock read = anim->property.readBlock;
195195
if (read) {
196196
// compare current animation value with object value
197197
Vector4r currentValue = currentVec->vector4r();
@@ -212,7 +212,7 @@ static void updateAnimatable(id obj, POPPropertyAnimationState *anim, bool shoul
212212
[anim->tracer writePropertyValue:POPBox(currentVec, anim->valueType, true)];
213213
}
214214
} else {
215-
pop_animatable_read_block read = anim->property.readBlock;
215+
POPAnimatablePropertyReadBlock read = anim->property.readBlock;
216216
NSCAssert(read, @"additive requires an animatable property readBlock");
217217
if (NULL == read) {
218218
return;

pop/POPPropertyAnimation.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,14 @@ typedef NS_OPTIONS(NSUInteger, POPAnimationClampFlags)
6363
@property (assign, nonatomic, getter = isAdditive) BOOL additive;
6464

6565
@end
66+
67+
@interface POPPropertyAnimation (CustomProperty)
68+
69+
+ (instancetype)animationWithCustomPropertyNamed:(NSString *)name
70+
readBlock:(POPAnimatablePropertyReadBlock)readBlock
71+
writeBlock:(POPAnimatablePropertyWriteBlock)writeBlock;
72+
73+
+ (instancetype)animationWithCustomPropertyReadBlock:(POPAnimatablePropertyReadBlock)readBlock
74+
writeBlock:(POPAnimatablePropertyWriteBlock)writeBlock;
75+
76+
@end

0 commit comments

Comments
 (0)