material-components / material-components/material-components-android

[transition: MaterialContainerTransform] Start view is fading out slowly after the activity is finished

Open
#1,760 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Feature: Transition
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Description:**

I'm using MaterialContainerTransform for transition between Activity B and Activity C.

**Start view:** Fab in Activity B.
**End view:** Root layout in Activity C.

Enter and return transition works well, but when `super.onBackPressed()` / `finishAfterTransition()` is called in Activity B, the start view is fading out slowly after Activity A is resumed.

---

![XLrCW7Ka2l](https://user-images.githubusercontent.com/51719518/94391218-8f7a7980-0172-11eb-9c2a-839205c32b96.gif)

---

**Expected behavior:** Fade animation for the start view should not occur,

**Source code:**

```java
public class ActivityA extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

...

binding.bottomAppBar.setOnMenuItemClickListener(item -> {
startActivity(new Intent(this, ActivityB.class)); //Starting Activity B.
return true;
});
}

}
```

```java
public class ActivityB extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Window window = getWindow();
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);

setExitSharedElementCallback(new MaterialContainerTransformSharedElementCallback());

super.onCreate(savedInstanceState);

...

//Starting Activity C.
binding.fab.setOnClickListener(v ->
startActivity(new Intent(this, ActivityC.class),
ActivityOptions.makeSceneTransitionAnimation(this, v, "transition_activity").toBundle())
);
}

}
```

```java
public class ActivityC extends AppCompatActivity {

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Window window = getWindow();
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS);

setEnterSharedElementCallback(new MaterialContainerTransformSharedElementCallback());

window.setSharedElementEnterTransition(createTransition());
window.setSharedElementReturnTransition(createTransition());

super.onCreate(savedInstanceState);

...
}

private MaterialContainerTransform createTransition() {
MaterialContainerTransform materialContainerTransform = new MaterialContainerTransform();

materialContainerTransform.addTarget(R.id.root);
materialContainerTransform.setDuration(350L);
materialContainerTransform.setAllContainerColors(Color.WHITE);

return materialContainerTransform;
}

}

```

**Additional info:**

If I set the transition name of the start view to null before calling `super.onBackPressed()` / `finishAfterTransition()`, this issue does not occur.

```java
@Override
public void onBackPressed() {
binding.fab.setTransitionName(null);
super.onBackPressed();
}
```

**Android API version:** 29

**Material Library version:** 1.3.0-alpha02

**Device:** Nokia 8.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the MaterialContainerTransformSharedElementCallback and the shared-element return transition configured in ActivityB and ActivityC. Reproduce the Activity B→C→B flow on Android API 29 using the supplied transition setup, then inspect when the start view is restored after the return. Done means the start view does not fade after Activity A resumes, while enter and return transitions still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.