diff --git a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameLoader.java b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameLoader.java index 3fc10e5828..2d680d629c 100644 --- a/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameLoader.java +++ b/library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameLoader.java @@ -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; } diff --git a/library/test/src/test/java/com/bumptech/glide/load/resource/gif/GifFrameLoaderTest.java b/library/test/src/test/java/com/bumptech/glide/load/resource/gif/GifFrameLoaderTest.java index cf0cb94390..2e0e888463 100644 --- a/library/test/src/test/java/com/bumptech/glide/load/resource/gif/GifFrameLoaderTest.java +++ b/library/test/src/test/java/com/bumptech/glide/load/resource/gif/GifFrameLoaderTest.java @@ -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);