This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
/
RACSignal+RCLAnimationAdditions.h
142 lines (131 loc) · 5.64 KB
/
RACSignal+RCLAnimationAdditions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// RACSignal+RCLAnimationAdditions.h
// ReactiveCocoaLayout
//
// Created by Justin Spahr-Summers on 2013-01-04.
// Copyright (c) 2013 GitHub. All rights reserved.
//
#import <ReactiveCocoa/ReactiveCocoa.h>
// Defines the curve (timing function) for an animation.
//
// RCLAnimationCurveDefault - The default or inherited animation curve.
// RCLAnimationCurveEaseInOut - Begins the animation slowly, speeds up in the
// middle, and then slows to a stop.
// RCLAnimationCurveEaseIn - Begins the animation slowly and speeds up to
// a stop.
// RCLAnimationCurveEaseOut - Begins the animation quickly and slows down to
// a stop.
// RCLAnimationCurveLinear - Animates with the same pace over the duration of
// the animation.
#ifdef RCL_FOR_IPHONE
typedef enum {
RCLAnimationCurveDefault = 0,
RCLAnimationCurveEaseInOut = UIViewAnimationOptionCurveEaseInOut,
RCLAnimationCurveEaseIn = UIViewAnimationOptionCurveEaseIn,
RCLAnimationCurveEaseOut = UIViewAnimationOptionCurveEaseOut,
RCLAnimationCurveLinear = UIViewAnimationOptionCurveLinear
} RCLAnimationCurve;
#else
typedef enum : NSUInteger {
RCLAnimationCurveDefault,
RCLAnimationCurveEaseInOut,
RCLAnimationCurveEaseIn,
RCLAnimationCurveEaseOut,
RCLAnimationCurveLinear
} RCLAnimationCurve;
#endif
// Determines whether the calling code is running from within -animate (or
// a variant thereof).
//
// This can be used to conditionalize behavior based on whether a signal
// somewhere in the chain is supposed to be animated.
//
// This function is thread-safe.
extern BOOL RCLIsInAnimatedSignal(void);
@interface RACSignal (RCLAnimationAdditions)
// Behaves like -animatedSignalsWithDuration: with the system's default
// animation duration.
- (RACSignal *)animatedSignals;
// Invokes -animatedSignalsWithDuration:curve: with a curve of
// RCLAnimationCurveDefault.
- (RACSignal *)animatedSignalsWithDuration:(NSTimeInterval)duration;
// Wraps every next in an animation, using the default duration and animation
// curve, and captures each animation in an inner signal.
//
// On iOS, how you combine the inner signals determines whether animations are
// interruptible:
//
// - Concatenating the inner signals will result in new animations only
// beginning after all previous animations have completed.
// - Flattening or switching the inner signals will start new animations as
// soon as possible, and use the current (in progress) UI state for
// animating.
//
// On OS X, `NSView` animations are always serialized.
//
// Combining the inner signals, and binding the resulting signal of values to
// a view property, will result in updates to that property (that originate from
// the signal) being automatically animated.
//
// To delay an animation, use -[RACSignal delay:] or -[RACSignal throttle:] on
// the receiver _before_ using this method. Because the aforementioned methods
// delay delivery of `next`s, applying them _after_ this method may cause
// values to be delivered outside of any animation block.
//
// Examples
//
// RAC(self.textField, alpha, @1) = [[alphaValues
// animatedSignalsWithDuration:0.2]
// /* Animate changes to the alpha without interruption. */
// concat];
//
// RAC(self.button, alpha, @1) = [[[alphaValues
// /* Delay animations by 0.1 seconds. */
// delay:0.1]
// animatedSignalsWithDuration:0.2 curve:RCLAnimationCurveLinear]
// /* Animate changes to the alpha, and interrupt for any new animations. */
// switchToLatest];
//
// Returns a signal of signals, where each inner signal sends one `next`
// that corresponds to a value from the receiver, then completes when the
// animation corresponding to that value has finished. Deferring the events of
// the returned signal or having them delivered on another thread is considered
// undefined behavior.
- (RACSignal *)animatedSignalsWithDuration:(NSTimeInterval)duration curve:(RCLAnimationCurve)curve;
// Behaves like -animateWithDuration: with the system's default animation
// duration.
- (RACSignal *)animate;
// Invokes -animateWithDuration:curve: with a curve of RCLAnimationCurveDefault.
- (RACSignal *)animateWithDuration:(NSTimeInterval)duration;
// Wraps every next in an animation, using the given duration and animation
// curve.
//
// When using this method, new animations will not begin until all previous
// animations have completed. To disable this behavior (on iOS only), use
// -animatedSignalsWithDuration:curve: instead, and flatten or switch the
// returned signal.
//
// Binding the resulting signal to a view property will result in updates to
// that property (that originate from the signal) being automatically animated.
//
// To delay an animation, use -[RACSignal delay:] or -[RACSignal throttle:] on
// the receiver _before_ applying -animate. Because the aforementioned methods
// delay delivery of `next`s, applying them _after_ -animate will cause values
// to be delivered outside of any animation block.
//
// Examples
//
// RAC(self.textField, rcl_alphaValue, @1) = [[alphaValues
// /* Animate changes to the alpha without interruption. */
// animateWithDuration:0.2];
//
// RAC(self.button, rcl_alphaValue, @1) = [[alphaValues
// /* Delay animations by 0.1 seconds. */
// delay:0.1]
// animateWithDuration:0.2 curve:RCLAnimationCurveLinear];
//
// Returns a signal which animates the sending of its values. Deferring the
// signal's events or having them delivered on another thread is considered
// undefined behavior.
- (RACSignal *)animateWithDuration:(NSTimeInterval)duration curve:(RCLAnimationCurve)curve;
@end