Status Update
Comments
ea...@gmail.com <ea...@gmail.com> #2
This actually has nothing to do with NavHostFragment, but is the behavior of NavController's setGraph().
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
When you call navController.setGraph(R.navigation.navigation_graph), it stores that ID and will restore that ID automatically.
If you were to instead use:
NavInflater navInflater = new NavInflater(this, navController.getNavigatorProvider());
navController.setGraph(navInflater.inflate(R.navigation.navigation_graph));
Then NavController would not restore the graph itself and the call to restoreState() you point out would only restore the back stack state, etc. but would wait for you to call setGraph again.
You're right that the inconsistency between the two setGraph methods is concerning. We'll take a look.
bo...@gmail.com <bo...@gmail.com> #3
Turns out, we already had a tracking bug for this issue, will follow up on that other one.
ad...@google.com <ad...@google.com>
ad...@google.com <ad...@google.com> #4
Thank you for promptly replying to my report. You are right that the issue you've just mentioned is similar to mine. I shall continue observing the progress over there.
il...@google.com <il...@google.com>
il...@google.com <il...@google.com>
jb...@google.com <jb...@google.com> #5
The underlying issue with hide shared element transitions has been addressed in https://issuetracker.google.com/issues/70793925 and it will be fixed in the Fragment 1.2.0-rc03 release for using Framework transitions. The corresponding change for the androidx Transition library will be in the 1.3.0-rc02 release.
With that working you will need to postpone the transition until after the RecyclerView has its views drawn, or the Fragment Library cannot find the view to do the shared element transition on.
See this blog post by Chris Banes that details this (https://chris.banes.dev/2018/02/18/fragmented-transitions/ ).
We have an open bug around documenting all of the steps to do shared element transitions in Fragments with RecyclerViews (https://issuetracker.google.com/issues/118928936 ).
Marking this as a duplicate of the hide transition issue.
With that working you will need to postpone the transition until after the RecyclerView has its views drawn, or the Fragment Library cannot find the view to do the shared element transition on.
See this blog post by Chris Banes that details this (
We have an open bug around documenting all of the steps to do shared element transitions in Fragments with RecyclerViews (
Marking this as a duplicate of the hide transition issue.
Description
Steps to reproduce the behaviour:
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
[...]
public class AppActivity extends AppCompatActivity
myFragment1.setSharedElementReturnTransition(new MyNewTransition());
myFragment1.setSharedElementEnterTransition(new MyNewTransition());
[...]
a) getSupportFragmentManager().beginTransaction()
.addSharedElement(myImage, "mytransition")
.replace(R.id.recycler_view_container, myFragment2)
.commit();
b) getSupportFragmentManager().beginTransaction()
.addSharedElement(myImage, "mytransition")
.add(R.id.recycler_view_container, myFragment2)
.hide(myFragment1)
commit();
In the (a) code, the image transition is correct and animation occurs perfectly between the shared elements, but I don't need this.
In the (b) code, the only difference is that myFragment1 is being hidden and the myFragment2 is added, in this case both the enter transition and the return transition are broken and no animation occurs.
I need the (b) code because "replace"-ing the fragments will destroy the myFragment1 and rebuilding it is a heavy-load process.
I think this is a bug with androidx libraries