Added option to disable View visibility events for VitoView
Summary:
This change makes it possible to disable View Visibility events for VitoView.
For fetching / releasing the image, with this disabled, we only rely on VitoView.load(...) combined with View attached / detached events.
@@ -13,6 +13,8 @@ import android.view.View;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
+import com.facebook.common.internal.Supplier;
+import com.facebook.common.internal.Suppliers;
import com.facebook.drawee.drawable.VisibilityCallback;
import com.facebook.fresco.vito.core.FrescoDrawableInterface;
import com.facebook.fresco.vito.core.VitoImageRequest;
@@ -26,6 +28,12 @@ import com.facebook.infer.annotation.Nullsafe;
@Nullsafe(Nullsafe.Mode.LOCAL)
public class VitoViewImpl2 {
+ private static Supplier<Boolean> sUseVisibilityCallbacks = Suppliers.BOOLEAN_TRUE;
+
+ public static void setUseVisibilityCallbacks(Supplier<Boolean> useVisibilityCallbacks) {
+ sUseVisibilityCallbacks = useVisibilityCallbacks;
+ }
+
private static final View.OnAttachStateChangeListener mOnAttachStateChangeListenerCallback =
new View.OnAttachStateChangeListener() {
@Override
@@ -137,6 +145,7 @@ public class VitoViewImpl2 {
final FrescoDrawableInterface frescoDrawable =
FrescoVitoProvider.getController().createDrawable();
+ if (sUseVisibilityCallbacks.get()) {
frescoDrawable.setVisibilityCallback(
new VisibilityCallback() {
@Override
@@ -153,6 +162,7 @@ public class VitoViewImpl2 {
// NOP
}
});
+ }
return frescoDrawable;
}
}
