Skip to content

Commit

Permalink
feat(flyout): Implement FlyoutBase.OverlayInputPassThroughElement
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges authored and dr1rrb committed Apr 19, 2024
1 parent c62fed4 commit c54cc2f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Flyout\Flyout_OverlayInputPassThroughElement.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\FlipView\FlipView_Images.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -6099,6 +6103,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\GridView\GridViewMultipleSelectionMode.xaml.cs">
<DependentUpon>GridViewMultipleSelectionMode.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Flyout\Flyout_OverlayInputPassThroughElement.xaml.cs">
<DependentUpon>Flyout_OverlayInputPassThroughElement.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\ImageSourceWriteableBitmapInvalidate_Stretch.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\IconSourceTests\IconSourceElementTests.xaml.cs">
<DependentUpon>IconSourceElementTests.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public bool ShouldConstrainToRootBounds
}
#endif
// Skipping already declared property Placement
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Microsoft.UI.Xaml.DependencyObject OverlayInputPassThroughElement
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public bool IsConstrainedToRootBounds
#endif
// Skipping already declared property IsOpenProperty
// Skipping already declared property LightDismissOverlayModeProperty
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public static global::Microsoft.UI.Xaml.DependencyProperty OverlayInputPassThroughElementProperty { get; } =
Microsoft.UI.Xaml.DependencyProperty.Register(
Expand Down
9 changes: 9 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ internal Brush LightDismissOverlayBackground

internal static DependencyProperty LightDismissOverlayBackgroundProperty { get; } =
DependencyProperty.Register("LightDismissOverlayBackground", typeof(Brush), typeof(FlyoutBase), new FrameworkPropertyMetadata(null));

internal static DependencyProperty OverlayInputPassThroughElementProperty { get; } =
DependencyProperty.Register("OverlayInputPassThroughElement", typeof(DependencyObject), typeof(FlyoutBase), new FrameworkPropertyMetadata(null));

public DependencyObject OverlayInputPassThroughElement
{
get { return (DependencyObject)GetValue(OverlayInputPassThroughElementProperty); }
set { SetValue(OverlayInputPassThroughElementProperty, value); }
}

/// <summary>
/// Gets or sets whether a disabled control can receive focus.
Expand Down
27 changes: 27 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutPopupPanel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#if !__UWP__
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uno.UI;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;

namespace Microsoft.UI.Xaml.Controls
Expand Down Expand Up @@ -35,6 +38,30 @@ public FlyoutBasePopupPanel(FlyoutBase flyout) : base(flyout._popup)
internal override FlyoutBase Flyout => _flyout;

protected override int PopupPlacementTargetMargin => 5;

protected override void OnPointerPressed(object sender, PointerRoutedEventArgs args)
{
base.OnPointerPressed(sender, args);

// Make sure we are the original source. We do not want to handle PointerPressed on the Popup itself.
if (args.OriginalSource == this)
{
if (Flyout.OverlayInputPassThroughElement is UIElement passThroughElement)
{
var (elementToBeHit, _) = VisualTreeHelper.SearchDownForTopMostElementAt(
args.GetCurrentPoint(null).Position,
passThroughElement.XamlRoot.VisualTree.RootElement,
VisualTreeHelper.DefaultGetTestability,
childrenFilter: elements => elements.Where(e => e != this));

var eventArgs = new PointerRoutedEventArgs(
new PointerEventArgs(args.GetCurrentPoint(null), args.KeyModifiers),
args.OriginalSource as UIElement);

elementToBeHit.OnPointerDown(eventArgs);
}
}
}
}
}
#endif
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/Popup/PopupPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private protected override void OnUnloaded()

// TODO: pointer handling should really go on PopupRoot. For now it's easier to put here because PopupRoot doesn't track open popups, and also we
// need to support native popups on Android that don't use PopupRoot.
private void OnPointerPressed(object sender, PointerRoutedEventArgs args)
protected virtual void OnPointerPressed(object sender, PointerRoutedEventArgs args)
{
// Make sure we are the original source. We do not want to handle PointerPressed on the Popup itself.
if (args.OriginalSource == this && Popup is { } popup)
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/VisualTreeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ internal static (UIElement? element, Branch? stale) HitTest(
/// On skia: The absolute position relative to the window origin.
/// Everywhere else: The position relative to the parent (i.e. the position in parent coordinates).
/// </param>
private static (UIElement? element, Branch? stale) SearchDownForTopMostElementAt(
internal static (UIElement? element, Branch? stale) SearchDownForTopMostElementAt(
Point position,
UIElement element,
GetHitTestability getVisibility,
Expand Down

0 comments on commit c54cc2f

Please sign in to comment.