Skip to content

Commit

Permalink
fix(listview): account for panel orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Aug 10, 2023
1 parent f3fbb2c commit 4a44ab9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public partial class ItemsStackPanel : Panel, IVirtualizingPanel
#endif
public int LastVisibleIndex => _layout?.LastVisibleIndex ?? -1;

internal override Orientation? InternalOrientation => Orientation;

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

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

internal override Orientation? InternalOrientation => Orientation;

#if __ANDROID__
public int FirstCacheIndex => _layout.XamlParent.NativePanel.ViewCache.FirstCacheIndex;
public int LastCacheIndex => _layout.XamlParent.NativePanel.ViewCache.LastCacheIndex;
Expand Down
25 changes: 19 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,21 @@ internal bool TryHandleKeyDown(KeyRoutedEventArgs args)
OnItemClicked(focusedContainer, args.KeyboardModifiers);
}
}
else if (args.Key == VirtualKey.Down)
{
return TryMoveKeyboardFocusAndSelection(+1, args.KeyboardModifiers);
}
else if (args.Key == VirtualKey.Up)
else
{
return TryMoveKeyboardFocusAndSelection(-1, args.KeyboardModifiers);
var orientation = ItemsPanelRoot.InternalOrientation ?? Orientation.Vertical;

switch (args.Key)
{
case VirtualKey.Down when orientation == Orientation.Vertical:
return TryMoveKeyboardFocusAndSelection(+1, args.KeyboardModifiers);
case VirtualKey.Up when orientation == Orientation.Vertical:
return TryMoveKeyboardFocusAndSelection(-1, args.KeyboardModifiers);
case VirtualKey.Right when orientation == Orientation.Horizontal:
return TryMoveKeyboardFocusAndSelection(+1, args.KeyboardModifiers);
case VirtualKey.Left when orientation == Orientation.Horizontal:
return TryMoveKeyboardFocusAndSelection(-1, args.KeyboardModifiers);
}
}
return false;
}
Expand All @@ -124,6 +132,11 @@ private bool TryMoveKeyboardFocusAndSelection(int offset, VirtualKeyModifiers mo
var newContainer = ContainerFromIndex(newIndex) as SelectorItem;
var newItem = ItemFromIndex(newIndex);

if (newIndex < 0 || newIndex >= Items.Count)
{
return false;
}

FocusedIndexContainerItem = (newIndex, newContainer, newItem);

switch (SelectionMode)
Expand Down
7 changes: 7 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/Panel/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ 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.
/// </summary>
internal virtual Orientation? InternalOrientation { get; }

internal Thickness PaddingInternal { get; set; }

internal Thickness BorderThicknessInternal { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/StackPanel/StackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ private void OnCornerRadiusPropertyChanged(CornerRadius oldValue, CornerRadius n

#region Orientation DependencyProperty

internal override Orientation? InternalOrientation => Orientation;

public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/VirtualizingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public VirtualizingPanel()
public VirtualizingPanelLayout GetLayouter() => GetLayouterCore();

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

internal override Orientation? InternalOrientation => GetLayouter().Orientation;
}
}

0 comments on commit 4a44ab9

Please sign in to comment.