Skip to content

Commit

Permalink
Set UI framework for Vito View component
Browse files Browse the repository at this point in the history
Reviewed By: kartavya-ramnani

Differential Revision: D65563999

fbshipit-source-id: d1702d2fd199167b09f16084c62ac11aa8b99e81
  • Loading branch information
oprisnik authored and facebook-github-bot committed Nov 11, 2024
1 parent 0510267 commit b532c53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ object VitoView {
imageListener: ImageListener?,
target: View,
onFadeListener: OnFadeListener? = null,
uiFramework: String = "view",
) {
VitoViewImpl2.show(
imageSource, imageOptions, callerContext, imageListener, null, target, onFadeListener)
imageSource,
imageOptions,
callerContext,
imageListener,
null,
target,
onFadeListener,
uiFramework)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ object VitoViewImpl2 {
imageRequestListener: VitoImageRequestListener?,
target: View,
onFadeListener: OnFadeListener? = null,
uiFramework: String = "view",
) {
show(
FrescoVitoProvider.getImagePipeline()
Expand All @@ -79,7 +80,8 @@ object VitoViewImpl2 {
imageListener,
imageRequestListener,
target,
onFadeListener)
onFadeListener,
uiFramework)
}

@JvmStatic
Expand All @@ -91,8 +93,9 @@ object VitoViewImpl2 {
imageRequestListener: VitoImageRequestListener?,
target: View,
onFadeListener: OnFadeListener? = null,
uiFramework: String = "view",
) {
val frescoDrawable = ensureDrawableSet(target)
val frescoDrawable = ensureDrawableSet(target, uiFramework)
// The Drawable might be re-purposed before being cleaned up, so we release if necessary.
val oldImageRequest = frescoDrawable.imageRequest
if (oldImageRequest != null && oldImageRequest != imageRequest) {
Expand Down Expand Up @@ -154,13 +157,13 @@ object VitoViewImpl2 {
* @param target the target to use
* @return The drawable to use for the given target
*/
private fun ensureDrawableSet(target: View): FrescoDrawableInterface {
private fun ensureDrawableSet(target: View, uiFramework: String): FrescoDrawableInterface {
return when (target) {
is ImageView ->
when (val current = target.drawable) {
is FrescoDrawableInterface -> current
else ->
createDrawable().also {
createDrawable(uiFramework).also {
// Force the Drawable to adjust its bounds to match the hosting ImageView's
// bounds, since Fresco has custom scale types that are separate from ImageView's
// scale type.
Expand All @@ -173,7 +176,10 @@ object VitoViewImpl2 {
else ->
when (val current = target.background) {
is FrescoDrawableInterface -> current
else -> createDrawable().also { ViewCompat.setBackground(target, it as Drawable) }
else ->
createDrawable(uiFramework).also {
ViewCompat.setBackground(target, it as Drawable)
}
}
}
}
Expand All @@ -182,9 +188,9 @@ object VitoViewImpl2 {
return (if (view is ImageView) view.drawable else view.background) as? FrescoDrawableInterface
}

private fun createDrawable(): FrescoDrawableInterface {
private fun createDrawable(uiFramework: String): FrescoDrawableInterface {
val frescoDrawable: FrescoDrawableInterface =
FrescoVitoProvider.getController().createDrawable()
FrescoVitoProvider.getController().createDrawable(uiFramework)
if (useVisibilityCallbacks.get()) {
frescoDrawable.setVisibilityCallback(
object : VisibilityCallback {
Expand Down

0 comments on commit b532c53

Please sign in to comment.