Shared element transition
Shared element transition doesn't seem to work.
Tested in a motorola device with android 5.0
Can you give us more details? What exactly did you try to do, and what happened instead?
In the new android version, lollipop, we can use an ImageView as a shared element transition between activities. In that case the image make a smoth transition from one activity to the next one. When using the SimpleDraweeView it just disappear.
The code to test it should be something like this:
theme of the app:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
</style>
Activity1 Layout.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image"
android:layout_width="@dimen/size_1"
android:layout_height="@dimen/size_1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
Activity2 Layout.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/image"
android:layout_width="@dimen/size_2"
android:layout_height="@dimen/size_2"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:transitionName="image_transition"/>
</RelativeLayout>
The code to start the second activity:
Intent intent = new Intent(activity1, Activity2.class);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(activity1, simpleDraweeView1, "image_transition");
activity1.startActivity(intent, options.toBundle());
This code should make a transition between the activities where the image moves and resizes from the top left corner of the activity 1 to the bottom right corner of the activity 2. I have tested a similar code loading images from the network and it does not display the animation.
I think this is realted too https://github.com/facebook/fresco/issues/99
I suspect this has to do with attach/detach events that view gets when in transition. We'll have to investigate that.
This is something I can confirm as well. Shared Element transitions seem to be broken on Fresco. It would be great if we could get this fixed, as this is a very important feature moving forward.
Happened to me too. When setting transtitionName xml attr to SimpleDraweeView, setImageUri() method stopped working
Any updates on this ?
After the FadeDrawable finished animate real image, there is a log: com.facebook.samples.comparison D/ViewRootImpl﹕ changeCanvasOpacity: opaque=false
maybe the changeCanvasOpacity cause the image not draw.
Is the bug fixed? It's very significant for my project as well. :)
package org.goodev.droidddle.drawee;
import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.view.SimpleDraweeView;
import android.content.Context; import android.graphics.Matrix; import android.util.AttributeSet;
public class TranslateDraweeView extends SimpleDraweeView { public TranslateDraweeView(Context context) { super(context); }
public TranslateDraweeView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TranslateDraweeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public TranslateDraweeView(Context context, GenericDraweeHierarchy hierarchy) {
super(context, hierarchy);
}
// looks like overwrite this method can fix this issue
// but still don't figure out why
public void animateTransform(Matrix matrix) {
invalidate();
}
}
@goodev there's not such a method to overwrite.
@shumin0809 just add this method, this is a hide public method for the transition.
I am seeing different, but still buggy behaviour with SharedElementTransitions. Don't know if this is the same, related, or separate issue.
_Reproduction_ Pretty standard setup for a SharedElementTransition:
- RecyclerView in a fragment with GridLayoutManager displaying lots of images as SimpleDraweeViews, setting transitionName on them dynamically in the viewholder bind method (where I am also setting the uri)
- OnClick fire a transition to a different fragment with a single SimpleDrawee view and the same transitionName also set dynamically
_Expected_ As for normal ImageViews (provided scaleType matches), seamless animation of shared resource between fragments
_Observed_ SharedElementTransition occurs but there is a flicker before the target image appears (seems that the target image isn't set early enough)
_Notes_ I have tried loading images from web and disk, and the image is loaded and in the cache before launching the transition. The target fragment's code is pulling the exact same uri. I fiddled around trying to use the pipeline directly (and learned a lot) but failed to affect the result.
_Setup_ Devices: Nexus 5 & Nexus 7 (2013), both running Android 5.1.1 (API 22) Up to date library and tools: fresco (0.5.0), Android Studio (1.3 Preview 3 EAP.0), compileSdk (22), build tools (22.0.1)
_Realisations_ While writing this post I've noticed 2 things that might be relevant:
- The two Drawees are different sizes (this is not a problem for transitioning standard ImageViews and I don't remember anything about pre-fetching that sets the target dimensions)
- From memory I think I am passing fresco the fragments as Context somewhere in the code, perhaps meaning the two fragments each have their own cache??
@jorgemf - Doesn't your posted code need a matching transitionName attribute set in the Activity 1 layout? https://developer.android.com/training/material/animations.html
_Start an activity with a shared element_ ... 4 - Assign a common name to the shared elements in both layouts with the android:transitionName attribute.
For my issue it might just be that I need to postpone the transition. I'll have a look at this today: http://www.androiddesignpatterns.com/2015/03/activity-postponed-shared-element-transitions-part3b.html
I'm with the same problem. I using fresco 0.5.3 and SimpleDraweeView not load image with attr "android:transitionName". Anybody know outher solution using Fresco?
@jorgemf If you set "android-background" in your Activity1 Layout.xml, it work not perfectly, but will work. I set in my test it: android:background="@android:color/transparent"
@LuizGadao If you set a background you lose all the advantages of the library. I think it is pointless as you want it for images downloaded from internet. Not for static resources as a background. After testing some libraries, picasso is working fine for me. No problems at all.
@jorgemf I agree with you. It is only a hack for do it work.
Any news on this one?
@LuizGadao can you post an example of your workaround XML?