Fix the random test case failure because when running next test case, previous test case's animation does not stop

This commit is contained in:
DreamPiggy 2020-11-20 18:07:27 +08:00
parent 6ecc8c5541
commit 7a61a3339e
1 changed files with 12 additions and 0 deletions

View File

@ -641,11 +641,15 @@ static BOOL _isCalled;
player.playbackMode = SDAnimatedImagePlaybackModeReverse;
__block NSInteger i = player.totalFrameCount - 1;
__weak typeof(imageView) wimageView = imageView;
[player setAnimationFrameHandler:^(NSUInteger index, UIImage * _Nonnull frame) {
expect(index).equal(i);
expect(frame).notTo.beNil();
if (index == 0) {
[expectation fulfill];
// Stop Animation to avoid extra callback
[wimageView.player stopPlaying];
[wimageView removeFromSuperview];
return;
}
i--;
@ -678,6 +682,7 @@ static BOOL _isCalled;
__block NSInteger i = 0;
__block BOOL flag = false;
__block NSUInteger cnt = 0;
__weak typeof(imageView) wimageView = imageView;
[player setAnimationFrameHandler:^(NSUInteger index, UIImage * _Nonnull frame) {
expect(index).equal(i);
expect(frame).notTo.beNil();
@ -698,6 +703,9 @@ static BOOL _isCalled;
if (cnt > 3) {
[expectation fulfill];
// Stop Animation to avoid extra callback
[wimageView.player stopPlaying];
[wimageView removeFromSuperview];
}
}];
@ -729,6 +737,7 @@ static BOOL _isCalled;
__block NSInteger i = player.totalFrameCount - 1;
__block BOOL flag = false;
__block NSUInteger cnt = 0;
__weak typeof(imageView) wimageView = imageView;
[player setAnimationFrameHandler:^(NSUInteger index, UIImage * _Nonnull frame) {
expect(index).equal(i);
expect(frame).notTo.beNil();
@ -749,6 +758,9 @@ static BOOL _isCalled;
if (cnt > 3) {
[expectation fulfill];
// Stop Animation to avoid extra callback
[wimageView.player stopPlaying];
[wimageView removeFromSuperview];
}
}];
[player startPlaying];