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

Fix Button.Flyout not toggling #8448

Merged
merged 8 commits into from
Aug 2, 2022
Merged

Conversation

pr8x
Copy link
Contributor

@pr8x pr8x commented Jul 5, 2022

  • Fixes Button.Flyout not toggling correctly (see Button.Flyout should toggle on/off #8379) by manually setting OverlayInputPassThroughElement to placementTarget inside FlyoutBase (as suggested by @maxkatz6). Not sure if this can have side effects for other code using flyouts.
  • Exposing OverlayDismissEventPassThrough on FlyoutBase to allow for customizing event pass-through behavior.

Fixes #8379

Expose OverlayDismissEventPassThrough on FlyoutBase
@grokys
Copy link
Member

grokys commented Jul 6, 2022

@pr8x I'll close my PR and we'll use this one as it also contains fixes.

What I assume should happen is that if IsSet(OverlayInputPassThroughElementProperty) then the control provided there should be used (or it could be set to null to disable the behavior), otherwise the placement target should be used. Does that sound right?

cc: @maxkatz6

@maxkatz6
Copy link
Member

maxkatz6 commented Jul 6, 2022

@grokys it's a direct property, so does IsSet work there properly?

@grokys
Copy link
Member

grokys commented Jul 6, 2022

Ah yeah IsSet doesn't work with direct properties. I guess we have 2 choices:

  1. Make OverlayInputPassThroughElementProperty a styled property on FlyoutBase
  2. Leave it a direct property and make null mean unset: this means there will be no way to disable making the PlacementTarget the passthough element, but not sure if that's actually required.

@pr8x
Copy link
Contributor Author

pr8x commented Jul 6, 2022

I wonder if we could just explicitly set the OverlayInputPassThroughElement for Button.Flyout and in other cases leave the user to decide?

@maxkatz6
Copy link
Member

maxkatz6 commented Jul 6, 2022

@pr8x yes, it should be better

@grokys
Copy link
Member

grokys commented Jul 7, 2022

I wonder if we could just explicitly set the OverlayInputPassThroughElement for Button.Flyout and in other cases leave the user to decide?

Is this what UWP does?

@pr8x
Copy link
Contributor Author

pr8x commented Jul 7, 2022

Is this what UWP does?

No idea. Couldn't find the source code for FlyoutBase

@grokys
Copy link
Member

grokys commented Jul 11, 2022

I think it should be easy enough to determine by adding a flyout to a button and seeing if it behaves differently to flyouts on other controls?

@robloo
Copy link
Contributor

robloo commented Jul 12, 2022

Tagging @amwx who did the implementation for FlyoutBase.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0021861-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@grokys
Copy link
Member

grokys commented Jul 13, 2022

Taken a look at UWP, and it looks like there, no passthrough is being set. Here's my test code:

  <StackPanel>
    <Button x:Name="b">
      Hello
      <Button.Flyout>
        <MenuFlyout>
          <MenuFlyoutItem>Foo</MenuFlyoutItem>
        </MenuFlyout>
      </Button.Flyout>
    </Button>

    <CheckBox IsChecked="{Binding ElementName=b, Path=IsPointerOver}">PointerOver</CheckBox>
  </StackPanel>

You can see that hovering over the button with the flyout open does not set PointerOver on the button meaning that there's no passthrough.

@grokys
Copy link
Member

grokys commented Jul 13, 2022

From the related issue:

Instead, it seems like PointerPressed triggers light dismiss layer to close the popup. And same click PointerReleased triggers button to open the popup. Default ClickMode is Release.

This actually sounds like the root of the problem. Even when ClickMode is Release the button shouldn't be triggering a click without an associated pointer down event.

@pr8x
Copy link
Contributor Author

pr8x commented Jul 14, 2022

This actually sounds like the root of the problem. Even when ClickMode is Release the button shouldn't be triggering a click without an associated pointer down event.

I think this is due to OverlayDismissEventPassThrough (which is set for all Flyouts by default). It will trigger a pointer down on the button which will make it handle the release event later. The right solution probably is to not use OverlayInputPassThroughElement and in case OverlayDismissEventPassThrough is set somehow ignore the button the flyout was opened from? Not sure how to do this though - API wise.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0022327-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

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

@pr8x @grokys
Let's do next:

  1. Current changes in Button.cs look good.
  2. Feature wise, we need Flyout.OverlayInputPassThroughElement anyway, so it should be added. As it was in Add OverlayInputPassThroughElement to FlyoutBase. #8446.
  3. Let's not set Flyout.OverlayInputPassThroughElement by default (keep it null). But set OverlayDismissEventPassThroughProperty to false. With this combination I can't reproduce original issue.

@grokys do you remember why OverlayDismissEventPassThroughProperty was set to true on the ContextMenu (and later copied to the FlyoutBase)?

I am actually not sure if we even need Flyout.OverlayDismissEventPassThroughProperty property, we can just disable it on the inner popup without giving customization. Flyout.OverlayInputPassThroughElement should be enough. Unless @grokys is against it.

@pr8x
Copy link
Contributor Author

pr8x commented Jul 28, 2022

Current changes in Button.cs look good.

Actually when we disable OverlayDismissEventPassThroughProperty we don't need any extra logic inside Button. The toggling should work out-of-the-box.

@maxkatz6
Copy link
Member

The toggling should work out-of-the-box.

True. I just think it makes sense to toggle flyout OnClick instead of just opening.

@timunie
Copy link
Contributor

timunie commented Jul 28, 2022

For Context Menu I can imagine the user wants to open it at a different position once clicked on a different position of the same control. Like when you have a collection of images. Have to double check if that's the same behavior in normal Windows or just in a particular App I have in mind.

@maxkatz6
Copy link
Member

@timunie oh, it's actually a good point

@timunie
Copy link
Contributor

timunie commented Jul 29, 2022

@timunie oh, it's actually a good point

Okay, So I double-checked this and it's not consistent over the programs I use:

Close ContextMenu on second right click:

  • Gimp
  • Inkscape

Open ContextMenu at another position on second right click:

  • Win 10 Desktop
  • Word
  • Excel
  • CATIA
  • DoubleCommander

List could be extended if needed.

@grokys
Copy link
Member

grokys commented Jul 29, 2022

Yeah, seems like a platform-specific thing. It's probably something we could change per-platform once we have a platform settings API, but for the moment we should probably just stick with the existing behavior for ContentMenu. Looks like OverlayDismissEventPassThrough can be removed for Flyout though as this behavior doesn't apply.

@pr8x
Copy link
Contributor Author

pr8x commented Jul 29, 2022

To make a context menu open again at different mouse position we only need OverlayInputPassThroughElement actually (and set it to the control that opened the context menu). Not sure if we even need OverlayDismissEventPassThrough tbh

@pr8x
Copy link
Contributor Author

pr8x commented Jul 29, 2022

@maxkatz6 Fixed it.

@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0022630-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 enabled auto-merge August 2, 2022 14:58
@maxkatz6 maxkatz6 merged commit 2911b37 into AvaloniaUI:master Aug 2, 2022
@avaloniaui-team
Copy link
Contributor

You can test this PR using the following package version. 0.10.999-cibuild0022728-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

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.

Button.Flyout should toggle on/off
6 participants