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

Hide CommandBarButtonGroupView if all CommandBarButtons are hidden #1254

Merged
merged 7 commits into from
Sep 15, 2022

Conversation

nodes11
Copy link
Contributor

@nodes11 nodes11 commented Sep 14, 2022

Platforms Impacted

  • iOS
  • macOS

Description of changes

Issue:
If all the items in a CommandBarButtonGroupView are hidden, the system spacers are still shown in the stack view and create visible empty space. See video below for example.

This is a bug with the CommandBar. Not technically a regression since the ability to hide a CommandBarButton was introduced with this commit and this change is fixing a case that was missed with the original commit.

Root Cause:
The CommandBarItem.propertyChangedUpdateBlock was calling CommandBarButton.updateState() directly to update the isHidden state of a CommandBarButton. This works to hide each of the individual buttons, but the superview, the CommadBarButtonGroupView.stackView, isn't aware of when its subviews change their hidden state. If all of the subviews are hidden, the superview needs to also mark itself as hidden so that the system spacers inside the stackView do not remain visible.

Fix:

  • The CommandBarItem.propertyChangedUpdateBlock block that calls CommandBarButton.updateState() now takes an additional Bool parameter to indicate if the CommadBarButtonGroupView should also update its state. If the parameter is true the block calls hideGroupIfNeeded() on the group.
  • Add a call to hideGroupIfNeeded() from CommadBarButtonGroupView. init(buttons:) to ensure the group view is hidden if it is initialized with buttons that are set as hidden.
  • Modified the loop used to create a CommadBarButtonGroupView so that an update call can be made on the group if needed.
  • Updated CommandBarDemoController to hide the "Delete" item instead of the "+" item. Since the "Delete" item is the item in its own group, the CommadBarButtonGroupView will have to hide itself when the "Delete" item is hidden, testing the functionality added in this PR.

Verification

Before (Observe space before the Delete item):

Hide.-.Buggy.mov

After (Observe space before the Delete item):

Hide.-.Fixed.mov

Pull request checklist

This PR has considered:

  • Light and Dark appearances
  • iOS supported versions (all major versions greater than or equal current target deployment version)
  • VoiceOver and Keyboard Accessibility
  • Internationalization and Right to Left layouts
  • Different resolutions (1x, 2x, 3x)
  • Size classes and window sizes (iPhone vs iPad, notched devices, multitasking, different window sizes, etc)
  • iPad Pointer interaction
  • SwiftUI consumption (validation or new demo scenarios needed)
  • Objective-C exposure (provide it only if needed)
Microsoft Reviewers: Open in CodeFlow

@nodes11 nodes11 requested a review from a team as a code owner September 14, 2022 23:21
… hidden

- Calls to update the CommandBarButton state now go through the group. This enables the group to be able to check if it needs to hide itself.
- Slight modification of the loop used to create a CommadBarButtonGroupView to enable button updates that go through the group.
- Updated CommandBarDemoController to hide the "Delete" item instead of the "+" item. Since the "Delete" item is the item in its group, the CommadBarButtonGroupView will have to hide itself when the "Delete" item is hidden, testing the functionality added in this PR.
@nodes11 nodes11 merged commit aa9d788 into microsoft:main Sep 15, 2022
sophialee0416 pushed a commit to sophialee0416/fluentui-apple that referenced this pull request Sep 20, 2022
…icrosoft#1254)

Hide CommandBarButtonGroupView if all contained CommandBarButtons are hidden

- The CommandBarItem.propertyChangedUpdateBlock block that calls CommandBarButton.updateState() now takes an additional Bool parameter to indicate if the CommadBarButtonGroupView should also update its state. If the parameter is true the block calls hideGroupIfNeeded() on the group.
- Add a call to hideGroupIfNeeded() from CommadBarButtonGroupView. init(buttons:) to ensure the group view is hidden if it is initialized with buttons that are set as hidden.
- Modified the loop used to create a CommadBarButtonGroupView so that an update call can be made on the group if needed.
- Updated CommandBarDemoController to hide the "Delete" item instead of the "+" item. Since the "Delete" item is the item in its own group, the CommadBarButtonGroupView will have to hide itself when the "Delete" item is hidden, testing the functionality added in this PR.
lcapkovic pushed a commit to lcapkovic/fluentui-apple that referenced this pull request Sep 22, 2022
…icrosoft#1254)

Hide CommandBarButtonGroupView if all contained CommandBarButtons are hidden

- The CommandBarItem.propertyChangedUpdateBlock block that calls CommandBarButton.updateState() now takes an additional Bool parameter to indicate if the CommadBarButtonGroupView should also update its state. If the parameter is true the block calls hideGroupIfNeeded() on the group.
- Add a call to hideGroupIfNeeded() from CommadBarButtonGroupView. init(buttons:) to ensure the group view is hidden if it is initialized with buttons that are set as hidden.
- Modified the loop used to create a CommadBarButtonGroupView so that an update call can be made on the group if needed.
- Updated CommandBarDemoController to hide the "Delete" item instead of the "+" item. Since the "Delete" item is the item in its own group, the CommadBarButtonGroupView will have to hide itself when the "Delete" item is hidden, testing the functionality added in this PR.
Comment on lines +34 to +39
for view in stackView.arrangedSubviews {
if !view.isHidden {
allViewsHidden = false
break
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

swifty way to do this:

isHidden = !stackView.arrangedSubviews.contains(where: { !$0.isHidden })

@harrieshin harrieshin mentioned this pull request Nov 14, 2022
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants