Skip to content

Commit

Permalink
fix(iOS): implement scaleX and scaleY transition animations (#7807)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador authored Apr 8, 2024
1 parent ad00de9 commit 020a94a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/ios/ElementAnimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#import "ElementHorizontalTransition.h"
#import "ElementVerticalTransition.h"
#import "HorizontalTranslationTransition.h"
#import "HorizontalScaleTransition.h"
#import "RNNElementFinder.h"
#import "Transition.h"
#import "VerticalRotationTransition.h"
#import "VerticalTranslationTransition.h"
#import "VerticalScaleTransition.h"

@implementation ElementAnimator {
UIView *_containerView;
Expand Down Expand Up @@ -60,6 +62,18 @@ - (instancetype)initWithTransitionOptions:(TransitionOptions *)transitionOptions
transitionDetails:transitionOptions.rotationY]];
}

if (transitionOptions.scaleX.hasAnimation) {
[animations addObject:[[HorizontalScaleTransition alloc]
initWithView:self.view
transitionDetails:transitionOptions.scaleX]];
}

if (transitionOptions.scaleY.hasAnimation) {
[animations addObject:[[VerticalScaleTransition alloc]
initWithView:self.view
transitionDetails:transitionOptions.scaleY]];
}

return animations;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/ios/HorizontalScaleTransition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "FloatTransition.h"
#import <Foundation/Foundation.h>

@interface HorizontalScaleTransition : FloatTransition

@end
21 changes: 21 additions & 0 deletions lib/ios/HorizontalScaleTransition.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import "HorizontalScaleTransition.h"

@implementation HorizontalScaleTransition

- (CATransform3D)animateWithProgress:(CGFloat)p {
CGFloat scaleX = [RNNInterpolator fromFloat:self.from
toFloat:self.to
precent:p
interpolator:self.interpolator];
return CATransform3DMakeScale(scaleX, 1, 1);
}

- (CGFloat)calculateFrom:(Double *)from {
return from.hasValue ? from.get : 1;
}

- (CGFloat)calculateTo:(Double *)to {
return to.hasValue ? to.get : 1;
}

@end
14 changes: 14 additions & 0 deletions lib/ios/TransitionOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
self.alpha = [[TransitionDetailsOptions alloc] initWithDict:dict[@"alpha"]];
self.x = [[TransitionDetailsOptions alloc] initWithDict:dict[@"x"]];
self.y = [[TransitionDetailsOptions alloc] initWithDict:dict[@"y"]];
self.scaleX = [[TransitionDetailsOptions alloc] initWithDict:dict[@"scaleX"]];
self.scaleY = [[TransitionDetailsOptions alloc] initWithDict:dict[@"scaleY"]];
self.translationX = [[TransitionDetailsOptions alloc] initWithDict:dict[@"translationX"]];
self.translationY = [[TransitionDetailsOptions alloc] initWithDict:dict[@"translationY"]];
self.rotationX = [[TransitionDetailsOptions alloc] initWithDict:dict[@"rotationX"]];
Expand All @@ -23,6 +25,8 @@ - (void)mergeOptions:(TransitionOptions *)options {
[self.alpha mergeOptions:options.alpha];
[self.x mergeOptions:options.x];
[self.y mergeOptions:options.y];
[self.scaleX mergeOptions:options.scaleX];
[self.scaleY mergeOptions:options.scaleY];
[self.translationX mergeOptions:options.translationX];
[self.translationY mergeOptions:options.translationY];
[self.rotationX mergeOptions:options.rotationX];
Expand All @@ -36,12 +40,14 @@ - (void)mergeOptions:(TransitionOptions *)options {

- (BOOL)hasAnimation {
return self.x.hasAnimation || self.y.hasAnimation || self.alpha.hasAnimation ||
self.scaleX.hasAnimation || self.scaleY.hasAnimation ||
self.translationX.hasAnimation || self.translationY.hasAnimation ||
self.rotationX.hasAnimation || self.rotationY.hasAnimation;
}

- (BOOL)hasValue {
return self.x.hasAnimation || self.y.hasAnimation || self.alpha.hasAnimation ||
self.scaleX.hasAnimation || self.scaleY.hasAnimation ||
self.translationX.hasAnimation || self.translationY.hasAnimation ||
self.rotationX.hasAnimation || self.rotationY.hasAnimation ||
self.waitForRender.hasValue || self.enable.hasValue;
Expand All @@ -61,6 +67,14 @@ - (NSTimeInterval)maxDuration {
maxDuration = [_y.duration withDefault:0];
}

if ([_scaleX.duration withDefault:0] > maxDuration) {
maxDuration = [_scaleX.duration withDefault:0];
}

if ([_scaleY.duration withDefault:0] > maxDuration) {
maxDuration = [_scaleY.duration withDefault:0];
}

if ([_translationX.duration withDefault:0] > maxDuration) {
maxDuration = [_translationX.duration withDefault:0];
}
Expand Down
6 changes: 6 additions & 0 deletions lib/ios/VerticalScaleTransition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "FloatTransition.h"
#import <Foundation/Foundation.h>

@interface VerticalScaleTransition : FloatTransition

@end
21 changes: 21 additions & 0 deletions lib/ios/VerticalScaleTransition.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import "VerticalScaleTransition.h"

@implementation VerticalScaleTransition

- (CATransform3D)animateWithProgress:(CGFloat)p {
CGFloat scaleY = [RNNInterpolator fromFloat:self.from
toFloat:self.to
precent:p
interpolator:self.interpolator];
return CATransform3DMakeScale(1, scaleY, 1);
}

- (CGFloat)calculateFrom:(Double *)from {
return from.hasValue ? from.get : 1;
}

- (CGFloat)calculateTo:(Double *)to {
return to.hasValue ? to.get : 1;
}

@end

0 comments on commit 020a94a

Please sign in to comment.