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.19k stars 1.74k forks source link

NavigationPage and FlyoutPage both call OnNavigatedTo, so it is called twice #23902

Open mfeingol opened 3 months ago

mfeingol commented 3 months ago

Description

When navigating to a new page by assigning a new NavigationPage to the FlyoutPage's Detail property, I see NavigationPage called twice on the NavigationPage's inner page. This behavior is incorrect. OnNavigatedTo should only be called once.

First:

    0x37 in Microsoft.Maui.Controls.Page.SendNavigatedTo at /_/src/Controls/src/Core/Page/Page.cs:840,4 C#
    0xE4 in Microsoft.Maui.Controls.FlyoutPage.set_Detail at /_/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs:70,5 C#

... and then:

    0x1C in Microsoft.Maui.Controls.Page.SendNavigatedTo at /_/src/Controls/src/Core/Page/Page.cs:839,4 C#
    0x20 in Microsoft.Maui.Controls.NavigationPage.SendNavigated at /_/src/Controls/src/Core/NavigationPage/NavigationPage.cs:380,4 C#
    0x2 in Microsoft.Maui.Controls.NavigationPage.<OnHandlerChangedCore>b__101_1 at /_/src/Controls/src/Core/NavigationPage/NavigationPage.cs:702,6 C#
    0x1F7 in Microsoft.Maui.Controls.NavigationPage.SendHandlerUpdateAsync at /_/src/Controls/src/Core/NavigationPage/NavigationPage.cs:681,4   C#
    0x11 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.Maui.Controls.NavigationPage.<SendHandlerUpdateAsync>d__100>.ExecutionContextCallback  C#
    0x42 in System.Threading.ExecutionContext.RunInternal   C#
    0x47 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.Maui.Controls.NavigationPage.<SendHandlerUpdateAsync>d__100>.MoveNext  C#
    0x2 in System.Runtime.CompilerServices.AsyncTaskMethodBuilder<System.Threading.Tasks.VoidTaskResult>.AsyncStateMachineBox<Microsoft.Maui.Controls.NavigationPage.<SendHandlerUpdateAsync>d__100>.MoveNext   C#
    0x6 in System.Threading.Tasks.AwaitTaskContinuation.<>c.<.cctor>b__17_0 C#
    0x15 in System.Threading.Tasks.AwaitTaskContinuation.RunCallback    C#
    0x21 in System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run  C#
    0x85 in System.Threading.Tasks.Task.RunContinuations    C#
    0x16 in System.Threading.Tasks.Task.FinishContinuations C#
    0x4C in System.Threading.Tasks.Task<object>.TrySetResult    C#
    0x7 in System.Threading.Tasks.TaskCompletionSource<object>.TrySetResult C#
    0x2 in System.Threading.Tasks.TaskCompletionSource<object>.SetResult    C#
    0x76 in Microsoft.Maui.Controls.NavigationPage.Microsoft.Maui.IStackNavigation.NavigationFinished at /_/src/Controls/src/Core/NavigationPage/NavigationPage.cs:472,4    C#
    0x27 in Microsoft.Maui.Platform.StackNavigationManager.NavigationFinished at /_/src/Core/src/Platform/Android/Navigation/StackNavigationManager.cs:243,4    C#
    0xF in Microsoft.Maui.Platform.StackNavigationManager.OnNavigationViewFragmentResumed at /_/src/Core/src/Platform/Android/Navigation/StackNavigationManager.cs:452,5    C#
    0x4B in Microsoft.Maui.Platform.StackNavigationManager.Callbacks.OnFragmentResumed at /_/src/Core/src/Platform/Android/Navigation/StackNavigationManager.cs:552,6   C#
    0x1A in AndroidX.Fragment.App.FragmentManager.FragmentLifecycleCallbacks.n_OnFragmentResumed_Landroidx_fragment_app_FragmentManager_Landroidx_fragment_app_Fragment_ at D:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release\net8.0-android\generated\src\AndroidX.Fragment.App.FragmentManager.cs:638,5 C#
    0xB in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:198,5   C#

Steps to Reproduce

  1. Use a FlyoutPage for navigation.
  2. Observe the two calls to OnNavigatedTo

Link to public reproduction project repository

N/A

Version with bug

8.0.70 SR7

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

Android 14

Did you find any workaround?

No response

Relevant log output

No response

github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Zhanglirong-Winnie commented 3 months ago

This issue has been verified using Visual Studio 17.11.0 Preview 5.0(8.0.70). Can repro on Android platform.

marcojak commented 2 months ago

Got the same issue. Any hope this will be fixed?

meopoc commented 2 months ago

Me too. Any ideas for a workaround?

cat0363 commented 1 month ago

I'm also running into the same problem.