AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology

Home Page:https://avaloniaui.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update Popup.OverlayDismissEventPassThrough default based on form factor

billhenn opened this issue · comments

Is your feature request related to a problem? Please describe.

Right now, the Popup.OverlayDismissEventPassThrough property default is always false. The new PopupFlyoutBase.OverlayDismissEventPassThrough added in PR is an additional owner of the Popup.OverlayDismissEventPassThrough property and therefore also defaults false.

The problem is that on desktop form factors, end users will expect click event pass-through to work, while on mobile form factors, end users will expect click event pass-through not to work. The behavior should be consistent through all popups and flyouts (which are based on popups) in the application for a given form factor.

To currently achieve click event pass-through on desktop, one must:

  • Retemplate all native and custom control themes to update their Popup usage to set OverlayDismissEventPassThrough="{OnFormFactor Default=False, Desktop=True}".
  • Update all Flyout usage throughout the application to do the same. However also noting that OnFormFactor might not even be available in code-behind for flyouts created in code-behind.

Having to do all this work to support expected click event pass-through per form factor is tedious and most people will not even know to do it. It would be better to bake logical defaults into the framework.

Describe the solution you'd like

It would be ideal for the default value of the Popup.OverlayDismissEventPassThrough property value to be based on the form factor so that no control themes or flyout declarations in apps would need alteration.

This can be done very simply by updating the Popup property's declaration like this:

public static readonly StyledProperty<bool> OverlayDismissEventPassThroughProperty =
  AvaloniaProperty.Register<Popup, bool>(nameof(OverlayDismissEventPassThrough), defaultValue: IsDesktopFormFactor());

private static bool IsDesktopFormFactor()
  => AvaloniaLocator.Current.GetRequiredService<IRuntimePlatform>().GetRuntimeInfo().IsDesktop;

The net result is that click event pass-through works out of the box for desktop form factors and remains disabled (like now) for non-desktop form factors. Nobody has to think about anything and it works as expected for end users by default.

Describe alternatives you've considered

No response

Additional context

The PR helped ensure that flyouts also could set the OverlayDismissEventPassThrough property.