Skip to content

Commit

Permalink
Add static method for wrapping drawable factories
Browse files Browse the repository at this point in the history
Reviewed By: oprisnik

Differential Revision: D64253193
  • Loading branch information
Abbondanzo authored and facebook-github-bot committed Oct 16, 2024
1 parent b8151c5 commit dc0c49d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class KFrescoController(
drawableFactory?.createDrawable(r, a, b)?.let { createDrawableModel(it, b) }
}
}
?: run {
FLog.e(TAG, "Could not create Drawable for CloseableImage: $b")
null
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.facebook.fresco.vito.options.ImageOptionsDrawableFactory
import com.facebook.imagepipeline.drawable.DrawableFactory
import com.facebook.imagepipeline.image.CloseableImage

class DrawableFactoryWrapper(private val drawableFactory: DrawableFactory) :
class DrawableFactoryWrapper private constructor(private val drawableFactory: DrawableFactory) :
ImageOptionsDrawableFactory {
override fun createDrawable(
resources: Resources,
Expand All @@ -30,4 +30,15 @@ class DrawableFactoryWrapper(private val drawableFactory: DrawableFactory) :
} else {
null
}

companion object {
@JvmStatic
fun wrap(drawableFactory: DrawableFactory): ImageOptionsDrawableFactory {
return if (drawableFactory is ImageOptionsDrawableFactory) {
drawableFactory
} else {
DrawableFactoryWrapper(drawableFactory)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ class DefaultFrescoVitoProvider(
return if (animatedDrawableFactory == null) {
bitmapFactory
} else {
if (animatedDrawableFactory is ImageOptionsDrawableFactory) {
ArrayVitoDrawableFactory(bitmapFactory, animatedDrawableFactory)
} else {
ArrayVitoDrawableFactory(bitmapFactory, DrawableFactoryWrapper(animatedDrawableFactory))
}
ArrayVitoDrawableFactory(
bitmapFactory, DrawableFactoryWrapper.wrap(animatedDrawableFactory))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class KFrescoVitoProvider(
override fun getConfig(): FrescoVitoConfig = vitoConfig

private fun getFactory(): ImageOptionsDrawableFactory? {
return ImagePipelineFactory.getInstance().getAnimatedDrawableFactory(null)?.let {
DrawableFactoryWrapper(it)
}
return ImagePipelineFactory.getInstance()
.getAnimatedDrawableFactory(null)
?.let(DrawableFactoryWrapper::wrap)
}
}

0 comments on commit dc0c49d

Please sign in to comment.