Skip to content

Commit bc5f563

Browse files
Abbondanzometa-codesync[bot]
authored andcommitted
Drop Drawee from Android background image loading
Summary: The `url()` background image loader used Drawee only to reach the image pipeline and to defer releasing a bitmap. It now gets the same pipeline from `ImagePipelineFactory`, and releases the bitmap on the next main-thread turn, which is what the Drawee releaser does on the UI thread. Background images now depend on the image pipeline alone. Changelog: [Internal] Differential Revision: D135152979
1 parent 80c03ca commit bc5f563

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/drawable/BackgroundImageURLLoader.kt‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import com.facebook.common.logging.FLog
1515
import com.facebook.common.references.CloseableReference
1616
import com.facebook.datasource.BaseDataSubscriber
1717
import com.facebook.datasource.DataSource
18-
import com.facebook.drawee.backends.pipeline.Fresco
19-
import com.facebook.drawee.components.DeferredReleaser
2018
import com.facebook.fresco.middleware.HasExtraData
2119
import com.facebook.imagepipeline.common.ImageDecodeOptions
20+
import com.facebook.imagepipeline.core.ImagePipelineFactory
2221
import com.facebook.imagepipeline.image.CloseableImage
2322
import com.facebook.imagepipeline.image.CloseableStaticBitmap
2423
import com.facebook.imagepipeline.request.ImageRequestBuilder
24+
import com.facebook.react.bridge.UiThreadUtil
2525
import com.facebook.react.common.ReactConstants
2626
import com.facebook.react.uimanager.style.BackgroundImageLayer
2727
import com.facebook.react.views.imagehelper.ImageSource
@@ -123,7 +123,10 @@ internal class BackgroundImageURLLoader(
123123
FLog.w(ReactConstants.TAG, e, "Invalid background image uri: %s", uri)
124124
return
125125
}
126-
val dataSource = Fresco.getImagePipeline().fetchDecodedImage(imageRequest, CALLER_CONTEXT)
126+
val dataSource =
127+
ImagePipelineFactory.getInstance()
128+
.imagePipeline
129+
.fetchDecodedImage(imageRequest, CALLER_CONTEXT)
127130
this.dataSource = dataSource
128131
dataSource.subscribe(
129132
object : BaseDataSubscriber<CloseableReference<CloseableImage>>() {
@@ -188,9 +191,7 @@ internal class BackgroundImageURLLoader(
188191
this.imageReference = null
189192
// The last frame drawn can still use the bitmap, so release it after that frame, like
190193
// Fresco's drawee.
191-
DeferredReleaser.getInstance().scheduleDeferredRelease {
192-
CloseableReference.closeSafely(imageReference)
193-
}
194+
UiThreadUtil.runOnUiThread { CloseableReference.closeSafely(imageReference) }
194195
}
195196
}
196197
}

0 commit comments

Comments
 (0)