Skip to content

Commit

Permalink
Avoid IllegalArgumentException in GifFrameLoader.
Browse files Browse the repository at this point in the history
IllegalArgumentException is thrown when the target is invisible and
startFromFirstFrame is called and the target subsequently becomes visible.
  • Loading branch information
dalinaum committed May 13, 2020
1 parent 1caeff4 commit 1ae9a2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ void onFrameReady(DelayTarget delayTarget) {
// already incremented the frame pointer and can't decode the same frame again. Instead we'll
// just hang on to this next frame until start() or clear() are called.
if (!isRunning) {
pendingTarget = delayTarget;
if (startFromFirstFrame) {
handler.obtainMessage(FrameLoaderCallback.MSG_CLEAR, delayTarget).sendToTarget();
} else {
pendingTarget = delayTarget;
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,18 @@ public void onFrameReady_whenNotRunning_callsFrameReadyWithNewFrameOnStart() {
assertThat(loader.getCurrentFrame()).isEqualTo(expected);
}

@Test
public void onFrameReady_whenInvisible_setVisibleLater() {
loader = createGifFrameLoader(/*handler=*/ null);
// The target is invisible at this point.
loader.unsubscribe(callback);
loader.setNextStartFromFirstFrame();
DelayTarget loaded = mock(DelayTarget.class);
when(loaded.getResource()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));
loader.onFrameReady(loaded);
loader.subscribe(callback);
}

@Test
public void startFromFirstFrame_withPendingFrame_clearsPendingFrame() {
loader = createGifFrameLoader(/*handler=*/ null);
Expand Down

0 comments on commit 1ae9a2a

Please sign in to comment.