Skip to content

Commit

Permalink
feat(flyout): Implement EdgeAligned FlyoutPlacementModes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjohnoliver committed Dec 4, 2020
1 parent 9474c0a commit 0941866
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public async Task When_Attached_To_TextBlock_Check_Placement()
[DataRow(FlyoutPlacementMode.Bottom, HorizontalPosition.Center, VerticalPosition.BeyondBottom)]
[DataRow(FlyoutPlacementMode.Left, HorizontalPosition.BeyondLeft, VerticalPosition.Center)]
[DataRow(FlyoutPlacementMode.Right, HorizontalPosition.BeyondRight, VerticalPosition.Center)]
#if NETFX_CORE // Not implemented on Uno https://github.com/unoplatform/uno/issues/4629
[DataRow(FlyoutPlacementMode.TopEdgeAlignedLeft, HorizontalPosition.LeftFlush, VerticalPosition.BeyondTop)]
[DataRow(FlyoutPlacementMode.TopEdgeAlignedRight, HorizontalPosition.RightFlush, VerticalPosition.BeyondTop)]
[DataRow(FlyoutPlacementMode.BottomEdgeAlignedLeft, HorizontalPosition.LeftFlush, VerticalPosition.BeyondBottom)]
Expand All @@ -133,7 +132,6 @@ public async Task When_Attached_To_TextBlock_Check_Placement()
[DataRow(FlyoutPlacementMode.LeftEdgeAlignedBottom, HorizontalPosition.BeyondLeft, VerticalPosition.BottomFlush)]
[DataRow(FlyoutPlacementMode.RightEdgeAlignedTop, HorizontalPosition.BeyondRight, VerticalPosition.TopFlush)]
[DataRow(FlyoutPlacementMode.RightEdgeAlignedBottom, HorizontalPosition.BeyondRight, VerticalPosition.BottomFlush)]
#endif
public async Task Check_Placement_All(
FlyoutPlacementMode placementMode,
HorizontalPosition horizontalPosition,
Expand Down Expand Up @@ -180,7 +178,6 @@ public async Task Check_Placement_All(
[DataRow(FlyoutPlacementMode.Bottom, HorizontalPosition.Center, VerticalPosition.BeyondBottom)]
[DataRow(FlyoutPlacementMode.Left, HorizontalPosition.BeyondLeft, VerticalPosition.Center)]
[DataRow(FlyoutPlacementMode.Right, HorizontalPosition.BeyondRight, VerticalPosition.Center)]
#if NETFX_CORE // Not implemented on Uno https://github.com/unoplatform/uno/issues/4629
[DataRow(FlyoutPlacementMode.TopEdgeAlignedLeft, HorizontalPosition.LeftFlush, VerticalPosition.BeyondTop)]
[DataRow(FlyoutPlacementMode.TopEdgeAlignedRight, HorizontalPosition.RightFlush, VerticalPosition.BeyondTop)]
[DataRow(FlyoutPlacementMode.BottomEdgeAlignedLeft, HorizontalPosition.LeftFlush, VerticalPosition.BeyondBottom)]
Expand All @@ -189,7 +186,6 @@ public async Task Check_Placement_All(
[DataRow(FlyoutPlacementMode.LeftEdgeAlignedBottom, HorizontalPosition.BeyondLeft, VerticalPosition.BottomFlush)]
[DataRow(FlyoutPlacementMode.RightEdgeAlignedTop, HorizontalPosition.BeyondRight, VerticalPosition.TopFlush)]
[DataRow(FlyoutPlacementMode.RightEdgeAlignedBottom, HorizontalPosition.BeyondRight, VerticalPosition.BottomFlush)]
#endif
public async Task Check_Placement_All_MenuFlyout(
FlyoutPlacementMode placementMode,
HorizontalPosition horizontalPosition,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Windows.UI.Xaml.Controls.Primitives
{
public partial class FlyoutBase
{
internal enum PreferredJustification
{
Center,
Top,
Bottom,
Left,
Right
}
}
}
70 changes: 67 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Microsoft.Extensions.Logging;
using Uno.Disposables;
using Uno.Extensions;
using Uno.UI;
using Windows.Foundation;
using Windows.UI.ViewManagement;
Expand Down Expand Up @@ -157,7 +159,7 @@ internal Brush LightDismissOverlayBackground
set { SetValue(LightDismissOverlayBackgroundProperty, value); }
}

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

public FrameworkElement Target { get; private set; }
Expand Down Expand Up @@ -229,7 +231,7 @@ private protected virtual void ShowAtCore(FrameworkElement placementTarget, Flyo

Target = placementTarget;

if(showOptions != null)
if (showOptions != null)
{
_popupPositionInTarget = showOptions.Position;
}
Expand Down Expand Up @@ -265,7 +267,7 @@ protected internal virtual void Close()
{
if (_popup != null)
{
_popup.IsOpen = false;
_popup.IsOpen = false;
}
}

Expand Down Expand Up @@ -335,5 +337,67 @@ internal void SetPresenterStyle(
}

internal Control GetPresenter() => _popup?.Child as Control;

internal static PreferredJustification GetJustificationFromPlacementMode(FlyoutPlacementMode placement)
{
switch (placement)
{
case FlyoutPlacementMode.Full:
case FlyoutPlacementMode.Top:
case FlyoutPlacementMode.Bottom:
case FlyoutPlacementMode.Left:
case FlyoutPlacementMode.Right:
return PreferredJustification.Center;
case FlyoutPlacementMode.TopEdgeAlignedLeft:
case FlyoutPlacementMode.BottomEdgeAlignedLeft:
return PreferredJustification.Left;
case FlyoutPlacementMode.TopEdgeAlignedRight:
case FlyoutPlacementMode.BottomEdgeAlignedRight:
return PreferredJustification.Right;
case FlyoutPlacementMode.LeftEdgeAlignedTop:
case FlyoutPlacementMode.RightEdgeAlignedTop:
return PreferredJustification.Top;
case FlyoutPlacementMode.LeftEdgeAlignedBottom:
case FlyoutPlacementMode.RightEdgeAlignedBottom:
return PreferredJustification.Bottom;
default:
if (typeof(FlyoutBase).Log().IsEnabled(LogLevel.Error))
{
typeof(FlyoutBase).Log().LogError("Unsupported FlyoutPlacementMode");
}
return PreferredJustification.Center;
}
}

internal static MajorPlacementMode GetMajorPlacementFromPlacement(FlyoutPlacementMode placement)
{
switch (placement)
{
case FlyoutPlacementMode.Full:
return MajorPlacementMode.Full;
case FlyoutPlacementMode.Top:
case FlyoutPlacementMode.TopEdgeAlignedLeft:
case FlyoutPlacementMode.TopEdgeAlignedRight:
return MajorPlacementMode.Top;
case FlyoutPlacementMode.Bottom:
case FlyoutPlacementMode.BottomEdgeAlignedLeft:
case FlyoutPlacementMode.BottomEdgeAlignedRight:
return MajorPlacementMode.Bottom;
case FlyoutPlacementMode.Left:
case FlyoutPlacementMode.LeftEdgeAlignedTop:
case FlyoutPlacementMode.LeftEdgeAlignedBottom:
return MajorPlacementMode.Left;
case FlyoutPlacementMode.Right:
case FlyoutPlacementMode.RightEdgeAlignedTop:
case FlyoutPlacementMode.RightEdgeAlignedBottom:
return MajorPlacementMode.Right;
default:
if (typeof(FlyoutBase).Log().IsEnabled(LogLevel.Error))
{
typeof(FlyoutBase).Log().LogError("Unsupported FlyoutPlacementMode");
}
return MajorPlacementMode.Full;
}
}
}
}
9 changes: 0 additions & 9 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutPlacementMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,14 @@ public enum FlyoutPlacementMode
/// The preferred location of the flyout is centered on the screen.
/// </summary>
Full,
[NotImplemented]
TopEdgeAlignedLeft,
[NotImplemented]
TopEdgeAlignedRight,
[NotImplemented]
BottomEdgeAlignedLeft,
[NotImplemented]
BottomEdgeAlignedRight,
[NotImplemented]
LeftEdgeAlignedTop,
[NotImplemented]
LeftEdgeAlignedBottom,
[NotImplemented]
RightEdgeAlignedTop,
[NotImplemented]
RightEdgeAlignedBottom,
[NotImplemented]
Auto
}
}
Loading

0 comments on commit 0941866

Please sign in to comment.