@@ -67,7 +67,8 @@ - (NSValue *)presentationValueForKeyPath:(NSString *)keyPath {
6767- (CAAnimation *)createAnimationForKeyPath : (NSString *)keyPath
6868 fromValue : (NSValue *)fromValue
6969 toValue : (NSValue *)toValue
70- props : (const EaseViewProps &)props {
70+ props : (const EaseViewProps &)props
71+ loop : (BOOL )loop {
7172 if (props.transitionType == EaseViewTransitionType::Spring) {
7273 CASpringAnimation *spring =
7374 [CASpringAnimation animationWithKeyPath: keyPath];
@@ -89,6 +90,14 @@ - (CAAnimation *)createAnimationForKeyPath:(NSString *)keyPath
8990 timing.timingFunction = timingFunctionForEasing (props.transitionEasing );
9091 timing.fillMode = kCAFillModeForwards ;
9192 timing.removedOnCompletion = NO ;
93+ if (loop) {
94+ if (props.transitionLoop == EaseViewTransitionLoop::Repeat) {
95+ timing.repeatCount = HUGE_VALF ;
96+ } else if (props.transitionLoop == EaseViewTransitionLoop::Reverse) {
97+ timing.repeatCount = HUGE_VALF ;
98+ timing.autoreverses = YES ;
99+ }
100+ }
92101 return timing;
93102 }
94103}
@@ -97,7 +106,8 @@ - (void)applyAnimationForKeyPath:(NSString *)keyPath
97106 animationKey : (NSString *)animationKey
98107 fromValue : (NSValue *)fromValue
99108 toValue : (NSValue *)toValue
100- props : (const EaseViewProps &)props {
109+ props : (const EaseViewProps &)props
110+ loop : (BOOL )loop {
101111 [CATransaction begin ];
102112 [CATransaction setDisableActions: YES ];
103113 [self .layer setValue: toValue forKeyPath: keyPath];
@@ -106,7 +116,8 @@ - (void)applyAnimationForKeyPath:(NSString *)keyPath
106116 CAAnimation *animation = [self createAnimationForKeyPath: keyPath
107117 fromValue: fromValue
108118 toValue: toValue
109- props: props];
119+ props: props
120+ loop: loop];
110121 [self .layer addAnimation: animation forKey: animationKey];
111122}
112123
@@ -157,35 +168,40 @@ - (void)updateProps:(const Props::Shared &)props
157168 animationKey: kAnimKeyOpacity
158169 fromValue: @(newViewProps.initialAnimateOpacity)
159170 toValue: @(newViewProps.animateOpacity)
160- props: newViewProps];
171+ props: newViewProps
172+ loop: YES ];
161173 }
162174 if (newViewProps.initialAnimateTranslateX !=
163175 newViewProps.animateTranslateX ) {
164176 [self applyAnimationForKeyPath: @" transform.translation.x"
165177 animationKey: kAnimKeyTranslateX
166178 fromValue: @(newViewProps.initialAnimateTranslateX)
167179 toValue: @(newViewProps.animateTranslateX)
168- props: newViewProps];
180+ props: newViewProps
181+ loop: YES ];
169182 }
170183 if (newViewProps.initialAnimateTranslateY !=
171184 newViewProps.animateTranslateY ) {
172185 [self applyAnimationForKeyPath: @" transform.translation.y"
173186 animationKey: kAnimKeyTranslateY
174187 fromValue: @(newViewProps.initialAnimateTranslateY)
175188 toValue: @(newViewProps.animateTranslateY)
176- props: newViewProps];
189+ props: newViewProps
190+ loop: YES ];
177191 }
178192 if (newViewProps.initialAnimateScale != newViewProps.animateScale ) {
179193 [self applyAnimationForKeyPath: @" transform.scale.x"
180194 animationKey: kAnimKeyScaleX
181195 fromValue: @(newViewProps.initialAnimateScale)
182196 toValue: @(newViewProps.animateScale)
183- props: newViewProps];
197+ props: newViewProps
198+ loop: YES ];
184199 [self applyAnimationForKeyPath: @" transform.scale.y"
185200 animationKey: kAnimKeyScaleY
186201 fromValue: @(newViewProps.initialAnimateScale)
187202 toValue: @(newViewProps.animateScale)
188- props: newViewProps];
203+ props: newViewProps
204+ loop: YES ];
189205 }
190206 if (newViewProps.initialAnimateRotate != newViewProps.animateRotate ) {
191207 [self applyAnimationForKeyPath: @" transform.rotation.z"
@@ -194,7 +210,8 @@ - (void)updateProps:(const Props::Shared &)props
194210 newViewProps.initialAnimateRotate))
195211 toValue: @(degreesToRadians (
196212 newViewProps.animateRotate))
197- props: newViewProps];
213+ props: newViewProps
214+ loop: YES ];
198215 }
199216 } else {
200217 // No initial animation, set target values directly
@@ -221,37 +238,42 @@ - (void)updateProps:(const Props::Shared &)props
221238 animationKey: kAnimKeyOpacity
222239 fromValue: [self presentationValueForKeyPath: @" opacity" ]
223240 toValue: @(newViewProps.animateOpacity)
224- props: newViewProps];
241+ props: newViewProps
242+ loop: NO ];
225243 }
226244 if (oldViewProps.animateTranslateX != newViewProps.animateTranslateX ) {
227245 [self applyAnimationForKeyPath: @" transform.translation.x"
228246 animationKey: kAnimKeyTranslateX
229247 fromValue: [self presentationValueForKeyPath:
230248 @" transform.translation.x" ]
231249 toValue: @(newViewProps.animateTranslateX)
232- props: newViewProps];
250+ props: newViewProps
251+ loop: NO ];
233252 }
234253 if (oldViewProps.animateTranslateY != newViewProps.animateTranslateY ) {
235254 [self applyAnimationForKeyPath: @" transform.translation.y"
236255 animationKey: kAnimKeyTranslateY
237256 fromValue: [self presentationValueForKeyPath:
238257 @" transform.translation.y" ]
239258 toValue: @(newViewProps.animateTranslateY)
240- props: newViewProps];
259+ props: newViewProps
260+ loop: NO ];
241261 }
242262 if (oldViewProps.animateScale != newViewProps.animateScale ) {
243263 [self applyAnimationForKeyPath: @" transform.scale.x"
244264 animationKey: kAnimKeyScaleX
245265 fromValue: [self presentationValueForKeyPath:
246266 @" transform.scale.x" ]
247267 toValue: @(newViewProps.animateScale)
248- props: newViewProps];
268+ props: newViewProps
269+ loop: NO ];
249270 [self applyAnimationForKeyPath: @" transform.scale.y"
250271 animationKey: kAnimKeyScaleY
251272 fromValue: [self presentationValueForKeyPath:
252273 @" transform.scale.y" ]
253274 toValue: @(newViewProps.animateScale)
254- props: newViewProps];
275+ props: newViewProps
276+ loop: NO ];
255277 }
256278 if (oldViewProps.animateRotate != newViewProps.animateRotate ) {
257279 [self applyAnimationForKeyPath: @" transform.rotation.z"
@@ -260,7 +282,8 @@ - (void)updateProps:(const Props::Shared &)props
260282 @" transform.rotation.z" ]
261283 toValue: @(degreesToRadians (
262284 newViewProps.animateRotate))
263- props: newViewProps];
285+ props: newViewProps
286+ loop: NO ];
264287 }
265288 }
266289
0 commit comments