Browse Source

@ (#21741)

#21740 - SplitView must not steal BackRequested when its pane is closed

When the SplitView is in Overlay or CompactOverlay mode it handled the
TopLevel.BackRequested event even if its pane was not open, which broke
system back navigation. Now it only closes the pane and marks the event
handled when the pane is actually open; otherwise the event bubbles on.

Adds unit tests covering both overlay modes.
@

Co-authored-by: alexander.marek <alexander.marek@opti-q.com>
pull/21750/head
Alexander Marek 3 months ago
committed by GitHub
parent
commit
cc08405da9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      src/Avalonia.Controls/SplitView/SplitView.cs
  2. 37
      tests/Avalonia.Controls.UnitTests/SplitViewTests.cs

3
src/Avalonia.Controls/SplitView/SplitView.cs

@ -598,6 +598,9 @@ namespace Avalonia.Controls
if (!IsInOverlayMode())
return;
if (!IsPaneOpen)
return;
SetCurrentValue(IsPaneOpenProperty, false);
e.Handled = true;
}

37
tests/Avalonia.Controls.UnitTests/SplitViewTests.cs

@ -284,6 +284,43 @@ namespace Avalonia.Controls.UnitTests
Assert.True(splitView.IsPaneOpen);
}
[Theory]
[InlineData(SplitViewDisplayMode.Overlay)]
[InlineData(SplitViewDisplayMode.CompactOverlay)]
public void Top_Level_Back_Requested_Should_Not_Be_Handled_When_Pane_Is_Closed(SplitViewDisplayMode displayMode)
{
using var app = UnitTestApplication.Start(TestServices.StyledWindow
.With(globalClock: new MockGlobalClock()));
var wnd = new Window
{
Width = 1280,
Height = 720
};
var splitView = new SplitView
{
DisplayMode = displayMode
};
wnd.Content = splitView;
wnd.Show();
// Pane is closed: the SplitView must ignore the event so back navigation can proceed.
Assert.False(splitView.IsPaneOpen);
var closedArgs = new Interactivity.RoutedEventArgs(TopLevel.BackRequestedEvent);
wnd.RaiseEvent(closedArgs);
Assert.False(closedArgs.Handled);
// Pane is open: the SplitView should close it and handle the event.
splitView.IsPaneOpen = true;
var openArgs = new Interactivity.RoutedEventArgs(TopLevel.BackRequestedEvent);
wnd.RaiseEvent(openArgs);
Assert.True(openArgs.Handled);
Assert.False(splitView.IsPaneOpen);
}
[Fact]
public void With_Default_IsPaneOpen_Value_Should_Have_Closed_Pseudo_Class_Set()
{

Loading…
Cancel
Save