Skip to content

Commit d838034

Browse files
oprisnikmeta-codesync[bot]
authored andcommitted
Honor EmptyImageSource.isExpectedEmpty in controllers
Differential Revision: D113540276 fbshipit-source-id: 8b435eec1780fe3cd5eb117040deb7daca92ba2b
1 parent dc3b90b commit d838034

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

vito/core-impl/src/main/java/com/facebook/fresco/vito/core/impl/KFrescoController.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import com.facebook.fresco.vito.source.BitmapImageSource
4242
import com.facebook.fresco.vito.source.ColorImageSource
4343
import com.facebook.fresco.vito.source.DrawableImageSource
4444
import com.facebook.fresco.vito.source.DrawableResImageSource
45+
import com.facebook.fresco.vito.source.EmptyImageSource
4546
import com.facebook.imagepipeline.image.CloseableBitmap
4647
import com.facebook.imagepipeline.image.CloseableImage
4748
import com.facebook.imagepipeline.image.CloseableStaticBitmap
@@ -236,6 +237,24 @@ class KFrescoController(
236237
setDrawableAsActualImage(drawable, resourceDrawable, imageRequest, imageId)
237238
return true
238239
}
240+
is EmptyImageSource -> {
241+
// Expected empty: caller opted in via `isExpectedEmpty` and the config flag is on. Route
242+
// through `onEmptyEvent` + placeholder — skipping the default fetch path where
243+
// `ImageSourceToImagePipelineAdapter.NO_REQUEST_SUPPLIER` produces an immediate failure
244+
// with `"No image request was specified!"`. The config read is the LAST condition so we
245+
// only exercise the new path when the source is genuinely expected-empty. Non-expected
246+
// empty sources fall through to today's failure path.
247+
if (source.isExpectedEmpty && config.handleExpectedEmptyImageSource()) {
248+
drawable.listenerManager.onEmptyEvent(callerContext)
249+
drawable.placeholderLayer.setPlaceholder(imageRequest.resources, options)
250+
drawable.listenerManager.onPlaceholderSet(
251+
imageId,
252+
imageRequest,
253+
drawable.placeholderLayer.getDataModel().maybeGetDrawable(),
254+
)
255+
return true
256+
}
257+
}
239258
}
240259

241260
// Check if the image is in cache

vito/core-java-impl/src/main/java/com/facebook/fresco/vito/core/impl/FrescoController2Impl.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,17 @@ open class FrescoController2Impl(
9595
FLog.e(TAG, "Drawable not supported $drawable")
9696
return false
9797
}
98-
// Fast path for null-URIs
99-
if (config.fastPathForEmptyRequests() && imageRequest.imageSource is EmptyImageSource) {
98+
// Fast path for null-URIs. Two entry points: (a) the existing global
99+
// `fastPathForEmptyRequests` toggle, or (b) a per-source opt-in via
100+
// `EmptyImageSource.isExpectedEmpty` (callers who know "no image" is the legitimate outcome and
101+
// want it counted as onEmptyEvent rather than onFailure). The config read is the LAST condition
102+
// so (b) only exercises the new path when the source is genuinely expected-empty.
103+
val emptySource = imageRequest.imageSource as? EmptyImageSource
104+
if (
105+
emptySource != null &&
106+
(config.fastPathForEmptyRequests() ||
107+
(emptySource.isExpectedEmpty && config.handleExpectedEmptyImageSource()))
108+
) {
100109
emptyRequestFastPath(drawable, imageRequest, callerContext)
101110
return true
102111
}

vito/core/src/main/java/com/facebook/fresco/vito/core/DefaultFrescoVitoConfig.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ constructor(override val prefetchConfig: PrefetchConfig = DefaultPrefetchConfig(
5252

5353
override fun fastPathForEmptyRequests(): Boolean = false
5454

55+
override fun handleExpectedEmptyImageSource(): Boolean = false
56+
5557
override fun enableWindowWideColorGamut(): Boolean = false
5658

5759
override fun handleImageResultInBackground(): Boolean = false

vito/core/src/main/java/com/facebook/fresco/vito/core/FrescoVitoConfig.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ interface FrescoVitoConfig {
4848

4949
fun fastPathForEmptyRequests(): Boolean
5050

51+
/**
52+
* When on, controllers honor [EmptyImageSource.isExpectedEmpty] and route "expected empty"
53+
* requests through the `onEmptyEvent` success-with-no-image callback path instead of firing
54+
* `onFailure` with `"No image request was specified!"`. Default off preserves legacy failure
55+
* semantics for all callers.
56+
*/
57+
fun handleExpectedEmptyImageSource(): Boolean = false
58+
5159
fun enableWindowWideColorGamut(): Boolean
5260

5361
fun handleImageResultInBackground(): Boolean

0 commit comments

Comments
 (0)