Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs within the shell do not execute override the OnAppearing method #8102

Closed
innomarcoItalia opened this issue Jun 16, 2022 · 27 comments · Fixed by #12884
Closed

Tabs within the shell do not execute override the OnAppearing method #8102

innomarcoItalia opened this issue Jun 16, 2022 · 27 comments · Fixed by #12884
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout fixed-in-7.0.59 Look for this fix in 7.0.59! fixed-in-7.0.81 Look for this fix in 7.0.81! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@innomarcoItalia
Copy link

innomarcoItalia commented Jun 16, 2022

Description

Only the override of the first Tab is intercepted
MauiTest.zip

Steps to Reproduce

  1. Download the attached MauiTest project.
  2. Insert breakpoint in override OnAppearing into secondPage.cs
  3. Compile and run on an Android device

-click hamburger icon
-click Test
-click Second

Version with bug

6.0.400 (current)

Last version that worked well

6.0.312

Affected platforms

I was not able test on other platforms

Affected platform versions

Android 11 - Android 12

Did you find any workaround?

https://github.com/PureWeen/ShanedlerSamples/tree/main/ShanedlerSamples/Library/Workarounds
https://github.com/PureWeen/ShanedlerSamples/blob/main/ShanedlerSamples/MauiProgram.cs#L13

Relevant log output

No response

@innomarcoItalia innomarcoItalia added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 16, 2022
@jfversluis jfversluis added area-controls-shell Shell Navigation, Routes, Tabs, Flyout platform/android 🤖 and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 16, 2022
@kristinx0211 kristinx0211 added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage labels Jun 17, 2022
@kristinx0211
Copy link

verified repro on android, the breakpoint on OnAppearing can't be hit, on windows, it can be hit.

@StepKie
Copy link

StepKie commented Jun 17, 2022

To generalize this (testing on Android API 31 emulator):
Shell tab navigation seems to behave weirdly in several ways:
Using the AppShell.xaml from the example:

<Tab  Title="Test"  >
   <ShellContent Title="First"
       ContentTemplate="{DataTemplate local:FirstPage}"
       Route="FirstPage"/>
   <ShellContent Title="Second"
        ContentTemplate="{DataTemplate local:SecondPage}"
        Route="SecondPage" />
</Tab>
<ShellContent Title="ThirdPage"
       ContentTemplate="{DataTemplate local:ThirdPage}"
       Route="ThirdPage"/>
  • apart from OnAppearing, OnNavigatedXYZ methods are also not triggered on SecondPage.
  • when going to SecondPage, navigating to a different page on the main hierarchy like ThirdPage and coming back, the FirstPage is displayed again (the selection was persisted in Xamarin, and it would come back to SecondPage)
  • setting the ContentPage.Title property of the FirstPage in codebehind or associated ViewModel, this is applied it to all tabs (FirstPage and SecondPage then have this new title at the top). Setting the ContentPage.Title property in SecondPage code-behind/viewmodel has no effect on the displayed Title.

In general, Shell seems to behave as if there is only the first page is the only one integrated into Shell at all...

@joshuaokorie
Copy link

Do we have an update on when this will be fixed? From what i can see, this is is really blocking some folks from doing the migration to MAUI.

@anhvinh180594
Copy link

Did you guys find any workaround?

@joshuaokorie
Copy link

No work around from us. I have spent over a week trying to do different things but non works. I will probably need to remove that and create a custom renderer. Am not sure why MAUI team is not trying to resolve it. I know of at least 100 case of it. No traction on it at all.
Please let me know if you find an easier work around.

@Redth Redth modified the milestones: 6.0-servicing, Backlog Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@holecekp
Copy link

holecekp commented Sep 9, 2022

I have the same problem. Content of a tab is not loading because OnAppearing method is not executed for this tab.

@danielheddelin
Copy link

This is a major bug of huge importance and with great impact. Please work on it soon.

@StepKie
Copy link

StepKie commented Nov 21, 2022

Sorry to ask again, but apart from the bot notifying this has been put in the backlog, why is there no activity from Microsoft here at all?
In my opinion and as others have stated, this is a critical bug that prevents any stable use of shell for us, and this is still "in the backlog" half a year after MAUI release?

@ToolmakerSteve
Copy link

ToolmakerSteve commented Dec 7, 2022

StackOverflow / Can a Shell TabBar have a tab without a content page? shows another use case where the inability to put code in OnAppearing for each page is a fundamental showstopper. No workaround.

Given that Maui docs present Shell as the primary means of Navigation, the inability to know when a Page is about to show is a very serious flaw for Maui.

My recommended workaround until this is fixed: DON'T USE SHELL, Use NavigationPage.
More work for the app coder, but you've got full control, using a simple navigation paradigm that has worked for years in Xamarin Forms.

@CucaMacaii
Copy link

CucaMacaii commented Dec 7, 2022

Well, I'm glad that by finding this page I realized at least that I am not an idiot, as I was starting to suspect after more than an hour of testing my code. Bummer !

I am working on an accounting application, and this app works with objects (accounts, transfer, expenses, etc) which all have statuses (like "submitted", "accepted", "rejected", and so on). This is done on several pages feeding on the same list of objects and then filtering it. After, for instance, "Approving" an object on page "Approvals", I would like to see my object appearing on the page "Finalized" i.e. I would like to trigger a refresh of the Finalized page. Currently I populate this page by calling a "LoadDataAsync()" method in the constructor (in Finalized.xaml.cs) because calling this LoadDataAsync() method in OnAppearing() will never execute it. So that means that the data is populated once, in the beginning, and will never get refreshed. OnAppearing() does not trigger on this page because it only triggers on the first page in my Tab (which is the only one working properly).

By the way, do you know of any way of solving this, short of navigating to this stupid "Finalized" page and setting a bound parameter in its viewmodel to trigger the reload ? I do not want to navigate to this page just so I can refresh it ! Thank you !!!

Microsoft, please fix this !

@danielheddelin
Copy link

Not a workaround, but pub/sub using WeakReferenceManager can be of help in certain situations: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/messagingcenter?view=net-maui-7.0

durandt pushed a commit to durandt/maui-issue1-android-tabs that referenced this issue Dec 22, 2022
durandt pushed a commit to durandt/maui-issue1-android-tabs that referenced this issue Dec 22, 2022
durandt pushed a commit to durandt/maui-issue1-android-tabs that referenced this issue Dec 22, 2022
@durandt
Copy link

durandt commented Dec 22, 2022

This issue has been around since Xamarin.Forms (xamarin/Xamarin.Forms#3855)

This issue also causes rendering issues for the view attached in the shell tab as it is not initialized properly. For example, items added to an ObservableCollection rendered in a StackLayout with a BindableLayout won't be rendered on the view.

Repro: https://github.com/durandt/maui-issue1-android-tabs

@avi22228
Copy link

avi22228 commented Jan 9, 2023

Is there a workaround for this? It is surprising that a bug this big is not fixed yet.

@p2pbsh
Copy link

p2pbsh commented Jan 10, 2023

Just found this one the hard way today, surprised it's not been addressed yet, bit of a show stopper.

@StepKie
Copy link

StepKie commented Jan 11, 2023

Just found this one the hard way today, surprised it's not been addressed yet, bit of a show stopper.

I don't know what else to do but chime in to bump this every few weeks. Why is nothing happening here from Microsoft's side?

Please just tell us what you plan to do or some kind of rough timeline!

We are totally blocked from finalizing the migration of our B2B app -which relies on shell navigation baked into all viewmodels- to MAUI...

@joshuaokorie
Copy link

joshuaokorie commented Jan 11, 2023 via email

@mikeparker104 mikeparker104 added the partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with label Jan 12, 2023
@StepKie
Copy link

StepKie commented Jan 17, 2023

Weekly bump until someone in official capacity deigns to respond.
This is not a run-of-the-mill issue, it's a total showstopper for shell apps.

@samhouts samhouts added the p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint label Jan 17, 2023
@PureWeen
Copy link
Member

PureWeen commented Jan 23, 2023

For now, please try this as a workaround.

https://github.com/PureWeen/ShanedlerSamples/tree/main/ShanedlerSamples/Library/Workarounds
https://github.com/PureWeen/ShanedlerSamples/blob/main/ShanedlerSamples/MauiProgram.cs#L13

Working on a permanent fix now. Apologies for this one falling off the radar for so long 👎

@durandt
Copy link

durandt commented Jan 24, 2023

Hi @PureWeen , thank you for working on this!

I have tried your work-around on my repro ( https://github.com/durandt/maui-issue1-android-tabs ),
and the following works:

  • Nested AppShell second (top-)tab's OnAppearing is called (within the first bottom-tab)

But the following is not working:

  1. Nested AppShell second (top-)tab's OnAppearing is not called within the subsequent bottom-tabs
    Put it in other words:
    <TabBar>
       <Tab Title="Home" Icon="house">
           <ShellContent Title="Home 1" ContentTemplate="{DataTemplate views:MainPage}" /><!-- Works -->
           <ShellContent Title="Home 2" ContentTemplate="{DataTemplate views:MainPage}" /><!-- Works -->
       </Tab>
       <Tab Title="Other" Icon="information">
           <ShellContent Title="Other 1" ContentTemplate="{DataTemplate views:MainPage}" /><!-- Works -->
           <ShellContent Title="Other 2" ContentTemplate="{DataTemplate views:MainPage}" /><!-- DOES NOT work -->
       </Tab>
    </TabBar>
  1. Switching view using the bottom tabs (select second tab, then go back to first tab) AND THEN switching views with the top-tabs crashes with NullReferenceException in ShellToolbarTrackerrWorkaround.OnPageChanged:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.UpdateLeftBarButtonItem() in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 678
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.OnPageChanged(Page oldPage, Page newPage) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 259
[mono-rt]    at maui_issue1_android_tabs.Workarounds.HostExtensions.ShellWorkarounds.ShellToolbarTrackerrWorkaround.OnPageChanged(Page oldPage, Page newPage) in /Users/thidu06/projects/maui/maui-issue1-android-tabs/maui-issue1-android-tabs/Workarounds/AndroidShellWorkarounds.cs:line 157
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.set_Page(Page value) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 120
[mono-rt]    at maui_issue1_android_tabs.Workarounds.HostExtensions.ShellWorkarounds.ShellSectionRendererWorkaround.UpdateCurrentItem(ShellContent content) in /Users/thidu06/projects/maui/maui-issue1-android-tabs/maui-issue1-android-tabs/Workarounds/AndroidShellWorkarounds.cs:line 241
[mono-rt]    at maui_issue1_android_tabs.Workarounds.HostExtensions.ShellWorkarounds.ShellSectionRendererWorkaround.OnPageSelected(Int32 position) in /Users/thidu06/projects/maui/maui-issue1-android-tabs/maui-issue1-android-tabs/Workarounds/AndroidShellWorkarounds.cs:line 207
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.ViewPagerPageChanged.OnPageSelected(Int32 position) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellSectionRenderer.cs:line 399
[mono-rt]    at AndroidX.ViewPager2.Widget.ViewPager2.OnPageChangeCallback.n_OnPageSelected_I(IntPtr jnienv, IntPtr native__this, Int32 position) in C:\a\_work\3\s\generated\androidx.viewpager2.viewpager2\obj\Release\net6.0-android\generated\src\AndroidX.ViewPager2.Widget.ViewPager2.cs:line 318
[mono-rt]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPI_V(_JniMarshal_PPI_V callback, IntPtr jnienv, IntPtr klazz, Int32 p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 55

@PureWeen
Copy link
Member

PureWeen commented Jan 24, 2023

Hi @PureWeen , thank you for working on this!

I have tried your work-around on my repro ( https://github.com/durandt/maui-issue1-android-tabs ), and the following works:

  • Nested AppShell second (top-)tab's OnAppearing is called (within the first bottom-tab)

But the following is not working:

  1. Nested AppShell second (top-)tab's OnAppearing is not called within the subsequent bottom-tabs
    Put it in other words:
    <TabBar>
       <Tab Title="Home" Icon="house">
           <ShellContent Title="Home 1" ContentTemplate="{DataTemplate views:MainPage}" /><!-- Works -->
           <ShellContent Title="Home 2" ContentTemplate="{DataTemplate views:MainPage}" /><!-- Works -->
       </Tab>
       <Tab Title="Other" Icon="information">
           <ShellContent Title="Other 1" ContentTemplate="{DataTemplate views:MainPage}" /><!-- Works -->
           <ShellContent Title="Other 2" ContentTemplate="{DataTemplate views:MainPage}" /><!-- DOES NOT work -->
       </Tab>
    </TabBar>
  1. Switching view using the bottom tabs (select second tab, then go back to first tab) AND THEN switching views with the top-tabs crashes with NullReferenceException in ShellToolbarTrackerrWorkaround.OnPageChanged:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.UpdateLeftBarButtonItem() in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 678
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.OnPageChanged(Page oldPage, Page newPage) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 259
[mono-rt]    at maui_issue1_android_tabs.Workarounds.HostExtensions.ShellWorkarounds.ShellToolbarTrackerrWorkaround.OnPageChanged(Page oldPage, Page newPage) in /Users/thidu06/projects/maui/maui-issue1-android-tabs/maui-issue1-android-tabs/Workarounds/AndroidShellWorkarounds.cs:line 157
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellToolbarTracker.set_Page(Page value) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellToolbarTracker.cs:line 120
[mono-rt]    at maui_issue1_android_tabs.Workarounds.HostExtensions.ShellWorkarounds.ShellSectionRendererWorkaround.UpdateCurrentItem(ShellContent content) in /Users/thidu06/projects/maui/maui-issue1-android-tabs/maui-issue1-android-tabs/Workarounds/AndroidShellWorkarounds.cs:line 241
[mono-rt]    at maui_issue1_android_tabs.Workarounds.HostExtensions.ShellWorkarounds.ShellSectionRendererWorkaround.OnPageSelected(Int32 position) in /Users/thidu06/projects/maui/maui-issue1-android-tabs/maui-issue1-android-tabs/Workarounds/AndroidShellWorkarounds.cs:line 207
[mono-rt]    at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.ViewPagerPageChanged.OnPageSelected(Int32 position) in D:\a\_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellSectionRenderer.cs:line 399
[mono-rt]    at AndroidX.ViewPager2.Widget.ViewPager2.OnPageChangeCallback.n_OnPageSelected_I(IntPtr jnienv, IntPtr native__this, Int32 position) in C:\a\_work\3\s\generated\androidx.viewpager2.viewpager2\obj\Release\net6.0-android\generated\src\AndroidX.ViewPager2.Widget.ViewPager2.cs:line 318
[mono-rt]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPI_V(_JniMarshal_PPI_V callback, IntPtr jnienv, IntPtr klazz, Int32 p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 55

Thank you for testing it out!
Updated my workaround and tested against your sample and seem to be working alright now

@durandt
Copy link

durandt commented Jan 25, 2023

@PureWeen Updated work-around works well, thank you Shane!

@PureWeen
Copy link
Member

@durandt great to hear!!

This fix will be released with SR4. We were a little too late unfortunately to get it in for SR3.

@BenBtg
Copy link
Contributor

BenBtg commented Jan 25, 2023

Can confirm the the workaround works for me too. Thanks Shane!

@StepKie
Copy link

StepKie commented Jan 27, 2023

This fix will be released with SR4. We were a little too late unfortunately to get it in for SR3.

Awesome, thank you! When will "SR4" be released? Is it the first Tuesday of the month? February or March?

@holecekp
Copy link

Will the fix solve also the following two issues with OnAppearing? There is another issue with OnAppearing not executing (#9531) and another one that causes OnAppearing/OnDisappearing to be executed many times instead of just once (#10161). It would be worth testing the workaround also for them before SR4 is released.

@samhouts samhouts added the fixed-in-7.0.59 Look for this fix in 7.0.59! label Feb 16, 2023
@samhouts samhouts modified the milestones: Backlog, .NET 7 + Servicing Feb 16, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! label Feb 22, 2023
@SmartmanApps
Copy link

Hey @PureWeen,

I was referred here from #9531. I installed your workaround nuget and added the builder command, but I'm still experiencing the issue with OnAppearing not running correctly - see my comments there (I was commenting there because that was the only OnAppearing issue I could see that was still open). I'm not using shell, so maybe your workaround only works with shell? I'm experiencing the issue in Windows on a Content/NavigationPage.

Thanks.

@samhouts samhouts added the fixed-in-7.0.81 Look for this fix in 7.0.81! label Apr 12, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout fixed-in-7.0.59 Look for this fix in 7.0.59! fixed-in-7.0.81 Look for this fix in 7.0.81! fixed-in-7.0.100 fixed-in-7.0.101 fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! p/1 Work that is important, and has been scheduled for release in this or an upcoming sprint partner/cat 😻 this is an issue that impacts one of our partners or a customer our advisory team is engaged with platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.