Skip to content

Commit

Permalink
Add ImageListener to FrescoVitoSlideshowComponentSpec
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D51055760

fbshipit-source-id: 88c3c1619b6f140ec7ffe44cabd2a78935364a0a
  • Loading branch information
Shyam Narayan authored and facebook-github-bot committed Nov 7, 2023
1 parent 303dbc1 commit 9a3c816
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.os.Handler
import android.os.Looper
import com.facebook.common.callercontext.ContextChain
import com.facebook.fresco.vito.core.FrescoDrawableInterface
import com.facebook.fresco.vito.listener.ImageListener
import com.facebook.fresco.vito.options.ImageOptions
import com.facebook.fresco.vito.provider.FrescoVitoProvider
import com.facebook.fresco.vito.source.ImageSourceProvider
Expand Down Expand Up @@ -68,6 +69,7 @@ object FrescoVitoSlideshowComponentSpec {
@Prop(optional = true) isPlaying: Boolean,
@Prop(optional = true) imageOptions: ImageOptions?,
@Prop(optional = true) callerContext: Any?,
@Prop(optional = true) imageListener: ImageListener?,
@TreeProp contextChain: ContextChain?,
@State(canUpdateLazily = true) slideshowIndex: Int,
@State(canUpdateLazily = true) timer: Timer,
Expand All @@ -90,7 +92,8 @@ object FrescoVitoSlideshowComponentSpec {
uris[slideshowIndex],
imageOptions,
callerContext,
contextChain)
contextChain,
imageListener)
// Immediately show current image
slideshowDrawable.fadeToNext()
slideshowDrawable.finishTransitionImmediately()
Expand All @@ -104,7 +107,8 @@ object FrescoVitoSlideshowComponentSpec {
uris[nextImageIndex],
imageOptions,
callerContext,
contextChain)
contextChain,
imageListener)

// Set up task for animating to next image
val animation: Runnable =
Expand All @@ -120,7 +124,8 @@ object FrescoVitoSlideshowComponentSpec {
imageOptions,
callerContext,
contextChain,
nextIndex)
nextIndex,
imageListener)
currentIndex = nextIndex
FrescoVitoSlideshowComponent.lazyUpdateSlideshowIndex(c, currentIndex)
}
Expand Down Expand Up @@ -160,7 +165,8 @@ object FrescoVitoSlideshowComponentSpec {
options: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?,
nextIndex: Int
nextIndex: Int,
listener: ImageListener?
) {
// Do not transition until both current and next images are available
if (isStillLoading(slideshowDrawable.currentImage) ||
Expand All @@ -171,7 +177,13 @@ object FrescoVitoSlideshowComponentSpec {
slideshowDrawable.fadeToNext()
// Fetch the next image ahead of time
fetchNextImage(
resources, slideshowDrawable, uris[nextIndex], options, callerContext, contextChain)
resources,
slideshowDrawable,
uris[nextIndex],
options,
callerContext,
contextChain,
listener)
}

private fun isStillLoading(frescoDrawable: FrescoDrawableInterface): Boolean =
Expand All @@ -183,7 +195,8 @@ object FrescoVitoSlideshowComponentSpec {
uri: Uri?,
options: ImageOptions?,
callerContext: Any?,
contextChain: ContextChain?
contextChain: ContextChain?,
listener: ImageListener?
) {
FrescoVitoProvider.getController()
.fetch(
Expand All @@ -193,7 +206,7 @@ object FrescoVitoSlideshowComponentSpec {
.createImageRequest(resources, ImageSourceProvider.forUri(uri), options),
callerContext = callerContext,
contextChain = contextChain,
listener = null,
listener = listener,
onFadeListener = null,
viewportDimensions = null)
}
Expand Down

0 comments on commit 9a3c816

Please sign in to comment.