Skip to content

Commit

Permalink
feat: Add support for UIElement.ContextFlyout
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Mar 22, 2020
1 parent be7e372 commit 5640745
Show file tree
Hide file tree
Showing 19 changed files with 223 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MenuFlyoutTests : SampleControlUITestBase
[AutoRetry]
public void MenuFlyoutItem_ClickTest()
{
Run("UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutItemTests.MenuFlyoutItem_Click");
Run("UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutTests.MenuFlyoutItem_Click");

_app.WaitForElement(_app.Marked("mfiButton"));

Expand Down Expand Up @@ -144,5 +144,29 @@ public void Dismiss_MenuFlyout()

TakeScreenshot("AfterSuccess");
}

[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android, Platform.iOS)] // We cannot test right button click on WASM yet
public void UIElement_ContextFlyout()
{
Run("UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutTests.UIElement_ContextFlyout");

var result = _app.Marked("result");
var myBorder = _app.Marked("myBorder");

var myBorderRect = _app.Query(_app.Marked("myBorder")).First().Rect;
_app.TouchAndHoldCoordinates(myBorderRect.CenterX, myBorderRect.CenterY);

TakeScreenshot("opened");

_app.FastTap(_app.Marked("testItem1"));
Assert.AreEqual("click: test1", result.GetText());

_app.TouchAndHoldCoordinates(myBorderRect.CenterX, myBorderRect.CenterY);

_app.FastTap(_app.Marked("testItem2"));
Assert.AreEqual("click: test2", result.GetText());
}
}
}
11 changes: 9 additions & 2 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,11 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\MenuFlyoutItemTests\MenuFlyoutItem_Click.xaml">
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\MenuFlyoutTests\MenuFlyoutItem_Click.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\MenuFlyoutTests\UIElement_ContextFlyout.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down Expand Up @@ -3525,9 +3529,12 @@
<DependentUpon>RotatedListView_WithRotatedItems.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ListView\WeirdMeasureSequenceControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\MenuFlyoutItemTests\MenuFlyoutItem_Click.xaml.cs">
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\MenuFlyoutTests\MenuFlyoutItem_Click.xaml.cs">
<DependentUpon>MenuFlyoutItem_Click.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\MenuFlyoutTests\UIElement_ContextFlyout.xaml.cs">
<DependentUpon>UIElement_ContextFlyout.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Models\RotatedListViewViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\Flyout\Flyout_LargeContent.xaml.cs">
<DependentUpon>Flyout_LargeContent.xaml</DependentUpon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutItemTests.MenuFlyoutItem_Click"
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutTests.MenuFlyoutItem_Click"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutItemTests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutItemTests
namespace UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutTests
{
[Uno.UI.Samples.Controls.SampleControlInfo("MenuFlyoutItem", "MenuFlyoutItem_Click", description: "Testing click on MenuFlyoutItem")]
[Uno.UI.Samples.Controls.SampleControlInfo("MenuFlyout", "MenuFlyoutItem_Click", description: "Testing click on MenuFlyoutItem")]
public sealed partial class MenuFlyoutItem_Click : UserControl
{
public MenuFlyoutItem_Click()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutTests.UIElement_ContextFlyout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border x:Name="myBorder" Background="Red" Height="200" Width="200">
<Border.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="testItem1" Text="test1" Click="OnMenuItemClick" />
<MenuFlyoutItem x:Name="testItem2" Text="test2" Click="OnMenuItemClick" />
</MenuFlyout>
</Border.ContextFlyout>
<TextBlock x:Name="result" Text="Right Tap me" />
</Border>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace UITests.Shared.Windows_UI_Xaml_Controls.MenuFlyoutTests
{
[Uno.UI.Samples.Controls.SampleControlInfo("MenuFlyout")]
public sealed partial class UIElement_ContextFlyout : UserControl
{
public UIElement_ContextFlyout()
{
this.InitializeComponent();
}

public void OnMenuItemClick(object sender, object args)
{
if (sender is MenuFlyoutItem item)
{
result.Text = "click: " + item.Text;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,6 @@ public void TryInvokeKeyboardAccelerator( global::Windows.UI.Xaml.Input.Process
// Forced skipping of method Windows.UI.Xaml.Controls.Primitives.FlyoutBase.AreOpenCloseAnimationsEnabled.get
// Forced skipping of method Windows.UI.Xaml.Controls.Primitives.FlyoutBase.AreOpenCloseAnimationsEnabled.set
// Forced skipping of method Windows.UI.Xaml.Controls.Primitives.FlyoutBase.IsOpen.get
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public void ShowAt( global::Windows.UI.Xaml.DependencyObject placementTarget, global::Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions showOptions)
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.Primitives.FlyoutBase", "void FlyoutBase.ShowAt(DependencyObject placementTarget, FlyoutShowOptions showOptions)");
}
#endif
// Skipping already declared method Windows.UI.Xaml.Controls.Primitives.FlyoutBase.CreatePresenter()
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls.Primitives
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
#endif
public partial class FlyoutShowOptions
{
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
Expand All @@ -23,20 +20,6 @@ public partial class FlyoutShowOptions
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public global::Windows.Foundation.Point? Position
{
get
{
throw new global::System.NotImplementedException("The member Point? FlyoutShowOptions.Position is not implemented in Uno.");
}
set
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions", "Point? FlyoutShowOptions.Position");
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Controls.Primitives.FlyoutPlacementMode Placement
{
get
Expand All @@ -63,13 +46,6 @@ public partial class FlyoutShowOptions
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public FlyoutShowOptions()
{
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions", "FlyoutShowOptions.FlyoutShowOptions()");
}
#endif
// Forced skipping of method Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions.FlyoutShowOptions()
// Forced skipping of method Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions.Position.get
// Forced skipping of method Windows.UI.Xaml.Controls.Primitives.FlyoutShowOptions.Position.set
Expand Down
22 changes: 0 additions & 22 deletions src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,6 @@ public bool ExitDisplayModeOnAccessKeyInvoked
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Controls.Primitives.FlyoutBase ContextFlyout
{
get
{
return (global::Windows.UI.Xaml.Controls.Primitives.FlyoutBase)this.GetValue(ContextFlyoutProperty);
}
set
{
this.SetValue(ContextFlyoutProperty, value);
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.DependencyObject AccessKeyScopeOwner
{
get
Expand Down Expand Up @@ -832,14 +818,6 @@ public bool CanBeScrollAnchor
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public static global::Windows.UI.Xaml.DependencyProperty ContextFlyoutProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
"ContextFlyout", typeof(global::Windows.UI.Xaml.Controls.Primitives.FlyoutBase),
typeof(global::Windows.UI.Xaml.UIElement),
new FrameworkPropertyMetadata(default(global::Windows.UI.Xaml.Controls.Primitives.FlyoutBase)));
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public static global::Windows.UI.Xaml.DependencyProperty IsAccessKeyScopeProperty { get; } =
Windows.UI.Xaml.DependencyProperty.Register(
"IsAccessKeyScope", typeof(bool),
Expand Down
25 changes: 9 additions & 16 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.Android.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Android.Views;
using Android.Widget;
using Android.App;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Runtime;
using Uno.Extensions;
using Uno.Logging;
using Uno.UI.Extensions;
using Uno.Disposables;
using Uno.UI.DataBinding;
using Uno.UI;
using Windows.Foundation;

namespace Windows.UI.Xaml.Controls.Primitives
{
Expand All @@ -27,9 +13,16 @@ partial void InitializePopupPanelPartial()
};
}

partial void SetPopupPositionPartial(UIElement placementTarget)

partial void SetPopupPositionPartial(UIElement placementTarget, Point? positionInTarget)
{
_popup.Anchor = placementTarget;

if (positionInTarget is Point position)
{
_popup.HorizontalOffset = position.X;
_popup.VerticalOffset = position.Y;
}
}
}
}
31 changes: 25 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class FlyoutBase : DependencyObject

protected internal Windows.UI.Xaml.Controls.Popup _popup;
private bool _isLightDismissEnabled = true;
private Point? _popupPositionInTarget;
private readonly SerialDisposable _sizeChangedDisposable = new SerialDisposable();

public FlyoutBase()
Expand Down Expand Up @@ -95,7 +96,7 @@ private void OnPopupOpened(object sender, object e)
{
if (_popup.Child is FrameworkElement child)
{
SizeChangedEventHandler handler = (_, __) => SetPopupPositionPartial(Target);
SizeChangedEventHandler handler = (_, __) => SetPopupPositionPartial(Target, _popupPositionInTarget);

child.SizeChanged += handler;

Expand Down Expand Up @@ -162,6 +163,11 @@ internal Brush LightDismissOverlayBackground

public FrameworkElement Target { get; private set; }

/// <summary>
/// Defines an optional position of the popup in the <see cref="Target"/> element.
/// </summary>
internal Point? PopupPositionInTarget => _popupPositionInTarget;

public void Hide()
{
Hide(canCancel: true);
Expand Down Expand Up @@ -192,12 +198,20 @@ internal void Hide(bool canCancel)
Closed?.Invoke(this, EventArgs.Empty);
}

public virtual void ShowAt(FrameworkElement placementTarget)
public void ShowAt(FrameworkElement placementTarget)
{
ShowAtCore(placementTarget);
ShowAtCore(placementTarget, null);
}

private protected virtual void ShowAtCore(FrameworkElement placementTarget)
public void ShowAt(DependencyObject placementTarget, FlyoutShowOptions showOptions)
{
if (placementTarget is FrameworkElement fe)
{
ShowAtCore(fe, showOptions);
}
}

private protected virtual void ShowAtCore(FrameworkElement placementTarget, FlyoutShowOptions showOptions)
{
EnsurePopupCreated();

Expand All @@ -216,6 +230,11 @@ private protected virtual void ShowAtCore(FrameworkElement placementTarget)

Target = placementTarget;

if(showOptions != null)
{
_popupPositionInTarget = showOptions.Position;
}

OnOpening();
Opening?.Invoke(this, EventArgs.Empty);
Open();
Expand Down Expand Up @@ -250,12 +269,12 @@ protected internal virtual void Close()

protected internal virtual void Open()
{
SetPopupPositionPartial(Target);
SetPopupPositionPartial(Target, _popupPositionInTarget);

_popup.IsOpen = true;
}

partial void SetPopupPositionPartial(UIElement placementTarget);
partial void SetPopupPositionPartial(UIElement placementTarget, Point? absolutePosition);

partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Uno.Disposables;
using Uno.UI.DataBinding;
using Uno.UI;
using Windows.Foundation;

namespace Windows.UI.Xaml.Controls.Primitives
{
Expand All @@ -21,7 +22,7 @@ partial void InitializePopupPanelPartial()
};
}

partial void SetPopupPositionPartial(UIElement placementTarget)
partial void SetPopupPositionPartial(UIElement placementTarget, Point? position)
{
_popup.Anchor = placementTarget;
}
Expand Down
Loading

0 comments on commit 5640745

Please sign in to comment.