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

Fixed Shell Tab is still visible after set Tab.IsVisible to false #24999

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

NirmalKumarYuvaraj
Copy link
Contributor

@NirmalKumarYuvaraj NirmalKumarYuvaraj commented Sep 30, 2024

Description of Change

When the visibility of the TabItem is changed dynamically, TabBar needs to be updated to reflect the TabBar items count, but hiding the visible TabItem updates the TabContent but doesn't automatically adjust the tab count.

Issues Fixed

Each time the DisplayedPage is modified,we have updated the TabBar items count through setupmenu().

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Fixes #8788
Fixes #23717
Fixes #23780

Before

Shell_before_fix.mp4

After

Shell_After_fix.mp4

@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Sep 30, 2024
@NirmalKumarYuvaraj NirmalKumarYuvaraj marked this pull request as ready for review October 3, 2024 12:30
@NirmalKumarYuvaraj NirmalKumarYuvaraj requested a review from a team as a code owner October 3, 2024 12:30
if (renderer?.ViewController != SelectedViewController)

if (renderer is null)
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is returning too soon. CurrentRenderer isn't updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method RendererForShellContent(ShellSection shellSection) returns null if no matching renderer is found for the given shellSection. In such cases, setting CurrentRenderer to null is necessary to avoid exceptions, particularly when ViewController or other renderer-related operations are invoked. Returning early when the renderer is null ensures we don’t proceed with invalid references, preventing potential runtime exceptions during shell navigation.

I believe this is a necessary safeguard. Please let me know if there’s a better approach or if you have additional recommendations.

@@ -432,7 +432,7 @@ void OnCurrentShellSectionPropertyChanged(object? sender, System.ComponentModel.
if (_mainLevelTabs == null)
return;

var currentItem = VirtualView.CurrentItem.CurrentItem;
var currentItem = VirtualView.CurrentItem?.CurrentItem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we enable nullable here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the nullable reference types are enabled here. After clearing CurrentItem, it reverts to its default value, which can indeed be null. To prevent potential exceptions, I will ensure that proper null checks are in place before accessing CurrentItem.

@@ -270,7 +270,7 @@ void OnVisibleChildRemoved(Element child)
if (CurrentItem == child)
{
if (ShellItemController.GetItems().Count == 0)
ClearValue(CurrentItemProperty, specificity: SetterSpecificity.FromHandler);
ClearValue(CurrentItemProperty);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the rationale for dropping the specificity ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale for dropping the specificity in this case is due to how values are set and managed. Initially, ClearValue(CurrentItemProperty, SetterSpecificity.FromHandler) was used to clear values set by a handler, such as FromHandler.

When a value is set manually or bound using SetValue, the specificity FromHandler is automatically replaced by ManualValueSetter, making the FromHandler value irrelevant. The existing logic in ClearValueCore retrieves the current setter key (e.g., ManualValueSetter or other), but if the value was manually set, passing FromHandler to ClearValue becomes redundant as this key is no longer present in the context values.

If FromHandler has not been overridden by another setter, the method clears the value based on the original key retrieved from the property.

if (original.Key == SetterSpecificity.FromHandler)
bpcontext.Values.Remove(SetterSpecificity.FromHandler);

If it has been overridden, the method automatically clears the value according to the current setter, ensuring that the value is cleared appropriately.

bpcontext.Values.Remove(specificity);

It is not necessary to pass the FromHandler in the ClearValue. Could you please share your thoughts on this approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of you clear the value set FromHandler, it should go back to the previous value with the highest specificity. isn't this what you want ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are passing the FromHandler specificity, it only checks the values set by the handler. Therefore, the manually set value for the CurrentItem property is not cleared when setting visibility. Resetting to the highest specificity is not our intention. Instead, we clear the value without specifying specificity to ensure it is properly cleared.

@jsuarezruiz jsuarezruiz added the area-controls-shell Shell Navigation, Routes, Tabs, Flyout label Oct 4, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

PureWeen commented Oct 8, 2024

/rebase

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

@NirmalKumarYuvaraj
Copy link
Contributor Author

/rebase

@jsuarezruiz
Copy link
Contributor

jsuarezruiz commented Oct 11, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

1 similar comment
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@PureWeen
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout community ✨ Community Contribution
Projects
Status: Todo
4 participants