Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gridview): fix header being placed in wrong orientation #15272

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4311,6 +4311,30 @@ public async Task When_ThemeChange()
}
}

[TestMethod]
[RunsOnUIThread]
public async Task When_GridView_Header_Orientation()
{
var header = new TextBlock
{
Text = "0",
VerticalAlignment = VerticalAlignment.Bottom
};

var SUT = new GridView
{
ItemsSource = "12345",
Header = header
};

await UITestHelper.Load(SUT);

var item1 = SUT.ContainerFromIndex(0).FindVisualChildByType<TextBlock>();
Assert.AreEqual("1", item1.Text);

header.GetAbsoluteBounds().Y.Should().BeLessThan(item1.GetAbsoluteBounds().Y);
}

[TestMethod]
[RunsOnUIThread]
#if __WASM__ || __SKIA__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ internal int LastVisibleIndex
}
}

internal override Orientation? InternalOrientation => Orientation;
internal override Orientation? PhysicalOrientation => Orientation;

internal static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
"Orientation", typeof(Orientation), typeof(CalendarPanel), new FrameworkPropertyMetadata(default(Orientation)));
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/ItemsControl/ItemsPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TemplatedParent is not ListViewBase
#if __ANDROID__ || __IOS__
_itemsPanel is NativeListViewBase nlvb ? nlvb.NativeLayout.Orientation :
#endif
(Panel as Panel)?.InternalOrientation ?? Orientation.Horizontal;
(Panel as Panel)?.PhysicalOrientation ?? Orientation.Horizontal;

public object Header
{
Expand Down Expand Up @@ -423,7 +423,7 @@ protected override Size MeasureOverride(Size size)
size.Height - padding.Top - padding.Bottom
);

var isHorizontal = ((Panel as Panel)?.InternalOrientation ?? Orientation.Horizontal) == Orientation.Horizontal;
var isHorizontal = ((Panel as Panel)?.PhysicalOrientation ?? Orientation.Horizontal) == Orientation.Horizontal;

var desiredSize = default(Size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class ItemsStackPanel : Panel, IVirtualizingPanel, IInsertionPane
#endif
public int LastVisibleIndex => _layout?.LastVisibleIndex ?? -1;

internal override Orientation? InternalOrientation => Orientation;
internal override Orientation? PhysicalOrientation => Orientation;

#if __ANDROID__
public int FirstCacheIndex => _layout.XamlParent.NativePanel.ViewCache.FirstCacheIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/ItemsWrapGrid/ItemsWrapGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class ItemsWrapGrid : Panel, IVirtualizingPanel

public int LastVisibleIndex => _layout?.LastVisibleIndex ?? -1;

internal override Orientation? InternalOrientation => Orientation;
internal override Orientation? PhysicalOrientation => Orientation;

#if __ANDROID__
public int FirstCacheIndex => _layout.XamlParent.NativePanel.ViewCache.FirstCacheIndex;
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal bool TryHandleKeyDown(KeyRoutedEventArgs args)
}
else
{
var orientation = ItemsPanelRoot?.InternalOrientation ?? Orientation.Vertical;
var orientation = ItemsPanelRoot?.PhysicalOrientation ?? Orientation.Vertical;

switch (args.Key)
{
Expand Down
11 changes: 4 additions & 7 deletions src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,11 @@ private static void OnChildrenTransitionsChanged(object dependencyObject, Depend
#endregion

/// <summary>
/// Panels don't have an Orientation in UWP, but many derived types do.
/// This should be overriden by the derived types to refer to match their
/// own Orientation. We don't set a default here since different scenarios
/// use different defaults. E.g. ListView assumes a vertical orientation
/// for keyboard navigation by default, but ItemsPresenter assumes a
/// horizontal orientation for header/footer placement.
/// This corresponds to WinUI's IOrientedPanel::get_PhysicalOrientation, but its overrides
/// are not yet ported from WinUI. Generally speaking, the override should point to
/// the corresponding Orientation property in the subclass (e.g. StackPanel.Orientation)
/// </summary>
internal virtual Orientation? InternalOrientation { get; }
internal virtual Orientation? PhysicalOrientation { get; }

internal Thickness PaddingInternal { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/StackPanel/StackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius n

#region Orientation DependencyProperty

internal override Orientation? InternalOrientation => Orientation;
internal override Orientation? PhysicalOrientation => Orientation;

public Orientation Orientation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public int MaximumRowsOrColumns
typeof(VariableSizedWrapGrid),
new FrameworkPropertyMetadata(-1));

internal override Orientation? InternalOrientation => Orientation;
internal override Orientation? PhysicalOrientation => Orientation;

/// <summary>
/// Gets or sets the direction in which child elements are arranged.
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/VirtualizingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public VirtualizingPanel()

private protected virtual VirtualizingPanelLayout GetLayouterCore() => throw new NotSupportedException($"This method must be overridden by implementing classes.");

internal override Orientation? InternalOrientation => GetLayouter().Orientation;
internal override Orientation? PhysicalOrientation => GetLayouter().Orientation;
}
}
24 changes: 24 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/WrapPanel/WrapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ public partial class WrapPanel : Panel
{
private Orientation _orientation = Orientation.Horizontal;

internal override Orientation? PhysicalOrientation
{
get
{
if (TemplatedParent is GridView gv && gv.Style == Style.GetDefaultStyleForType(GetDefaultStyleKey()))
{
// This is a workaround for our GridView using a WrapPanel instead of an ItemsWrapGrid (which we don't implement).
// The following is the implementation of ItemsWrapGrid::get_PhysicalOrientation from WinUI.
if (_orientation is Orientation.Horizontal)
{
return Orientation.Vertical;
}
else
{
return Orientation.Horizontal;
}
}
else
{
return _orientation;
}
}
}

public virtual Orientation Orientation
{
get
Expand Down
Loading