Native Animated - Fix timing animation delay on iOS
Summary: Delay was broken with native animations on iOS. After checking what android does to handle delay, I noticed it does nothing at all since the delay is already handled when generating the animation frames. This removes all code that tried to handle delay on iOS since it is not needed and breaks it. Also updated an example to have delay in UI explorer. Fixes #12388 **Test plan** Tested that delay works in UIExplorer on iOS and Android. Closes https://github.com/facebook/react-native/pull/12443 Differential Revision: D4582514 Pulled By: javache fbshipit-source-id: dc53295e716c8476c71ccd578380962f056de2be
This commit is contained in:
parent
bb48c0c608
commit
fb54a1eb3e
|
@ -352,12 +352,12 @@ exports.examples = [
|
|||
},
|
||||
},
|
||||
{
|
||||
title: 'Opacity without interpolation',
|
||||
title: 'Opacity with delay',
|
||||
render: function() {
|
||||
return (
|
||||
<Tester
|
||||
type="timing"
|
||||
config={{ duration: 1000 }}>
|
||||
config={{ duration: 1000, delay: 1000 }}>
|
||||
{anim => (
|
||||
<Animated.View
|
||||
style={[
|
||||
|
|
|
@ -289,7 +289,6 @@ class TimingAnimation extends Animation {
|
|||
type: 'frames',
|
||||
frames,
|
||||
toValue: this._toValue,
|
||||
delay: this._delay,
|
||||
iterations: this.__iterations,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ function createAndMountComponent(ComponentClass, props) {
|
|||
|
||||
describe('Native Animated', () => {
|
||||
|
||||
let nativeAnimatedModule = require('NativeModules').NativeAnimatedModule;
|
||||
const nativeAnimatedModule = require('NativeModules').NativeAnimatedModule;
|
||||
|
||||
beforeEach(() => {
|
||||
nativeAnimatedModule.addAnimatedEventToView = jest.fn();
|
||||
|
@ -276,7 +276,7 @@ describe('Native Animated', () => {
|
|||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
jasmine.any(Number),
|
||||
jasmine.any(Number),
|
||||
{type: 'frames', frames: jasmine.any(Array), toValue: jasmine.any(Number), delay: jasmine.any(Number), iterations: 1},
|
||||
{type: 'frames', frames: jasmine.any(Array), toValue: jasmine.any(Number), iterations: 1},
|
||||
jasmine.any(Function)
|
||||
);
|
||||
|
||||
|
@ -587,7 +587,7 @@ describe('Native Animated', () => {
|
|||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
jasmine.any(Number),
|
||||
jasmine.any(Number),
|
||||
{type: 'frames', frames: jasmine.any(Array), toValue: jasmine.any(Number), delay: jasmine.any(Number), iterations: 1},
|
||||
{type: 'frames', frames: jasmine.any(Array), toValue: jasmine.any(Number), iterations: 1},
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
@ -666,7 +666,7 @@ describe('Native Animated', () => {
|
|||
expect(nativeAnimatedModule.startAnimatingNode).toBeCalledWith(
|
||||
jasmine.any(Number),
|
||||
jasmine.any(Number),
|
||||
{type: 'frames', frames: jasmine.any(Array), toValue: jasmine.any(Number), delay: jasmine.any(Number), iterations: 1},
|
||||
{type: 'frames', frames: jasmine.any(Array), toValue: jasmine.any(Number), iterations: 1},
|
||||
jasmine.any(Function)
|
||||
);
|
||||
const animationId = nativeAnimatedModule.startAnimatingNode.mock.calls[0][0];
|
||||
|
|
|
@ -33,7 +33,6 @@ const double SINGLE_FRAME_INTERVAL = 1.0 / 60.0;
|
|||
NSArray<NSNumber *> *_frames;
|
||||
CGFloat _toValue;
|
||||
CGFloat _fromValue;
|
||||
NSTimeInterval _delay;
|
||||
NSTimeInterval _animationStartTime;
|
||||
NSTimeInterval _animationCurrentTime;
|
||||
RCTResponseSenderBlock _callback;
|
||||
|
@ -46,14 +45,12 @@ const double SINGLE_FRAME_INTERVAL = 1.0 / 60.0;
|
|||
{
|
||||
if ((self = [super init])) {
|
||||
NSNumber *toValue = [RCTConvert NSNumber:config[@"toValue"]] ?: @1;
|
||||
NSTimeInterval delay = [RCTConvert double:config[@"delay"]];
|
||||
NSArray<NSNumber *> *frames = [RCTConvert NSNumberArray:config[@"frames"]];
|
||||
|
||||
_animationId = animationId;
|
||||
_toValue = toValue.floatValue;
|
||||
_fromValue = valueNode.value;
|
||||
_valueNode = valueNode;
|
||||
_delay = delay;
|
||||
_frames = [frames copy];
|
||||
_callback = [callback copy];
|
||||
}
|
||||
|
@ -93,16 +90,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|||
}
|
||||
|
||||
NSTimeInterval currentTime = CACurrentMediaTime();
|
||||
NSTimeInterval stepInterval = currentTime - _animationCurrentTime;
|
||||
_animationCurrentTime = currentTime;
|
||||
NSTimeInterval currentDuration = _animationCurrentTime - _animationStartTime;
|
||||
|
||||
if (_delay > 0) {
|
||||
// Decrement delay
|
||||
_delay -= stepInterval;
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine how many frames have passed since last update.
|
||||
// Get index of frames that surround the current interval
|
||||
NSUInteger startIndex = floor(currentDuration / SINGLE_FRAME_INTERVAL);
|
||||
|
|
Loading…
Reference in New Issue