mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-12 11:40:33 +08:00
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:
committed by
Facebook Github Bot
parent
fb54a1eb3e
commit
1d37dd063c
@@ -71,19 +71,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(@[@{
|
||||
@@ -92,13 +85,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stepAnimation
|
||||
- (void)stepAnimationWithTime:(NSTimeInterval)currentTime
|
||||
{
|
||||
if (!_animationHasBegun || _animationHasFinished) {
|
||||
// Animation has not begun or animation has already finished.
|
||||
return;
|
||||
}
|
||||
|
||||
if (_animationStartTime == -1) {
|
||||
_animationStartTime = _animationCurrentTime = currentTime;
|
||||
}
|
||||
|
||||
// We are using a fixed time step and a maximum number of iterations.
|
||||
// The following post provides a lot of thoughts into how to build this
|
||||
// loop: http://gafferongames.com/game-physics/fix-your-timestep/
|
||||
@@ -106,7 +103,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
// Velocity is based on seconds instead of milliseconds
|
||||
CGFloat step = TIMESTEP_MSEC / 1000;
|
||||
|
||||
NSTimeInterval currentTime = CACurrentMediaTime();
|
||||
NSInteger numSteps = floorf((currentTime - _animationCurrentTime) / step);
|
||||
_animationCurrentTime = currentTime;
|
||||
if (numSteps == 0) {
|
||||
@@ -182,7 +178,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
||||
[self onUpdate:_toValue];
|
||||
}
|
||||
|
||||
[self stopAnimation];
|
||||
_animationHasFinished = YES;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user