Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share Element Gone after do SharedElementReturnTransition in Android N #1445

Open
changety opened this issue Aug 31, 2016 · 70 comments
Open
Assignees

Comments

@changety
Copy link

I use the newest fresco code for doing SharedElement Transition work, it runs well in Android L、M, But on Android N, it goes wrong

before transition
screenshot0

after transition
screenshot0

@aagnes-zz aagnes-zz added the needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem) label Sep 2, 2016
@aagnes-zz
Copy link
Contributor

Can you please show how you do the transition part using Fresco's demo app?

@changety
Copy link
Author

activity_main.xml and activity_detail� has same SimpleDraweeView with same transitionName
and in DetailActivity’s onCreate method as below:

protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setSharedElementEnterTransition(DraweeTransition.createTransitionSet(ScalingUtils.ScaleType.CENTER_CROP, ScalingUtils.ScaleType.FIT_CENTER));
getWindow().setSharedElementReturnTransition(DraweeTransition.createTransitionSet(ScalingUtils.ScaleType.FIT_CENTER, ScalingUtils.ScaleType.CENTER_CROP));
addTransitionListener();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
mBaselineJpegView = (SimpleDraweeView) findViewById(R.id.baseline_jpeg);
mBaselineJpegView.setImageURI(Uri.parse("https://www.gstatic.com/webp/gallery/1.sm.jpg"));
mBaselineJpegView.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View v) {
Toast.makeText(DetailActivity.this, "dsasa", Toast.LENGTH_LONG).show();
}
});
}

addTransitionListener() does nothing just print log

so do I use wrong way to do the transition? �

@raylee4204
Copy link

raylee4204 commented Oct 13, 2016

This is happening to me as well.

I have the following in onCreate() method before super.onCreate()

supportRequestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS);
Transition fade = new Fade();
fade.excludeTarget(android.R.id.statusBarBackground, true);
fade.excludeTarget(android.R.id.navigationBarBackground, true);
Window window = getWindow();
window.setEnterTransition(fade);
window.setReturnTransition(fade);
window.setExitTransition(fade);
TransitionSet transitionSet = DraweeTransition
                    .createTransitionSet(ScalingUtils.ScaleType.CENTER_CROP,
ScalingUtils.ScaleType.CENTER_CROP);
window.setSharedElementEnterTransition(transitionSet);
window.setSharedElementExitTransition(transitionSet);

@oprisnik oprisnik added the bug label Oct 13, 2016
@mihaicristianpetrescu
Copy link

I'm experiencing the same issue. The setSharedElementReturnTransition is not working on Android N. I've added logs to the transition listeners and the onTransitionStart and onTransitionEnd are not triggered on Android N, but on Android M & L it works just fine.
I'm using the latest version of the Fresco library com.facebook.fresco:fresco:0.14.1 with com.facebook.fresco:imagepipeline-okhttp3:0.14.1
I don't have this issue if I use Picasso library for loading the image.
The scenario is similar: gridView, gridItem navigates away to another Activity (everything is fine on this part) but when I go back, there is no reenter, the image flashes and is reloaded (the placeholder image is not visible nor the image that was already loaded). This only happens on Android N (7.0)

@raylee4204
Copy link

Any update on this issue?

@mihaicristianpetrescu
Copy link

Switched from Fresco to Picasso and the issue is resolved. Too bad this library isn't maintained as often as required by the new Android OS versions that come out.

@SanderTuit
Copy link

It seems that this issue is incorrectly marked as 'needs-details'. This problem also exists on Android 7.1.1 (API level 25).

@oprisnik oprisnik removed the needs-details This issue or PR is currently not actionable as it misses details (e.g. for reproducing the problem) label Dec 13, 2016
@oprisnik
Copy link
Contributor

Thanks, we'll take a look

@oprisnik oprisnik self-assigned this Dec 13, 2016
@tnache
Copy link

tnache commented Jan 24, 2017

I am also experiencing the same problem, so +1 from me for fixing it.

@copa
Copy link

copa commented Jan 25, 2017

same here

@sbo3000
Copy link

sbo3000 commented Jan 25, 2017

Do it. Do it. ;-)

@cyrata
Copy link

cyrata commented Jan 26, 2017

Yes, please do it.

@pinkred
Copy link

pinkred commented Feb 7, 2017

Please...

@aldasa
Copy link

aldasa commented Feb 27, 2017

+1

@raylee4204
Copy link

Wonder why this isn't a high priority..

@zhuitian90
Copy link

+1

@stanmots
Copy link

When I scroll to the shared element position in onActivityReenter the disappeared item is coming back though with a little white flickering:

    @Override
    public void onActivityReenter(int resultCode, Intent data) {
        super.onActivityReenter(resultCode, data);

        final int position = data.getIntExtra(EXTRA_GIF_POSITION, -1);
        if (resultCode == RESULT_OK && position != -1) {
            gifRecyclerView.getLayoutManager().scrollToPosition(position);
        }
    }

If someone knows a better fix I would appreciate if you could share it.

@dimivrn
Copy link

dimivrn commented Mar 14, 2017

Hello, i am experiencing the same issue but only on Android 7.1.1 API 25

If there are any updates about the issue i would highly appreciate it.

@FioneraGH
Copy link

same here on emu with 7.x, but I use onWindowFocusChanged be immersive, when finish occured the image will disappear but reshow instantly.

@bblackbelt
Copy link

Same here. Calling requestLayout on the View containing the SimpleDraweeView seems fixing it with some flickering. Please advise

@ibyxz
Copy link

ibyxz commented Mar 28, 2017

Just add this code in calling activity,+1 if this can help you!!! @oprisnik


setExitSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames,
                                           List<View> sharedElements,
                                           List<View> sharedElementSnapshots) {

                super.onSharedElementEnd(sharedElementNames, sharedElements,
                        sharedElementSnapshots);
                
                for (View view : sharedElements) {
                    if (view instanceof SimpleDraweeView) {
                        view.setVisibility(View.VISIBLE);
                    }
                }
            }
        });

@mengoni
Copy link

mengoni commented Apr 26, 2017

same problem here... @antxyz I've put your code in both calling and callee activities onCreate method but with no success. The shared element image is still invisible after returning transition.

@mengoni
Copy link

mengoni commented Apr 26, 2017

I don't know If it can help to find a solution, but I noticed that when softkeyboard is opened, the SimpleDraweeView become visible.

@fernando-jascovich
Copy link

fernando-jascovich commented May 22, 2017

I was having the same problem and it was fixed after this two calls:

  1. Just before startActivity(...:
	setExitSharedElementCallback(new SharedElementCallback() {
				@Override
				public void onSharedElementEnd(List<String> names,
											   List<View> elements,
											   List<View> snapshots) {
					super.onSharedElementEnd(names, elements, snapshots);
					for (final View view : elements) {
						if (view instanceof SimpleDraweeView) {
							view.post(() ->	view.setVisibility(View.VISIBLE));
						}
					}
				}
			});
  1. Inside the onCreate of the new activity:
setEnterSharedElementCallback(new SharedElementCallback() {
				@Override
				public void onSharedElementEnd(List<String> names,
											   List<View> elements,
											   List<View> snapshots) {
					super.onSharedElementEnd(names, elements, snapshots);
					for (final View view : elements) {
						if (view instanceof SimpleDraweeView) {
							view.post(() -> view.setVisibility(View.VISIBLE));
						}
					}
				}
			});

@luckyleongao
Copy link

@oprisnik I finally found the cause of my problem.
In case of misunderstanding other people, I'm here to give some explanations.
My issue has sth to do with the picture format.
If I use the method imageRequestBuilder.setProgressiveRenderingEnabled(true) with PNG format, my issue can always reproduce.
If I change the method to imageRequestBuilder.setProgressiveRenderingEnabled(false) with PNG format, everything works fine.
@oprisnik Thanks again for your patience!

@Fab-z4qx
Copy link

Please fix this issue...

@asos-davidf
Copy link

asos-davidf commented Apr 24, 2018

Fresco 1.9.0 doesn't fix the issue properly.
A mix of the propositions in this thread fixes it depending on the device:

So I'm using both workarounds in my code to be safe in my code and hopefully that covers everything. @oprisnik I'll spend some time to try and understand the problem better, if I find a fix I'll submit a PR.

@oprisnik
Copy link
Contributor

Yeah, unfortunately we still don't have a good fix for this issue since all solutions mentioned in this thread fail in one or the other way. If somebody has an idea on how to properly fix this, please let us know or, even better, submit a PR :)

@Fab-z4qx
Copy link

Still, this issue on react-native-maps component. I imagine it's a concurrent problem?
Do you have any idea of where is the problem?

@willbattel
Copy link

Any progress on pinpointing the issue? Seems we haven't hear anything since April.

@oprisnik
Copy link
Contributor

We still did not have time to further investigate what's going on here. Feel free to look into the issue and submit a pull request!

@oprisnik
Copy link
Contributor

oprisnik commented Jul 10, 2018

As mentioned earlier, the underlying issue seems to be an Android framework bug where ImageView doesn't properly restore the visibility of the underlying Drawable when returning from the transition.

I've filed an Android bug report here: https://issuetracker.google.com/issues/111293868

I've also created a (non-Fresco) sample app that outlines the issue: https://github.com/oprisnik/VisibilityPlayground

We'll investigate if there is a workaround for this issue. However, Fresco requires manual memory management and we rely on the Drawable visibility to re-request the image, so I'm not sure if there is a better fix than the workarounds described above.

@Crysis21
Copy link
Contributor

I switched to fresco not being aware of this issue. I render a ton of gifs and it does a great job, but I'm also dependent on these animations for navigation. I've been able to use the above mentioned hacks, but on a return animation, the image will disappear.

@RainFool
Copy link

Actually invalidate or View.setVisibility can not show drawable, you need call Drawable.setVisible(true, true) directly .
I add these codes in A Activity#OnCreate,it works fine:

ActivityCompat.setExitSharedElementCallback(this, new SharedElementCallback() {
            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
                if (FP.empty(sharedElements)) {
                    return;
                }
                for (View view : sharedElements) {
                    if (view instanceof SimpleDraweeView) {
                        ((SimpleDraweeView) view).getDrawable().setVisible(true, true);
                    }
                }
            }
        });

saied89 added a commit to saied89/DVDPrism that referenced this issue Dec 18, 2018
@grahammendick
Copy link

@oprisnik In your non-fresco sample app you set the transition to ChangeBounds. Does the bug happen if you remove this line? I guess the visibility is restored correctly when the ChangeImageTransform is in play. Is it possible to get fresco images to work with the ChangeImageTransform?

grahammendick added a commit to grahammendick/navigation that referenced this issue Jan 4, 2019
This was the fix for animating fresco images as per https://frescolib.org/docs/shared-transitions.html. But turns out they still don't work because of fresco/android bug, facebook/fresco#1445 and https://issuetracker.google.com/issues/111293868 (tried the workaround in the fresco bug but they didn't work). So backing it out and not supporting shared images for the first release. Will revisit when fresco/android fix the problem
@bu2zhouzhu
Copy link

@RainFool is right. simpleDraweeView.getVisibility() is VISIBLE, but simpleDraweeView.getDrawable().isVisible() is false.

@oprisnik
Copy link
Contributor

Yes, this is a bug in the Android framework where the View visibility (ImageView to be precise) is not propagated to the Drawable, so you have to manually update visibility. Please star the Android bug report here so that this gets more visibility: https://issuetracker.google.com/issues/111293868

facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Jun 19, 2023
Summary:
Adds support for Android Transitions during Fragment navigation.

React Native navigation libraries (like [the Navigation router](https://github.com/grahammendick/navigation/blob/e9deae985a1962db17d6b1fbf90628d20c29810c/NavigationReactNative/src/android/src/main/java/com/navigation/reactnative/NavigationStackView.java#L139) and [React Native Screens](https://github.com/software-mansion/react-native-screens/blob/ea240b46866d66398904d0c2d0fe5fabdc2f269b/android/src/main/java/com/swmansion/rnscreens/ScreenContainer.kt#L98)) use Fragments to manage the stack of screens. But they can’t use Transitions to animate these Fragments because React Native images disappear during the Transition (see the videos in the Test Plan section below).

Navigation libraries are forced to [setCustomAnimations](https://developer.android.com/reference/androidx/fragment/app/FragmentTransaction.html#setCustomAnimations(int,int)) instead of [enter and exit Transitions](https://developer.android.com/reference/android/app/Fragment#setEnterTransition(android.transition.Transition)). But animations have limitations compared to Transitions

- Animations have to be resx files so can’t be defined declaratively in React
- Android’s Material Transforms are built around Transitions
- Native shared elements only support Transitions

Images disappearing during Transitions is [a known Fresco bug](facebook/fresco#2512). This PR applies [the fix suggested by the Fresco repo](facebook/fresco#1445 (comment)).

## Changelog:

[ANDROID] [FIXED] - Support Android Transitions during Fragment navigation

Pull Request resolved: #37857

Test Plan:
I’ve created a [minimal reproduction that demonstrates the bug](https://github.com/grahammendick/image-disappears-during-transition-bug). The first video below shows the example from that repo. You can see that the image disappears when changing the painting. It should fade out and in like the text does.

The second video shows the same example after the fix is applied. You can see that the painting fades out and in just like the text.

https://github.com/facebook/react-native/assets/1761227/6739f029-eda0-44d2-b328-a73b075bd82a

https://github.com/facebook/react-native/assets/1761227/9c73cdf0-303b-4a82-8df5-5f6a5846a58e

Reviewed By: javache

Differential Revision: D46769995

Pulled By: dmytrorykun

fbshipit-source-id: 0ced8af7b246d8c59cbfb5cabf422114c6154c65
tungdo194 pushed a commit to tungdo194/rn-test that referenced this issue Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests