Skip to content

Commit

Permalink
Adds OnBoundsDefined prefetching when force keeping original size
Browse files Browse the repository at this point in the history
Reviewed By: malmeida

Differential Revision: D63783639

fbshipit-source-id: e87cb8e748347cccc605f384ab7e7d842fbd94e6
  • Loading branch information
Veeren Mandalia authored and facebook-github-bot committed Oct 3, 2024
1 parent 767bdc5 commit fe96e94
Showing 1 changed file with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,25 @@ object FrescoVitoImage2Spec {
forceKeepOriginalSize.set(
FrescoVitoProvider.getImagePipeline().isInDiskCacheSync(requestCachedValue))
}
if (forceKeepOriginalSize.get() == true) {
// Prefetch in OnPrepare since no prefetch will happen in OnBoundsDefined
maybePrefetchInOnPrepare(
prefetch,
prefetchDataSource,
requestCachedValue,
callerContext,
contextChain,
prefetchRequestListener)
}
} else {
forceKeepOriginalSize.set(false)
val config = FrescoVitoProvider.getConfig().prefetchConfig
if (shouldPrefetchInOnPrepare(prefetch)) {
prefetchDataSource.set(
FrescoVitoProvider.getPrefetcher()
.prefetch(
config.prefetchTargetOnPrepare(),
requestCachedValue,
callerContext,
contextChain,
prefetchRequestListener,
"FrescoVitoImage2Spec_OnPrepare"))
}
maybePrefetchInOnPrepare(
prefetch,
prefetchDataSource,
requestCachedValue,
callerContext,
contextChain,
prefetchRequestListener)
}
}

Expand Down Expand Up @@ -405,6 +410,28 @@ object FrescoVitoImage2Spec {
else -> ImageSourceProvider.emptySource()
}

private fun maybePrefetchInOnPrepare(
prefetch: Prefetch?,
prefetchDataSource: Output<DataSource<Void?>>,
requestCachedValue: VitoImageRequest,
callerContext: Any?,
contextChain: ContextChain?,
prefetchRequestListener: RequestListener?
) {
val config = FrescoVitoProvider.getConfig().prefetchConfig
if (shouldPrefetchInOnPrepare(prefetch)) {
prefetchDataSource.set(
FrescoVitoProvider.getPrefetcher()
.prefetch(
config.prefetchTargetOnPrepare(),
requestCachedValue,
callerContext,
contextChain,
prefetchRequestListener,
"FrescoVitoImage2Spec_OnPrepare"))
}
}

@JvmStatic
fun shouldPrefetchInOnPrepare(prefetch: Prefetch?): Boolean =
when (prefetch ?: Prefetch.AUTO) {
Expand Down

0 comments on commit fe96e94

Please sign in to comment.