dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.22k stars 1.76k forks source link

Android NavigationPage hides the previous page before back navigation #21187

Open leo-mck opened 8 months ago

leo-mck commented 8 months ago

Description

I am trying to change the animation between pages of a NavigationPage on android. For this I override the 4 xml files

nav_default_enter_anim.xml nav_default_exit_anim.xml nav_default_pop_enter_anim.xml nav_default_pop_exit_anim.xml

but it looks like when going back, the previous page fragment are being destroyed before the animation start. This create an ugly effect, even when using the defaults, altough in that case is hard to notice since the animations run faster. I increased the duration of the animations to be able to see the problem:

https://github.com/dotnet/maui/assets/876986/6f02524a-3414-4ddc-b4ca-4123be884d22

Steps to Reproduce

No response

Link to public reproduction project repository

https://github.com/leo-mck/MauiNavigationPageTestApp

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Stedy59 commented 8 months ago

@PureWeen - I will help, if I can.

Here is a video of where I stand with this issue. (Navigation durations have been increased)

https://github.com/dotnet/maui/assets/46286656/b00790d1-902a-42e6-887f-62306d0ad45a

I attempted to re-create the Xamarin functionality for NavigationTransitions authored by @jsuarezruiz . But I quickly realized that the Maui implementation was not using the same underlying "FragmentTransaction" as Xamarin.

I authored my own NavigationPage and Handler(s)... Having to re-create StackNavigationManager, NavHostFragment, NavigationContext, and NavigationViewFragment because everything was "internal" and the actual code that set the animation was 2 layers deep in the NavigationViewFragment.

I decided to use INavigationAnimator based animations instead of using NavigationAnimations as they allow greater control of the view.

NavigationViewFragment override:

public override Animator OnCreateAnimator(int transit, bool enter, int nextAnim) { if (!this.NavigationManager.IsAnimated) { return null; } INavigationAnimator navAnimator = this.NavigationManager.NavAnimator; return (navAnimator is not null) ? this.NavigationManager.IsPopping.Value ? enter ? navAnimator.OnPopEnterAnim(this._currentView) : navAnimator.OnPopExitAnim(this._currentView) : enter ? navAnimator.OnEnterAnim(this._currentView) : navAnimator.OnExitAnim(this._currentView) : base.OnCreateAnimator(transit, enter, 0); } When I saw that the issue you reported, I reached out to @jsuarezruiz for help because the Xamarin version had the same issue but was resolved. I asked him for any info on the fix, but never had a response.

Alex-Dobrynin commented 8 months ago

@Stedy59 have you managed to fix this by custom implementations?

yunusefendi52 commented 4 months ago

@PureWeen I think it's migraiton issue and a regression from Xamarin Forms to MAUI

Stedy59 commented 4 months ago

@Stedy59 have you managed to fix this by custom implementations?

Unfortunately, I have not been able to fix this issue. And, to this day, I have not had any response from either @jsuarezruiz or @PureWeen .

I have a feeling that this is not fixable in the "Maui" code base, but more likely in the Android libs??? @jonathanpeppers

jonathanpeppers commented 4 months ago

I have a feeling that this is not fixable in the "Maui" code base, but more likely in the Android libs???

Do you mean newer AndroidX libraries from Google? That could be a possibility. Generally, the Android workload just provides C# bindings to Java/Kotlin libraries as-is, so behavior in Google's code can change.

I also think the navigation implementation changed quite a bit from Xamarin.Forms to MAUI.

As for how to create custom animations for navigation, I don't know how to help with this, sorry!

Stedy59 commented 4 months ago

I have a feeling that this is not fixable in the "Maui" code base, but more likely in the Android libs???

Do you mean newer AndroidX libraries from Google? That could be a possibility. Generally, the Android workload just provides C# bindings to Java/Kotlin libraries as-is, so behavior in Google's code can change.

I also think the navigation implementation changed quite a bit from Xamarin.Forms to MAUI.

As for how to create custom animations for navigation, I don't know how to help with this, sorry!

Yes, the implementation TOTALLY changed... but for modal, it still uses the Transaction model.

As for the custom animations, got that working as shown in the vid...

Thank you for responding!!!!

rbev commented 2 weeks ago

It's so depressing to come across these kind of issues, that seem to just have zero care from the MAUI team

Page transitions are one of those things that will make or break your app, and this issue causes a major gulf in the polish between the iOS and Android versions of the app