I'm doing a nav graph in an Android project where I have a number of fragments - let's just assume for now that I have 3 (fragment A, B and C).
I have navigation actions between the fragment like this: A -> B, B -> C, and finially a global action always just pointing to A (Since the app is way bigger than 3 fragments and fragment A is a start screen, so it makes sense to have a global action going back to the start screen).
From fragment C I can go back to A with the global action (which is also using popUpTo and Inclusive, to clear the backstack totally).
Now the issue - I'm using transition animations when transitioning between the fragments and they work - except for the global action where I'm using popUpTo. I wish to use a from_left and to_right animation as enter/exit, which works exactly as intended on other fragments, but for the global action the exit animation is wrong (looks kinda like the fragment is moving out to the left of the screen instead of out to the right).
The weird thing is: If I set the popUpTo behaviour to "none", it works perfectly fine, animation plays as intended.
So, is there something one should be aware of about transition animations when using popUpTo in the nav graph?
Related
I have a feature as a module which consist of 3 fragments.
After User navigates to the 3'd fragment, there is a computation, when computation succeeds -> User should be navigated to the Home screen which is in the parent nav graph.
I've tried a lot of approaches, but nothing seem to work correctly, is there a way to finish current navigation graph and return to the parent graph?
Things I've tried:
Navigation to the home with a help of deeplink. Not a bad option, but it messes with backStack, and it is not user friendly in case feature will be exposed to different clients.
Navigating to the start destination with cleaning of the backstack and after navigateUp. Better option than the first, but still...
General:
I have my app consisting of the activity and several fragments. I am using the Navigation Graph to move through the various fragments. I have the ability to rotate the device and therefore have different layouts.
Problem:
I know from fragment A I go to fragment B and I rotate the phone, I go back to fragment A
First partial solution:
From the documentation I took what could have been the solution, which however turned out to be only a partial solution. in fact I read that to prevent problems during rotation I could use the following parameters:
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
This would seem to solve the rotation problem but it creates a new one: landscape layouts are not updated to the size they should have.
How can I completely remedy the problem?
It doesn't matter if you need to get your hands dirty in the code or just add another parameter in the manifest, I would like to understand what is wrong
Example:
bottom navigation -> TabA (entrypoint);
TabB,
TabC.
I click on Tab B -> then clicking inside I will go to fragment B1 (from corrent tab B). So I rotate phone and I will go again to Tab B instead fragment B1
When the phone rotate, the activity is recreated, so I suppose that you activity is starting again from the entry point fragment. You can use ViewModel to persist the actual fragment reference and inflate it again on OnResume method of the Activity who hold the fragments.
I'm using the SupportFragmentManager to navigate between different fragments (let's call them A, B, C, D for simplicity). The navigation itself works correctly.
The animation works only correctly considering the entering fragments. My code is basically the same for navigating between all fragments:
activity?.supportFragmentManager?.commit {
setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
replace(R.id.myNavHostFragment, BFragment())
}
The navigation is only linear, so I navigate from A -> B, B -> C, and C -> D.
The problem is: only the animation of A -> B works correctly.
For all others, during the animation, the wrong 'old' (exit) fragment A is shown in background, while the new one slides in.
So this means:
animation A -> B works fine.
animation B -> C does not work correctly. Fragment C slides in correctly. But while the animation plays, not Fragment B is shown in the background. Instead, somehow Fragment A is shown again.
the same for C -> D. Fragment A is shown, while C should be seen during the animation.
As you can see, I do not add fragments to the backstack. I really can't figure out why Fragment A is always shown during the animation, even if it should be a different one.
In a nutshell: the animation shows always the first fragment (A) as exit fragment, while it should be the previous one instead.
Please check your navigation graph and re-visit all the below attributes shown in below image.
Open your own navigation_graph.xml and then click on Design tab.
You will see below attribute(as shown in image) when you click on navigation direction.
Also, Animation has nothing to do with the back stack of your app.
You need to check Pop Behavior and Launch Options
Also please see if you have set any Flag's incorrectly in your code.
For e.g. FLAG like FLAG_ACTIVITY_CLEAR_TOP
And finally please thoroughly go through this Article
I hava two Fragment(OverviewFragmentăPersonalFragment), and one sub graph(contains two Fragment :BucketsFragment and ObjectsFragment, BucketsFragment is start destination). They are bind to one BottomNavigateView.
Now, After navigate to the sub graph start destination(BucketsFragment), and continue to navigate to ObjectsFragment. Then navigate to OverviewFragment and finally return to the sub graph.
Now, I came to start destination(BucketsFragment), but actually what I want is ObjectsFragment. what should I do?
The whole process is shown here
I want to navigate to the sub graph that retains the previous state, instead of a new sub graph.
As per the material design guidelines for bottom navigation:
On Android: the app navigates to a destinationâs top-level screen. Any prior user interactions and temporary screen states are reset, such as scroll position, tab selection, and in-line search.
So technically, this behavior is expected.
When you're on the Resources tab and go to the ObjectsFragment, the back stack is
DashBoardFragment -> BucketsFragment -> ObjectsFragment
When you go back to the Overview tab, the back stack becomes
DashBoardFragment
And no state is saved for Fragments that aren't on the back stack. That's why when you reselect the Resources tab, it is recrated from scratch and you get back to
DashBoardFragment -> BucketsFragment
There's an existing issue for supporting multiple back stacks which aims to bring support for saving the state of each tab separately, allowing the behavior you wish. As per that issue, this requires significant changes to how Fragments work (since they are the one saving the state of Fragments) as well as integration into Navigation itself.
That issue points out a temporary workaround, demonstrated in the NavigationAdvancedSample where each tab uses its own separate navigation graph and separate NavHostFragment, thus allowing each one to keep its own state independently from one another. This requires a bit different of a setup in the MainActivity and the help of a set of NavigationExtensions to get that working.
It is expected that all of that functionality, once the multiple back stacks work is done, to be folded into the Navigation library itself.
I am currently trying to use the Android Navigation component to navigate from one fragment (A) to another (B) by animating fragment B up from the bottom of the screen (over fragment A) and subsequently animating fragment B back down when the back button is pressed. I currently have an action defined for this:
<action
android:id="#+id/action_landingFragment_to_bookingFragment"
app:destination="#id/bookingFragment"
app:enterAnim="#anim/booking_screen_in"
app:exitAnim="#anim/nothing"
app:popEnterAnim="#anim/nothing"
app:popExitAnim="#anim/booking_screen_out"
app:popUpTo="#id/landingFragment" />
However, when I navigate to fragment B from fragment A currently, I get a nice smooth slide up from the bottom of the screen, hit the back button and see fragment B disappear instantly to display fragment A again, with no animation. I currently use no custom code for the back button on fragment B (though I tried navigateUp() and popBackStack() in an OnBackPressedCallback to see if I was missing something regarding these. I also wonder if there is an issue with Z-axis of the fragments (similar to this thread) but my normal enter/exit animations work fine and I have tried a more traditional set of animations (slide left/right) in which the enter and exit animations play but the pop animations once again do not.
Can anyone suggest the correct way to do back navigation such that these pop animations should be visible?