Skip to content

Commit

Permalink
chore: Update BreadcrumbBar to winui3/release/1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
morning4coffe-dev committed Oct 27, 2023
1 parent ec1a303 commit fe66f07
Show file tree
Hide file tree
Showing 6 changed files with 385 additions and 569 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX Reference BreadcrumbBar.h, commit f4a2812
// MUX Reference BreadcrumbBar.h, tag winui3/release/1.4.2

#nullable enable

using System.Collections.Specialized;
using Uno.Disposables;
using Windows.UI.Xaml.Controls;

Expand All @@ -31,9 +30,7 @@ public partial class BreadcrumbBar : Control
private BreadcrumbIterable? m_itemsIterable = null;

private ItemsRepeater? m_itemsRepeater = null;

private BreadcrumbElementFactory? m_itemsRepeaterElementFactory = null;

private BreadcrumbLayout? m_itemsRepeaterLayout = null;

// Pointers to first and last items to update visual states
Expand Down
38 changes: 12 additions & 26 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/Breadcrumb/BreadcrumbBar.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX Reference BreadcrumbBar.cpp, commit 9aedb00
// MUX Reference BreadcrumbBar.cpp, tag winui3/release/1.4.2

#nullable enable

using System.Collections.ObjectModel;
using Microsoft.UI.Input;
using Uno.Disposables;
using Uno.UI.Helpers.WinUI;
using Windows.System;
Expand Down Expand Up @@ -70,20 +71,7 @@ protected override void OnApplyTemplate()

m_itemsRepeater = (ItemsRepeater)GetTemplateChild(s_itemsRepeaterPartName);

if (this is UIElement thisAsUIElement7)
{
thisAsUIElement7.PreviewKeyDown += OnChildPreviewKeyDown;
}
else if (this is UIElement thisAsUIElement)
{
var handler = new KeyEventHandler(OnChildPreviewKeyDown);
m_breadcrumbKeyDownHandlerRevoker.Disposable = Disposable.Create(() =>
{
RemoveHandler(UIElement.KeyDownEvent, handler);
});
AddHandler(UIElement.KeyDownEvent, handler, true);
}

PreviewKeyDown += OnChildPreviewKeyDown;
AccessKeyInvoked += OnAccessKeyInvoked;
GettingFocus += OnGettingFocus;

Expand Down Expand Up @@ -467,19 +455,15 @@ private void OnGettingFocus(object sender, GettingFocusEventArgs args)

if (itemsRepeater.TryGetElement(m_focusedIndex) is { } selectedItem)
{
if (args is GettingFocusEventArgs argsAsIGettingFocusEventArgs2)
if (args.TrySetNewFocusedElement(selectedItem))
{
if (args.TrySetNewFocusedElement(selectedItem))
{
args.Handled = true;
}
args.Handled = true;
}
}
}

// Focus was already in the repeater: in RS3+ Selection follows focus unless control is held down.
else if (SharedHelpers.IsRS3OrHigher() &&
(global::Windows.UI.Xaml.Window.Current.CoreWindow.GetKeyState(VirtualKey.Control) &
else if ((InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control) &
CoreVirtualKeyStates.Down) != CoreVirtualKeyStates.Down)
{
if (args.NewFocusedElement is UIElement newFocusedElementAsUIE)
Expand Down Expand Up @@ -520,9 +504,9 @@ private bool MoveFocus(int indexIncrement)
{
if (itemsRepeater.TryGetElement(focusedIndex) is { } item)
{
if (item is Control itemAsControl)
if (item is UIElement itemAsUIE)
{
if (itemAsControl.Focus(FocusState.Programmatic))
if (itemAsUIE.Focus(FocusState.Programmatic))
{
FocusElementAt(focusedIndex);
return true;
Expand Down Expand Up @@ -638,7 +622,8 @@ private void OnChildPreviewKeyDown(object sender, KeyRoutedEventArgs args)
else if ((flowDirectionIsLTR && (args.OriginalKey == VirtualKey.GamepadDPadRight)) ||
(!flowDirectionIsLTR && (args.OriginalKey == VirtualKey.GamepadDPadLeft)))
{
if (FocusManager.TryMoveFocus(FocusNavigationDirection.Next))
var options = GetFindNextElementOptions();
if (FocusManager.TryMoveFocus(FocusNavigationDirection.Next, options))
{
args.Handled = true;
return;
Expand All @@ -657,7 +642,8 @@ private void OnChildPreviewKeyDown(object sender, KeyRoutedEventArgs args)
else if ((flowDirectionIsLTR && (args.OriginalKey == VirtualKey.GamepadDPadLeft)) ||
(!flowDirectionIsLTR && (args.OriginalKey == VirtualKey.GamepadDPadRight)))
{
if (FocusManager.TryMoveFocus(FocusNavigationDirection.Previous))
var options = GetFindNextElementOptions();
if (FocusManager.TryMoveFocus(FocusNavigationDirection.Previous, options))
{
args.Handled = true;
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX Reference BreadcrumbBar.properties.cpp, commit 9aedb00
// MUX Reference BreadcrumbBar.properties.cpp, tag winui3/release/1.4.2

#nullable enable

Expand Down
Loading

0 comments on commit fe66f07

Please sign in to comment.