|
@@ -9,10 +9,7 @@
|
9
|
9
|
#import "RNNAnimatedView.h"
|
10
|
10
|
|
11
|
11
|
@interface RNNAnimator()
|
12
|
|
-@property (nonatomic, strong)NSArray* animations;
|
13
|
|
-@property (nonatomic)double duration;
|
14
|
|
-@property (nonatomic)double springDamping;
|
15
|
|
-@property (nonatomic)double springVelocity;
|
|
12
|
+@property (nonatomic, strong) RNNTransitionOptions* transitionOptions;
|
16
|
13
|
@property (nonatomic, strong) RNNInteractivePopAnimator* interactivePopAnimator;
|
17
|
14
|
@property (nonatomic) BOOL backButton;
|
18
|
15
|
@property (nonatomic, strong) UIViewController* fromVC;
|
|
@@ -21,10 +18,10 @@
|
21
|
18
|
|
22
|
19
|
@implementation RNNAnimator
|
23
|
20
|
|
24
|
|
-- (instancetype)initWithAnimationsDictionary:(NSDictionary *)animationsDic {
|
|
21
|
+-(instancetype)initWithTransitionOptions:(RNNTransitionOptions *)transitionOptions {
|
25
|
22
|
self = [super init];
|
26
|
|
- if (animationsDic) {
|
27
|
|
- [self setupTransition:animationsDic];
|
|
23
|
+ if (transitionOptions) {
|
|
24
|
+ [self setupTransition:transitionOptions];
|
28
|
25
|
} else {
|
29
|
26
|
return nil;
|
30
|
27
|
}
|
|
@@ -32,37 +29,20 @@
|
32
|
29
|
return self;
|
33
|
30
|
}
|
34
|
31
|
|
35
|
|
--(void)setupTransition:(NSDictionary*)data{
|
36
|
|
- if ([data objectForKey:@"animations"]) {
|
37
|
|
- self.animations= [data objectForKey:@"animations"];
|
38
|
|
- } else {
|
|
32
|
+-(void)setupTransition:(RNNTransitionOptions *)transitionOptions {
|
|
33
|
+ self.transitionOptions = transitionOptions;
|
|
34
|
+ if (!transitionOptions.animations) {
|
39
|
35
|
[[NSException exceptionWithName:NSInvalidArgumentException reason:@"No animations" userInfo:nil] raise];
|
40
|
36
|
}
|
41
|
|
- if ([data objectForKey:@"duration"]) {
|
42
|
|
- self.duration = [[data objectForKey:@"duration"] doubleValue];
|
43
|
|
- } else {
|
44
|
|
- self.duration = 0.7;
|
45
|
|
- }
|
46
|
|
- if ([data objectForKey:@"springDamping"]) {
|
47
|
|
- self.springDamping = [[data objectForKey:@"springDamping"] doubleValue];
|
48
|
|
- } else {
|
49
|
|
- self.springDamping = 0.85;
|
50
|
|
- }
|
51
|
|
- if ([data objectForKey:@"springVelocity"]) {
|
52
|
|
- self.springVelocity= [[data objectForKey:@"springVelocity"] doubleValue];
|
53
|
|
- } else {
|
54
|
|
- self.springVelocity = 0.8;
|
55
|
|
- }
|
56
|
37
|
|
57
|
38
|
self.backButton = false;
|
58
|
39
|
}
|
59
|
40
|
|
60
|
41
|
-(NSArray*)prepareSharedElementTransition:(NSArray*)RNNSharedElementsToVC
|
61
|
42
|
andfromVCElements:(NSArray*)RNNSharedElementsFromVC
|
62
|
|
- withComponentView:(UIView*)componentView
|
63
|
|
-{
|
|
43
|
+ withComponentView:(UIView*)componentView {
|
64
|
44
|
NSMutableArray* transitions = [NSMutableArray new];
|
65
|
|
- for (NSDictionary* transition in self.animations) {
|
|
45
|
+ for (NSDictionary* transition in self.transitionOptions.animations) {
|
66
|
46
|
RNNTransitionStateHolder* transitionStateHolder = [[RNNTransitionStateHolder alloc] initWithTransition:transition];
|
67
|
47
|
RNNElementFinder* elementFinder = [[RNNElementFinder alloc] initWithToVC:self.toVC andfromVC:self.fromVC];
|
68
|
48
|
[elementFinder findElementsInTransition:transitionStateHolder];
|
|
@@ -73,7 +53,7 @@
|
73
|
53
|
[componentView bringSubviewToFront:animatedView];
|
74
|
54
|
transitionStateHolder.animatedView = animatedView;
|
75
|
55
|
[transitions addObject:transitionStateHolder];
|
76
|
|
- if (transitionStateHolder.isSharedElementTransition){
|
|
56
|
+ if (transitionStateHolder.isSharedElementTransition) {
|
77
|
57
|
[transitionStateHolder.toElement setHidden: YES];
|
78
|
58
|
}
|
79
|
59
|
[transitionStateHolder.fromElement setHidden:YES];
|
|
@@ -112,7 +92,7 @@
|
112
|
92
|
|
113
|
93
|
|
114
|
94
|
-(void)animateComplition:(NSArray*)transitions fromVCSnapshot:(UIView*)fromSnapshot andTransitioningContext:(id<UIViewControllerContextTransitioning>)transitionContext {
|
115
|
|
- [UIView animateWithDuration:[self transitionDuration:transitionContext ] delay:0 usingSpringWithDamping:self.springDamping initialSpringVelocity:self.springVelocity options:UIViewAnimationOptionCurveEaseOut animations:^{
|
|
95
|
+ [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0 usingSpringWithDamping:[self.transitionOptions.springDamping doubleValue] initialSpringVelocity:[self.transitionOptions.springVelocity doubleValue] options:UIViewAnimationOptionCurveEaseOut animations:^{
|
116
|
96
|
self.toVC.view.alpha = 1;
|
117
|
97
|
} completion:^(BOOL finished) {
|
118
|
98
|
for (RNNTransitionStateHolder* transition in transitions ) {
|
|
@@ -139,12 +119,11 @@
|
139
|
119
|
}];
|
140
|
120
|
}
|
141
|
121
|
|
142
|
|
-- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext
|
143
|
|
-{
|
144
|
|
- return self.duration;
|
|
122
|
+- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
|
|
123
|
+ return [self.transitionOptions.duration doubleValue];
|
145
|
124
|
}
|
146
|
|
-- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
|
147
|
|
-{
|
|
125
|
+
|
|
126
|
+- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
|
148
|
127
|
UIViewController* toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
|
149
|
128
|
UIViewController* fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
|
150
|
129
|
UIView* componentView = [transitionContext containerView];
|
|
@@ -162,7 +141,5 @@
|
162
|
141
|
[self animateComplition:transitions fromVCSnapshot:fromSnapshot andTransitioningContext:transitionContext];
|
163
|
142
|
[self animateTransitions:transitions];
|
164
|
143
|
}
|
165
|
|
-@end
|
166
|
|
-
|
167
|
|
-
|
168
|
144
|
|
|
145
|
+@end
|