Skip to content

Add IsVisible Property to ToolbarItem #30267

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Add IsVisible Property to ToolbarItem #30267

wants to merge 5 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 27, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

This PR adds the IsVisible property to ToolbarItem as requested in the original issue. The property allows developers to programmatically control the visibility of toolbar items without having to manually manage the ToolbarItems collection.

Changes Made

Core Implementation

  • Added IsVisible boolean property to ToolbarItem class with default value true
  • Implemented property change notification to trigger platform updates when visibility changes
  • Added appropriate API entries to all PublicAPI.Unshipped.txt files

Platform Support

  • Windows: Updated Toolbar.Windows.cs to filter toolbar items by IsVisible when building AppBar commands
  • Android: Updated Toolbar.Android.cs to filter toolbar items by IsVisible when updating menu items
  • Tizen: Inherits filtering behavior through existing UpdateMenu mechanism

Testing

  • Added comprehensive unit tests validating the property behavior
  • Created sample app demonstrating real-world usage with toggle functionality
  • All existing tests continue to pass

Usage Example

// Simple programmatic control
var toolbarItem = new ToolbarItem("Settings", "settings.png", OnSettingsClicked);
page.ToolbarItems.Add(toolbarItem);

// Hide the item
toolbarItem.IsVisible = false;

// Show the item again  
toolbarItem.IsVisible = true;

Implementation Details

The implementation keeps toolbar items in the ToolbarItems collection regardless of their visibility state. Platform-specific implementations filter out invisible items when building the native UI, ensuring proper performance and avoiding collection management complexity.

This approach provides a clean, simple API that matches developer expectations while maintaining compatibility with existing code.

Fixes #3701.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@Copilot Copilot AI changed the title [WIP] Add IsVisible Property to ToolbarItem Add IsVisible Property to ToolbarItem Jun 27, 2025
@Copilot Copilot AI requested a review from mattleibow June 27, 2025 09:59
Copilot finished work on behalf of mattleibow June 27, 2025 09:59
Copy link
Contributor

@jsuarezruiz jsuarezruiz left a comment

Choose a reason for hiding this comment

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

This requires public API changes and should be retarget to the net10.0 branch.

Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

This requires public API changes and should be retarget to the net10.0 branch.

You're absolutely right. This PR adds a new public API (IsVisible property to ToolbarItem) and should target the net10.0 branch. The implementation is complete and ready - it just needs to be retargeted to net10.0.

@Copilot Copilot AI requested a review from jsuarezruiz June 27, 2025 10:59
Copilot finished work on behalf of jsuarezruiz June 27, 2025 10:59
Copy link
Member

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

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

So far so good.

Can tou also do ios and mac catalyst.

Add some device tests.

Add some UI tests. Remember, UI tests have 2 parts: app component and the test runner component.

…lbarItem IsVisible property

Co-authored-by: mattleibow <[email protected]>
Copy link
Contributor Author

Copilot AI commented Jun 27, 2025

So far so good.

Can tou also do ios and mac catalyst....

I've completed the implementation for iOS and Mac Catalyst support, and added comprehensive device tests and UI tests as requested.

iOS/Mac Catalyst Support:

  • Added IsVisible filtering in iOS NavigationRenderer's UpdateToolbarItems() method (bca3361)
  • Implemented property change handling through PagePropertyChanged subscription to update toolbar when IsVisible changes
  • Properly handle subscription/unsubscription in view lifecycle methods

Device Tests:

  • Added platform-agnostic device tests in ToolbarTests.cs for filtering and dynamic visibility changes
  • Created iOS-specific device tests in ToolbarTests.iOS.cs that validate toolbar items in UINavigationBar and secondary toolbar items

UI Tests:

  • Host App Component: Created ToolbarIsVisibleTest.cs issue page with comprehensive test scenarios including primary/secondary items and interactive toggles
  • Test Runner Component: Created ToolbarUITests.cs with automated tests validating visibility behavior, dynamic changes, and secondary toolbar items

All changes are complete and ready for testing. The implementation now provides full cross-platform support for the IsVisible property on ToolbarItem across Windows, Android, Tizen, iOS, and Mac Catalyst.

Copilot finished work on behalf of mattleibow June 27, 2025 11:49
@Copilot Copilot AI requested a review from mattleibow June 27, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add IsVisible Property to ToolbarItem
3 participants