-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and refactor animations options (#4880)
- Loading branch information
Showing
24 changed files
with
292 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#import "RNNOptions.h" | ||
|
||
@interface RNNAnimationConfigurationOptions : RNNOptions | ||
|
||
@property (nonatomic, strong) Double* from; | ||
@property (nonatomic, strong) Double* to; | ||
@property (nonatomic, strong) Double* duration; | ||
@property (nonatomic, strong) Double* startDelay; | ||
|
||
- (BOOL)hasAnimation; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#import "RNNAnimationConfigurationOptions.h" | ||
|
||
@implementation RNNAnimationConfigurationOptions | ||
|
||
- (instancetype)initWithDict:(NSDictionary *)dict { | ||
self = [super init]; | ||
|
||
self.from = [DoubleParser parse:dict key:@"from"]; | ||
self.to = [DoubleParser parse:dict key:@"to"]; | ||
self.startDelay = [DoubleParser parse:dict key:@"startDelay"]; | ||
self.duration = [DoubleParser parse:dict key:@"duration"]; | ||
|
||
return self; | ||
} | ||
|
||
- (BOOL)hasAnimation { | ||
return self.from.hasValue && self.to.hasValue; | ||
} | ||
|
||
@end |
3 changes: 1 addition & 2 deletions
3
lib/ios/RNNTransitionsOptions.h → lib/ios/RNNAnimationsOptions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#import "RNNAnimationsOptions.h" | ||
|
||
@implementation RNNAnimationsOptions | ||
|
||
- (instancetype)initWithDict:(NSDictionary *)dict { | ||
self = [super init]; | ||
|
||
self.push = [[RNNScreenTransition alloc] initWithDict:dict[@"push"]]; | ||
self.pop = [[RNNScreenTransition alloc] initWithDict:dict[@"pop"]]; | ||
self.showModal = [[RNNScreenTransition alloc] initWithDict:dict[@"showModal"]]; | ||
self.dismissModal = [[RNNScreenTransition alloc] initWithDict:dict[@"dismissModal"]]; | ||
self.setStackRoot = [[RNNScreenTransition alloc] initWithDict:dict[@"setStackRoot"]]; | ||
self.setRoot = [[RNNScreenTransition alloc] initWithDict:dict[@"setRoot"]]; | ||
|
||
return self; | ||
} | ||
|
||
@end |
2 changes: 1 addition & 1 deletion
2
lib/ios/RNNModalAnimation.h → lib/ios/RNNAnimationsTransitionDelegate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#import "RNNAnimationsTransitionDelegate.h" | ||
|
||
@implementation RNNAnimationsTransitionDelegate | ||
|
||
- (instancetype)initWithScreenTransition:(RNNScreenTransition *)screenTransition isDismiss:(BOOL)isDismiss { | ||
self = [super init]; | ||
self.screenTransition = screenTransition; | ||
self.isDismiss = isDismiss; | ||
return self; | ||
} | ||
|
||
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { | ||
return self; | ||
} | ||
|
||
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { | ||
return self; | ||
} | ||
|
||
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext { | ||
return self.screenTransition.maxDuration / 1000; | ||
} | ||
|
||
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { | ||
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; | ||
UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; | ||
|
||
[CATransaction begin]; | ||
[CATransaction setCompletionBlock:^{ | ||
[transitionContext completeTransition:![transitionContext transitionWasCancelled]]; | ||
}]; | ||
|
||
if (_isDismiss) { | ||
[[transitionContext containerView] addSubview:toViewController.view]; | ||
[[transitionContext containerView] addSubview:fromViewController.view]; | ||
[self animateElement:self.screenTransition.content view:fromViewController.view elementName:@"content"]; | ||
} else { | ||
[[transitionContext containerView] addSubview:toViewController.view]; | ||
[self animateElement:self.screenTransition.content view:toViewController.view elementName:@"content"]; | ||
} | ||
|
||
[CATransaction commit]; | ||
} | ||
|
||
- (void)animationWithKeyPath:(NSString *)keyPath from:(id)from to:(id)to duration:(CFTimeInterval)duration forView:(UIView *)view animationName:(NSString *)animationName { | ||
CABasicAnimation *animation = [CABasicAnimation animation]; | ||
animation.keyPath = keyPath; | ||
animation.fromValue = from; | ||
animation.toValue = to; | ||
animation.duration = duration / 1000; | ||
[view.layer addAnimation:animation forKey:animationName]; | ||
} | ||
|
||
- (void)animateElement:(RNNElementTransitionOptions *)element view:(UIView *)view elementName:(NSString *)elementName { | ||
[self animationWithKeyPath:@"position.x" from:@(view.layer.position.x + [element.x.from getWithDefaultValue:0]) to:@(view.layer.position.x + [element.x.to getWithDefaultValue:0]) duration:[element.x.duration getWithDefaultValue:1] forView:view animationName:@"element.position.x"]; | ||
[self animationWithKeyPath:@"position.y" from:@(view.layer.position.y + [element.y.from getWithDefaultValue:0]) to:@(view.layer.position.y + [element.y.to getWithDefaultValue:0]) duration:[element.y.duration getWithDefaultValue:1] forView:view animationName:[NSString stringWithFormat:@"%@.position.y", elementName]]; | ||
[self animationWithKeyPath:@"opacity" from:@([element.alpha.from getWithDefaultValue:1]) to:@([element.alpha.to getWithDefaultValue:1]) duration:[element.alpha.duration getWithDefaultValue:1] forView:view animationName:[NSString stringWithFormat:@"%@.alpha", elementName]]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
#import "RNNAnimationOptions.h" | ||
#import "RNNSharedElementAnimationOptions.h" | ||
|
||
@interface RNNAnimator : NSObject <UIViewControllerAnimatedTransitioning> | ||
|
||
-(instancetype)initWithTransitionOptions:(RNNAnimationOptions *)transitionOptions; | ||
-(instancetype)initWithTransitionOptions:(RNNSharedElementAnimationOptions *)transitionOptions; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#import "RNNOptions.h" | ||
#import "RNNAnimationConfigurationOptions.h" | ||
|
||
@interface RNNElementTransitionOptions : RNNOptions | ||
|
||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* alpha; | ||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* x; | ||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* y; | ||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* scaleX; | ||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* scaleY; | ||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* rotationX; | ||
@property (nonatomic, strong) RNNAnimationConfigurationOptions* rotationY; | ||
@property (nonatomic, strong) Bool* waitForRender; | ||
|
||
- (double)maxDuration; | ||
- (BOOL)hasAnimation; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#import "RNNElementTransitionOptions.h" | ||
|
||
@implementation RNNElementTransitionOptions | ||
|
||
- (instancetype)initWithDict:(NSDictionary *)dict { | ||
self = [super init]; | ||
|
||
self.alpha = [[RNNAnimationConfigurationOptions alloc] initWithDict:dict[@"alpha"]]; | ||
self.x = [[RNNAnimationConfigurationOptions alloc] initWithDict:dict[@"x"]]; | ||
self.y = [[RNNAnimationConfigurationOptions alloc] initWithDict:dict[@"y"]]; | ||
|
||
return self; | ||
} | ||
|
||
- (BOOL)hasAnimation { | ||
return self.x.hasAnimation || self.y.hasAnimation || self.alpha.hasAnimation; | ||
} | ||
|
||
- (double)maxDuration { | ||
double maxDuration = 0; | ||
if ([_x.duration getWithDefaultValue:0] > maxDuration) { | ||
maxDuration = [_x.duration getWithDefaultValue:0]; | ||
} | ||
if ([_y.duration getWithDefaultValue:0] > maxDuration) { | ||
maxDuration = [_y.duration getWithDefaultValue:0]; | ||
} | ||
if ([_alpha.duration getWithDefaultValue:0] > maxDuration) { | ||
maxDuration = [_alpha.duration getWithDefaultValue:0]; | ||
} | ||
|
||
return maxDuration; | ||
} | ||
|
||
@end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.