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

[Android] Content wrapped in NavigationPage objects in Tabbed Page disappears after tabs navigating #9743

Closed
neordi opened this issue Aug 29, 2022 · 22 comments · Fixed by #11530
Labels
area-controls-tabbedpage TabbedPage fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@neordi
Copy link

neordi commented Aug 29, 2022

Description

While navigating between 4 or more tabs that are wrapped in a 'NavigationPage' objects in 'TabbedPage', some tabs disappear. Instead of them blank Navigation Page is displayed and no errors are provided. OnAppearing() method is invoked but no contents are displayed.

On IOS 'TabbedPage' with 'NavigationPage' objects as children behaves as expected.

Reproduction project is here.

Steps to Reproduce

  1. Create a File > New .Net MAUI App
  2. Replace 'ContentPage' with 'TabbedPage'
  3. Add to 'TabbedPage' 4 children that are wrapped in a 'NavigationPage' objects
  4. Launch Project on Android
  5. Navigate from 1st tab to 4th and than to 1st again.

Content of 1st tab has disappeared.

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11 and up

Did you find any workaround?

No response

Relevant log output

No response

@neordi neordi added the t/bug Something isn't working label Aug 29, 2022
@jfversluis jfversluis added this to the Backlog milestone 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.

@0mpurdy
Copy link

0mpurdy commented Nov 1, 2022

I have a temporary workaround for this, where you can increase the OffscreenPageLimit. The Xamarin.Forms property works, it looks like it's not hooked up properly in MAUI. This obviously is a tradeoff, and ideally the reload when it goes out of scope would also work.

private void ModifyTabbedPageHandler()
{
    Microsoft.Maui.Handlers.TabbedViewHandler.Mapper.AppendToMapping("FixMultiTab", (handler, view) =>
    {
#if ANDROID
        var viewPager = (AndroidX.ViewPager2.Widget.ViewPager2)handler.PlatformView;
        viewPager.OffscreenPageLimit = 5;
#endif
    });
}

This issue from Xamarin is similar, except that it's doing what I'd expect (where the page is reloaded if it goes out of scope), whereas in MAUI at the moment it just stays blank.

@hartez hartez changed the title [Android] Content wrapped in NavigationPage objects in Tabbed Page dissapears after tabs navigating [Android] Content wrapped in NavigationPage objects in Tabbed Page disappears after tabs navigating Nov 1, 2022
@jbe2277
Copy link

jbe2277 commented Nov 15, 2022

#10108 Android: UI elements disappear when showing page, the 2nd time
seems to be resolved with .NET7/MAUI7.

The issue is categorized as duplicate of this one. Maybe this is resolved as well.

@PureWeen PureWeen added the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Nov 19, 2022
@ghost
Copy link

ghost commented Nov 19, 2022

Hi @neordi. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost closed this as completed Nov 27, 2022
@tranb3r
Copy link

tranb3r commented Dec 5, 2022

I'm still having this issue, even with the latest version of maui, net7, VS.

@ghost
Copy link

ghost commented Dec 5, 2022

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@tranb3r
Copy link

tranb3r commented Dec 5, 2022

Could you please re-open this issue or mark it as duplicate of #7558, and then fix it ?

@drasticactions
Copy link
Contributor

The bot closed this bug prematurely, #11530 should be resolved first.

@dotnet dotnet unlocked this conversation Jan 19, 2023
@ghost ghost closed this as completed Jan 26, 2023
@tranb3r
Copy link

tranb3r commented Jan 26, 2023

@drasticactions
The bot has closed this issue again, could you please reopen it one more time, since the PR is sitll open?
Thanks

@PureWeen PureWeen reopened this Jan 26, 2023
@PureWeen PureWeen removed the s/try-latest-version Please try to reproduce the potential issue on the latest public version label Jan 26, 2023
@PureWeen
Copy link
Member

@tranb3r Can you try this work around and see how it goes?

Copy the files from here to your project

https://github.com/PureWeen/ShanedlerSamples/tree/main/ShanedlerSamples/Library

Then in your builder you can call

builder
            .UseMauiApp<App>()
            .ConfigureTabbedPageWorkarounds()

@tranb3r
Copy link

tranb3r commented Jan 27, 2023

@PureWeen
I've done some tests of your fix, both on my repro project and then on my app.
I confirm that the tabs work now as expected: no more blank page.

However, sometimes, the navigation (push page) does not work. I'm prettry sure it's linked to your fix.
Here is the log message when the navigation does not work:
[FragmentNavigator] Ignoring navigate() call: FragmentManager has already saved its state
Any idea what's happening?

@tranb3r
Copy link

tranb3r commented Jan 31, 2023

@PureWeen How can I help?

@PureWeen
Copy link
Member

@PureWeen How can I help?

I might have missed it but can you point me to your repro project with this workaround applied?
working inside that space will help.

@tranb3r
Copy link

tranb3r commented Jan 31, 2023

I might have missed it but can you point me to your repro project with this workaround applied? working inside that space will help.

https://github.com/tranb3r/Issues/tree/main/MauiAppTabbedPageBlank

@PureWeen
Copy link
Member

PureWeen commented Feb 3, 2023

I might have missed it but can you point me to your repro project with this workaround applied? working inside that space will help.

https://github.com/tranb3r/Issues/tree/main/MauiAppTabbedPageBlank

I updated my samples.
let me know how that works.

@tranb3r
Copy link

tranb3r commented Feb 3, 2023

Looks good to me. Thank you!!

@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 23, 2023
@tranb3r
Copy link

tranb3r commented Mar 3, 2023

@PureWeen
I'm having one more issue with your code.
Here is an exception I get when programmatically adding a new Tab to the TabbedPage:

System.InvalidCastException: Specified cast is not valid.
    at Microsoft.Maui.Controls.Handlers.TabbedPageManager.OnChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\TabbedPageManager.cs:line 274
    at System.Collections.ObjectModel.ObservableCollection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    at System.Collections.ObjectModel.ObservableCollection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
    at System.Collections.ObjectModel.ObservableCollection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].InsertItem(Int32 index, Element item)
    at System.Collections.ObjectModel.Collection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Insert(Int32 index, Element item)
    at Microsoft.Maui.Controls.ObservableWrapper`2[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Page, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Insert(Int32 index, Page item) in D:\a\_work\1\s\src\Controls\src\Core\ObservableWrapper.cs:line 137

Is this something that can be fixed in your code?
Thanks!

@ghost
Copy link

ghost commented Mar 3, 2023

Hello lovely human, thank you for your comment on this issue. Because this issue has been closed for a period of time, please strongly consider opening a new issue linking to this issue instead to ensure better visibility of your comment. Thank you!

@PureWeen
Copy link
Member

PureWeen commented Mar 3, 2023

@PureWeen I'm having one more issue with your code. Here is an exception I get when programmatically adding a new Tab to the TabbedPage:

System.InvalidCastException: Specified cast is not valid.
    at Microsoft.Maui.Controls.Handlers.TabbedPageManager.OnChildrenCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in D:\a\_work\1\s\src\Controls\src\Core\Platform\Android\TabbedPageManager.cs:line 274
    at System.Collections.ObjectModel.ObservableCollection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCollectionChanged(NotifyCollectionChangedEventArgs e)
    at System.Collections.ObjectModel.ObservableCollection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
    at System.Collections.ObjectModel.ObservableCollection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].InsertItem(Int32 index, Element item)
    at System.Collections.ObjectModel.Collection`1[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Insert(Int32 index, Element item)
    at Microsoft.Maui.Controls.ObservableWrapper`2[[Microsoft.Maui.Controls.Element, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Controls.Page, Microsoft.Maui.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].Insert(Int32 index, Page item) in D:\a\_work\1\s\src\Controls\src\Core\ObservableWrapper.cs:line 137

Is this something that can be fixed in your code? Thanks!

Hmmmmm let me think on that. I'll push something up over on my repository :-/

@PureWeen
Copy link
Member

PureWeen commented Mar 3, 2023

@tranb3r I pushed some changes over here
https://github.com/PureWeen/ShanedlerSamples

it's a bit weird :-) so we'll see

if you hit another issue just log it on that Repository.

@breenbob
Copy link
Contributor

@PureWeen Can this fix be backported to .Net 7?

@samhouts samhouts modified the milestones: Backlog, 8.0-preview1 Apr 6, 2023
@tranb3r
Copy link

tranb3r commented Apr 12, 2023

The bug is still here in maui SR 7.0.81.

@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2023
@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-tabbedpage TabbedPage fixed-in-8.0.0-preview.1.7762 Look for this fix in 8.0.0-preview.1.7762! migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants