Set frescoDrawable when view is re-attached
@@ -56,30 +56,6 @@ public class VitoViewImpl implements VitoView.Implementation {
Preconditions.checkArgument(
!(uri != null && multiUri != null), "Setting both a Uri and MultiUri is not allowed!");
- FrescoDrawable frescoDrawable;
- final Drawable background = target.getBackground();
- if (background instanceof FrescoDrawable) {
- frescoDrawable = (FrescoDrawable) background;
- } else {
- frescoDrawable = new FrescoDrawable(true);
- ViewCompat.setBackground(target, frescoDrawable);
- }
-
- frescoDrawable.setVisibilityCallback(
- new VisibilityCallback() {
- @Override
- public void onVisibilityChange(boolean visible) {
- if (!visible) {
- onDetach(target);
- }
- }
-
- @Override
- public void onDraw() {
- // NOP
- }
- });
-
final FrescoState oldState = getState(target);
final FrescoState state =
mFrescoContext
@@ -92,7 +68,6 @@ public class VitoViewImpl implements VitoView.Implementation {
callerContext,
target.getResources(),
imageListener);
- state.setFrescoDrawable(frescoDrawable);
setState(target, state);
// `addOnAttachStateChangeListener` is not idempotent
@@ -111,8 +86,38 @@ public class VitoViewImpl implements VitoView.Implementation {
}
}
+ private FrescoDrawable createFrescoDrawable(final View target) {
+ FrescoDrawable frescoDrawable;
+ final Drawable background = target.getBackground();
+ if (background instanceof FrescoDrawable) {
+ frescoDrawable = (FrescoDrawable) background;
+ } else {
+ frescoDrawable = new FrescoDrawable(true);
+ ViewCompat.setBackground(target, frescoDrawable);
+ }
+
+ frescoDrawable.setVisibilityCallback(
+ new VisibilityCallback() {
+ @Override
+ public void onVisibilityChange(boolean visible) {
+ if (!visible) {
+ onDetach(target);
+ }
+ }
+
+ @Override
+ public void onDraw() {
+ // NOP
+ }
+ });
+ return frescoDrawable;
+ }
+
private void onAttach(View view) {
- onAttach(getState(view));
+ FrescoDrawable frescoDrawable = createFrescoDrawable(view);
+ FrescoState state = getState(view);
+ state.setFrescoDrawable(frescoDrawable);
+ onAttach(state);
}
private void onDetach(View view) {
