Skip to content

Commit 133f7d9

Browse files
Merge pull request #20817 from unoplatform/dev/mazi/cbf-improvements
2 parents 0c048ea + 8d8408a commit 133f7d9

File tree

11 files changed

+150
-21
lines changed

11 files changed

+150
-21
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Linq;
2+
using System.Threading.Tasks;
3+
using Microsoft.UI.Xaml.Controls;
4+
using Microsoft.UI.Xaml.Controls.Primitives;
5+
using Microsoft.UI.Xaml.Media;
6+
using MUXControlsTestApp.Utilities;
7+
using Private.Infrastructure;
8+
9+
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls;
10+
11+
[TestClass]
12+
[RunsOnUIThread]
13+
public class Given_CommandBarFlyout
14+
{
15+
[TestMethod]
16+
public async Task When_CommandBarFlyoutCommandBar_AlwaysExpanded()
17+
{
18+
var commandBarFlyout = new CommandBarFlyout
19+
{
20+
AlwaysExpanded = true
21+
};
22+
commandBarFlyout.PrimaryCommands.Add(new AppBarButton { Label = "Primary Command" });
23+
commandBarFlyout.SecondaryCommands.Add(new AppBarButton { Label = "Secondary Command" });
24+
25+
var button = new Button
26+
{
27+
Content = "Open CommandBarFlyout",
28+
};
29+
30+
FlyoutBase.SetAttachedFlyout(button, commandBarFlyout);
31+
32+
TestServices.WindowHelper.WindowContent = button;
33+
await TestServices.WindowHelper.WaitForLoaded(button);
34+
35+
FlyoutBase.ShowAttachedFlyout(button);
36+
await TestServices.WindowHelper.WaitForIdle();
37+
38+
var popups = VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot);
39+
40+
var commandBarPopup = popups.FirstOrDefault(p => VisualTreeUtils.FindVisualChildByType<CommandBarFlyoutCommandBar>(p.Child) is not null);
41+
Assert.IsNotNull(commandBarPopup);
42+
var commandBar = VisualTreeUtils.FindVisualChildByType<CommandBarFlyoutCommandBar>(commandBarPopup?.Child);
43+
Assert.IsNotNull(commandBar);
44+
45+
bool wasClosed = false;
46+
commandBar.Closed += (s, e) => wasClosed = true;
47+
commandBar.IsOpen = false;
48+
49+
await TestServices.WindowHelper.WaitForIdle();
50+
Assert.IsTrue(commandBar.IsOpen, "CommandBarFlyout should remain open when AlwaysExpanded is true.");
51+
Assert.IsFalse(wasClosed, "CommandBarFlyout should not close when AlwaysExpanded is true.");
52+
}
53+
}

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Flyout.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public class Given_Flyout
3838
{
3939
private string GetAllIsOpens() => string.Join(" ", VisualTreeHelper.GetOpenPopupsForXamlRoot(TestServices.WindowHelper.XamlRoot).Select(p => p.IsOpen));
4040

41+
[TestMethod]
42+
[RunsOnUIThread]
43+
public async Task When_Default_ShowMode()
44+
{
45+
var flyout = new Flyout();
46+
Assert.AreEqual(FlyoutShowMode.Standard, flyout.ShowMode);
47+
}
48+
4149
[TestMethod]
4250
[RunsOnUIThread]
4351
public async Task When_Unloaded_Before_Shown()

src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Controls.Primitives/FlyoutBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.UI.Xaml.Controls.Primitives
99
public partial class FlyoutBase : global::Microsoft.UI.Xaml.DependencyObject
1010
{
1111
// Skipping already declared property XamlRoot
12-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
12+
#if false
1313
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "__TVOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
1414
public global::Microsoft.UI.Xaml.Controls.Primitives.FlyoutShowMode ShowMode
1515
{
@@ -145,7 +145,7 @@ public bool IsConstrainedToRootBounds
145145
typeof(global::Microsoft.UI.Xaml.Controls.Primitives.FlyoutBase),
146146
new Microsoft.UI.Xaml.FrameworkPropertyMetadata(default(bool)));
147147
#endif
148-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
148+
#if false
149149
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "__TVOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
150150
public static global::Microsoft.UI.Xaml.DependencyProperty ShowModeProperty { get; } =
151151
Microsoft.UI.Xaml.DependencyProperty.Register(

src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Controls.Primitives/FlyoutShowMode.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
#pragma warning disable 114 // new keyword hiding
44
namespace Microsoft.UI.Xaml.Controls.Primitives
55
{
6-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
6+
#if false
77
public enum FlyoutShowMode
88
{
9-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
9+
#if false
1010
Auto = 0,
1111
#endif
12-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
12+
#if false
1313
Standard = 1,
1414
#endif
15-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
15+
#if false
1616
Transient = 2,
1717
#endif
18-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
18+
#if false
1919
TransientWithDismissOnPointerMoveAway = 3,
2020
#endif
2121
}

src/Uno.UI/Generated/3.0.0.0/Microsoft.UI.Xaml.Controls.Primitives/FlyoutShowOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.UI.Xaml.Controls.Primitives
88
#endif
99
public partial class FlyoutShowOptions
1010
{
11-
#if __ANDROID__ || __IOS__ || __TVOS__ || IS_UNIT_TESTS || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__
11+
#if false
1212
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "__TVOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")]
1313
public global::Microsoft.UI.Xaml.Controls.Primitives.FlyoutShowMode ShowMode
1414
{

src/Uno.UI/UI/Xaml/Controls/AppBar/AppBar.Partial.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ private void OnIsOpenChanged(bool isOpen)
850850
// matter because Blue apps wouldn't have had access to them.
851851
// For post-WinBlue AppBars, we fire the Opening/Closing & Opened/Closed
852852
// events based on our display mode state transitions.
853-
//if (m_tpDisplayModesStateGroup == null)
853+
if (IsOpen == isOpen)
854854
{
855855
if (isOpen)
856856
{
@@ -1228,9 +1228,8 @@ protected bool TryDismissInlineAppBar()
12281228
if (isOpen)
12291229
{
12301230
isAppBarDismissed = true;
1231+
IsOpen = false;
12311232
}
1232-
1233-
IsOpen = false;
12341233
}
12351234

12361235
return isAppBarDismissed;

src/Uno.UI/UI/Xaml/Controls/CommandBarFlyout/CommandBarFlyoutCommandBar.mux.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ private void UpdateItemVisualState(Control? item, bool isPrimaryItem)
845845
}
846846
}
847847

848-
protected override void UpdateTemplateSettings()
848+
private new void UpdateTemplateSettings()
849849
{
850850
//COMMANDBARFLYOUT_TRACE_INFO(this, TRACE_MSG_METH_INT, METH_NAME, this, IsOpen);
851851

src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,25 @@ public bool AllowFocusOnInteraction
286286
[GeneratedDependencyProperty(DefaultValue = true, Options = FrameworkPropertyMetadataOptions.Inherits, ChangedCallback = true)]
287287
public static DependencyProperty AllowFocusOnInteractionProperty { get; } = CreateAllowFocusOnInteractionProperty();
288288

289+
/// <summary>
290+
/// Gets or sets a value that indicates how a flyout behaves when shown.
291+
/// </summary>
292+
public FlyoutShowMode ShowMode
293+
{
294+
get => (FlyoutShowMode)this.GetValue(ShowModeProperty);
295+
set => this.SetValue(ShowModeProperty, value);
296+
}
297+
298+
/// <summary>
299+
/// Identifies the ShowMode dependency property.
300+
/// </summary>
301+
public static DependencyProperty ShowModeProperty { get; } =
302+
DependencyProperty.Register(
303+
nameof(ShowMode),
304+
typeof(FlyoutShowMode),
305+
typeof(FlyoutBase),
306+
new FrameworkPropertyMetadata(FlyoutShowMode.Standard));
307+
289308
private void OnAllowFocusOnInteractionChanged(bool oldValue, bool newValue) =>
290309
SynchronizePropertyToPopup(Popup.AllowFocusOnInteractionProperty, AllowFocusOnInteraction);
291310

@@ -459,6 +478,13 @@ private protected virtual void ShowAtCore(FrameworkElement placementTarget, Flyo
459478
_ => PopupPlacementMode.Auto,
460479
};
461480

481+
ShowMode = showOptions?.ShowMode ?? FlyoutShowMode.Standard;
482+
483+
if (ShowMode == FlyoutShowMode.Auto)
484+
{
485+
ShowMode = FlyoutShowMode.Standard;
486+
}
487+
462488
OnOpening();
463489

464490
if (m_openingCanceled)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Microsoft.UI.Xaml.Controls.Primitives;
2+
3+
/// <summary>
4+
/// Defines constants that specify how a flyout behaves when shown.
5+
/// </summary>
6+
public enum FlyoutShowMode
7+
{
8+
/// <summary>
9+
/// The show mode is determined automatically based on the method used to show the flyout.
10+
/// </summary>
11+
Auto = 0,
12+
13+
/// <summary>
14+
/// Behavior is typical of a flyout shown reactively, like a context menu. The open flyout takes focus. For a CommandBarFlyout, it opens in its expanded state.
15+
/// </summary>
16+
Standard = 1,
17+
18+
/// <summary>
19+
/// Behavior is typical of a flyout shown proactively. The open flyout does not take focus. For a CommandBarFlyout, it opens in its collapsed state.
20+
/// </summary>
21+
Transient = 2,
22+
23+
/// <summary>
24+
/// The flyout exhibits Transient behavior while the cursor is close to it, but is dismissed when the cursor moves away.
25+
/// </summary>
26+
TransientWithDismissOnPointerMoveAway = 3,
27+
}
Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
using Windows.Foundation;
22

3-
namespace Microsoft.UI.Xaml.Controls.Primitives
3+
namespace Microsoft.UI.Xaml.Controls.Primitives;
4+
5+
/// <summary>
6+
/// Represents the options used to show a flyout.
7+
/// </summary>
8+
public partial class FlyoutShowOptions
49
{
5-
public partial class FlyoutShowOptions
10+
/// <summary>
11+
/// Initializes a new instance of the FlyoutShowOptions class.
12+
/// </summary>
13+
public FlyoutShowOptions()
614
{
7-
public Point? Position { get; set; }
15+
}
816

9-
public FlyoutPlacementMode Placement { get; set; } = FlyoutPlacementMode.Auto;
17+
/// <summary>
18+
/// Gets or sets the position where the flyout opens.
19+
/// </summary>
20+
public Point? Position { get; set; }
1021

11-
public FlyoutShowOptions()
12-
{
13-
}
14-
}
22+
/// <summary>
23+
/// Gets or sets a value that indicates where the flyout is placed in relation to its target element.
24+
/// </summary>
25+
public FlyoutPlacementMode Placement { get; set; } = FlyoutPlacementMode.Auto;
26+
27+
/// <summary>
28+
/// Gets or sets a value that indicates how the flyout behaves when opened.
29+
/// </summary>
30+
public FlyoutShowMode ShowMode { get; set; }
1531
}

0 commit comments

Comments
 (0)