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

[Bug] IActiveAware not working correctly with TabbedPage on initial start | need support for IActiveAware #2639

Open
Daniel0b1b opened this issue Dec 14, 2021 · 1 comment

Comments

@Daniel0b1b
Copy link

Description

Hi, my goal is to know which tab is selected in a tabbed page, but after initial start there are some issues.

I dynamically create my Tab pages using:

await NavigationService.NavigateAsync("/PrismTabbedPage1?" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage1&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage2&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage3&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage4&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage5&" +
                $"{KnownNavigationParameters.SelectedTab}=PrismContentPage2");

IActiveAware.IsActive is not fired if I tap on PrismContentPage3, PrismContentPage4 or PrismContentPage5 when the app is first started.
And all Pages are set to IsActive = true after initial start

Steps to Reproduce

  1. Add multiple ContentPages wrapped in a NavigationPage as a child of a TabbedPage
  2. After initial start all tabs has IActiveAware.IsActive = true
  3. Switch between tabs, and the IsActive property isn't called correctly before you came back the 2nd time

Expected Behavior

  • IActiveAware.IsActive to be set correctly when switching between tabs after initial start and don't set initial all tabs to IActiveAware.IsActive = true

Actual Behavior

  • IActiveAware.IsActive is not set correctly when switching the first time to a tab

  • IActiveAware.IsActive is initially set to true to all tabs when creating them

      PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: False
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: False
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage2ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage3ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage4ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage5ViewModel - IsActive: True
      PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: False // (because the 2nd tab was selected)
    

Basic Information

  • Version with issue: v7.1.0.431 (Prism.DryIoc.Forms)
  • Last known good version: Not known
  • Xamarin.Forms version: 5.0.0.2244
  • IDE: Microsoft Visual Studio Professional 2019 Version 16.11.7 (Windows 10)

Reproduction Link

Please see sample solution which replicates issue here
PrismTabbedPageActiveAware.zip

MainPage.cs is a ContentPage.

Tap on the Button to navigate to PrismTabbedPage1.cs:

await NavigationService.NavigateAsync("/PrismTabbedPage1?" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage1&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage2&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage3&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage4&" +
                $"{KnownNavigationParameters.CreateTab}=NavigationPage|PrismContentPage5&" +
                $"{KnownNavigationParameters.SelectedTab}=PrismContentPage2");

PrismContentPage1.cs to PrismContentPage5.cs are ContentPage wrapped with NavigationPage.
All PrismContentPage.cs inherit from ViewModelBase.cs which implements IActiveAware

The output in the console after calling NavigateAsync is:

PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: True
PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: False
PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: True
PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: False
PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: True
PrismTabbedPageActiveAware.ViewModels.PrismContentPage2ViewModel - IsActive: True
PrismTabbedPageActiveAware.ViewModels.PrismContentPage3ViewModel - IsActive: True
PrismTabbedPageActiveAware.ViewModels.PrismContentPage4ViewModel - IsActive: True
PrismTabbedPageActiveAware.ViewModels.PrismContentPage5ViewModel - IsActive: True 
PrismTabbedPageActiveAware.ViewModels.PrismContentPage1ViewModel - IsActive: False // (this is ok because the 2nd tab was selected - but PrismContentPage2ViewModel isn't active)

I refer to: #1164 (added support for ActiveAware NavPages in a TabbedPage)
And there to the comment #1164 (comment):

"There appears to be the same issue with dynamically created tab pages. For example my nav url is app:///MasterDetailPage/TabsPage?createTab=NavigationPage|ViewA&createTab=NavigationPage|ViewB&createTab=NavigationPage|ViewC&selectedTab=ViewA
IActiveAware IsActive is not fired if I tap on tab ViewB when the app is first started"

Is there any solution with a behavior described in /pull/1164? (xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms")

Thanks for your time.

@dansiegel
Copy link
Member

@Daniel0b1b sorry for such a delayed response to this.

I was able to confirm that this is not working as it should. I have added it to the Prism 9.0 roadmap and will be confirming that this is working properly for Prism.Maui as well since it's likely the bug is present there as well.

As a work around you would want to provide your own PageBehaviorFactory and exclude the ActiveAware Behaviors from Prism providing instead one that would meet your needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants