Jack Fan
Jack Fan

Reputation: 2231

ImageView shared element transition (between Activity) starts with wrong scaleType

I found the problem with SimpleDraweeView of fresco at the beginning. However the problem still exists after I replace with android ImageView. So I can't be sure whether the problem is due to Android or just fresco.

What the problem is

  1. The first activity has recycled view and each view has a ImageView (or SimpleDraweeView). The wanted scaleType is "centerCrop"
  2. The second activity has only one ImageView. The wanted scaleType is "fitCenter"

However in my private project, and also in the sample project.
https://github.com/JackFan-Z/ActivitySharedElementTransition
The ImageView starts with scaleType "fitCenter", which is wrong.

I tried to postpone shared element transition and set different scaleType of shared element in the callbacks of SharedElementCallback. But none of them really works. Could anyone help figure out what goes wrong, or where to debug?

The screenshots of the issue

The screenshot of the first Activity:
enter image description here

The screenshot of transition:
enter image description here

Upvotes: 7

Views: 1431

Answers (1)

plamenko
plamenko

Reputation: 1088

As you observed with ImageView this is an Android limitation. However, I am doing some changes to Fresco scale types and it will be possible to do this once I push my changes.

In short, instead of ScaleType being an Enum (which is very inflexible), ScaleType is changed to be an interface that can be implemented to do arbitrary scaling. This change has been landed internally and will soon be pushed to GitHub.

In addition to the above, I am working on the implementation of InterpolatingScaleType that just interpolates between the two underlying scale types based on the interpolation value (0.0 - 1.0). Value of 0.0 returns the same transform as the underlying scaleType1, whereas value of 1.0 returns the same transform as the underlying scaleType2. Inbetween values are a linear combination between the two.

InterpolatingScaleType allows to smoothly interpolate between the two different scale types which is handy in animations such as when doing a view transition.

Once this is ready I will update this answer.

EDIT:

@burzumrus was kind enough to provide an implementation that you can find here on GitHub. There is also a thread on this issue on the Fresco's GitHub page.

Upvotes: 2

Related Questions