From ba2ac342566911459ff1e8c16caaeccdc140b0e0 Mon Sep 17 00:00:00 2001 From: Joel Arvidsson Date: Thu, 2 Nov 2023 18:46:27 +0100 Subject: [PATCH] iOS scaleX/scaleY transition --- lib/ios/ElementAnimator.m | 14 ++++++++++++++ lib/ios/HorizontalScaleTransition.h | 6 ++++++ lib/ios/HorizontalScaleTransition.m | 21 +++++++++++++++++++++ lib/ios/TransitionOptions.m | 14 ++++++++++++++ lib/ios/VerticalScaleTransition.h | 6 ++++++ lib/ios/VerticalScaleTransition.m | 21 +++++++++++++++++++++ 6 files changed, 82 insertions(+) create mode 100644 lib/ios/HorizontalScaleTransition.h create mode 100644 lib/ios/HorizontalScaleTransition.m create mode 100644 lib/ios/VerticalScaleTransition.h create mode 100644 lib/ios/VerticalScaleTransition.m diff --git a/lib/ios/ElementAnimator.m b/lib/ios/ElementAnimator.m index 146700a6c9b..a383bdd7747 100644 --- a/lib/ios/ElementAnimator.m +++ b/lib/ios/ElementAnimator.m @@ -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; @@ -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; } diff --git a/lib/ios/HorizontalScaleTransition.h b/lib/ios/HorizontalScaleTransition.h new file mode 100644 index 00000000000..e87e5c07290 --- /dev/null +++ b/lib/ios/HorizontalScaleTransition.h @@ -0,0 +1,6 @@ +#import "FloatTransition.h" +#import + +@interface HorizontalScaleTransition : FloatTransition + +@end diff --git a/lib/ios/HorizontalScaleTransition.m b/lib/ios/HorizontalScaleTransition.m new file mode 100644 index 00000000000..4b190da3b3d --- /dev/null +++ b/lib/ios/HorizontalScaleTransition.m @@ -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 diff --git a/lib/ios/TransitionOptions.m b/lib/ios/TransitionOptions.m index 1cf92534736..11e2be68e23 100644 --- a/lib/ios/TransitionOptions.m +++ b/lib/ios/TransitionOptions.m @@ -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"]]; @@ -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]; @@ -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; @@ -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]; } diff --git a/lib/ios/VerticalScaleTransition.h b/lib/ios/VerticalScaleTransition.h new file mode 100644 index 00000000000..43af70b2d42 --- /dev/null +++ b/lib/ios/VerticalScaleTransition.h @@ -0,0 +1,6 @@ +#import "FloatTransition.h" +#import + +@interface VerticalScaleTransition : FloatTransition + +@end diff --git a/lib/ios/VerticalScaleTransition.m b/lib/ios/VerticalScaleTransition.m new file mode 100644 index 00000000000..c484b4bf9df --- /dev/null +++ b/lib/ios/VerticalScaleTransition.m @@ -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