Native Animated - Add tests on iOS

Summary:
Adds unit tests to the Native Animated implementation on iOS. This pretty much mirrors the tests we currently have on Android.

It also fixes 2 bugs I've found when adding the tests and pass the current time in `stepAnimation` instead of using `CACurrentMediaTime` to make testing easier.

- `stopListeningToAnimatedNodeValue` did not actually work at all, it should set the listener to nil.
- The finished value in the animation end callback was always true, this simplifies the `RCTAnimationDriver` interface to get rid of `removeAnimation` and fixes the end callback value.

**Test plan**
- Run the tests
- Make sure the UIExplorer example still works
Closes https://github.com/facebook/react-native/pull/13068

Differential Revision: D4786701

Pulled By: javache

fbshipit-source-id: a4f07e6eec1f363ca47b6f27984041793c915bfc
This commit is contained in:
Janic Duplessis
2017-03-28 09:08:51 -07:00
committed by Facebook Github Bot
parent fb54a1eb3e
commit 1d37dd063c
13 changed files with 1069 additions and 73 deletions

View File

@@ -61,19 +61,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (void)startAnimation
{
_animationStartTime = CACurrentMediaTime();
_animationCurrentTime = _animationStartTime;
_animationStartTime = _animationCurrentTime = -1;
_animationHasBegun = YES;
}
- (void)stopAnimation
{
_animationHasFinished = YES;
}
- (void)removeAnimation
{
[self stopAnimation];
_valueNode = nil;
if (_callback) {
_callback(@[@{
@@ -82,14 +75,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
}
}
- (void)stepAnimation
- (void)stepAnimationWithTime:(NSTimeInterval)currentTime
{
if (!_animationHasBegun || _animationHasFinished || _frames.count == 0) {
// Animation has not begun or animation has already finished.
return;
}
NSTimeInterval currentTime = CACurrentMediaTime();
if (_animationStartTime == -1) {
_animationStartTime = _animationCurrentTime = currentTime;
}
_animationCurrentTime = currentTime;
NSTimeInterval currentDuration = _animationCurrentTime - _animationStartTime;
@@ -103,7 +99,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
// Update value and flag animation has ended.
NSNumber *finalValue = _frames.lastObject;
[self updateOutputWithFrameOutput:finalValue.doubleValue];
[self stopAnimation];
_animationHasFinished = YES;
return;
}