Skip to content

Commit

Permalink
chore: Fix toggle button reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 29, 2024
1 parent d6bd4e0 commit c5086b3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
50 changes: 26 additions & 24 deletions src/Uno.UI/UI/Xaml/Controls/AppBar/AppBar.Partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
#endif

using System;
using System.Collections.Generic;
using System.Text;
using DirectUI;
using Uno.Disposables;
using Uno.UI;
using Uno.UI.Helpers.WinUI;
using Windows.ApplicationModel.Resources;
using Windows.Foundation;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
Expand All @@ -23,14 +20,10 @@
using Uno.UI.Extensions;
using static Microsoft/* UWP don't rename */.UI.Xaml.Controls._Tracing;
using Uno.UI.Xaml.Input;
using System.Linq;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml;
using Popup = Microsoft.UI.Xaml.Controls.Primitives.Popup;
using Windows.System;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Automation;
using Uno.UI.Controls;
using Uno.UI.Xaml.Core;
using WinUICoreServices = Uno.UI.Xaml.Core.CoreServices;

Expand Down Expand Up @@ -73,7 +66,7 @@ public partial class AppBar : ContentControl
WeakReference<Page>? m_wpOwner;

SerialDisposable m_contentRootSizeChangedEventHandler = new SerialDisposable();
SerialDisposable m_windowSizeChangedEventHandler = new SerialDisposable();
SerialDisposable m_xamlRootChangedEventHandler = new SerialDisposable();
SerialDisposable m_expandButtonClickEventHandler = new SerialDisposable();
SerialDisposable m_displayModeStateChangedEventHandler = new SerialDisposable();

Expand Down Expand Up @@ -148,10 +141,10 @@ private protected override void OnLoaded()
}

// TODO: Uno specific - use XamlRoot instead of Window
if (XamlRoot is not null)
if (m_xamlRootChangedEventHandler.Disposable is null && XamlRoot is not null)
{
XamlRoot.Changed += OnXamlRootChanged;
m_windowSizeChangedEventHandler.Disposable = Disposable.Create(() => XamlRoot.Changed -= OnXamlRootChanged);
m_xamlRootChangedEventHandler.Disposable = Disposable.Create(() => XamlRoot.Changed -= OnXamlRootChanged);
}

//UNO TODO
Expand Down Expand Up @@ -253,19 +246,7 @@ protected override void OnVisibilityChanged(Visibility oldValue, Visibility newV
}
private void UnregisterEvents()
{
m_contentRootSizeChangedEventHandler.Disposable = null;
m_windowSizeChangedEventHandler.Disposable = null;
m_expandButtonClickEventHandler.Disposable = null;
m_displayModeStateChangedEventHandler.Disposable = null;
m_overlayElementPointerPressedEventHandler.Disposable = null;

m_tpLayoutRoot = null;
m_tpContentRoot = null;
m_tpExpandButton = null;
m_tpDisplayModesStateGroupRef = null;

m_overlayClosingStoryboard = null;
m_overlayOpeningStoryboard = null;
m_xamlRootChangedEventHandler.Disposable = null;
}

private protected override void OnUnloaded()
Expand All @@ -285,7 +266,28 @@ private protected override void OnUnloaded()

protected override void OnApplyTemplate()
{
UnregisterEvents();
if (m_tpContentRoot is not null)
{
m_contentRootSizeChangedEventHandler.Disposable = null;
}

if (m_tpExpandButton is not null)
{
m_expandButtonClickEventHandler.Disposable = null;
}

if (m_tpDisplayModesStateGroupRef is not null)
{
m_displayModeStateChangedEventHandler.Disposable = null;
}

m_tpLayoutRoot = null;
m_tpContentRoot = null;
m_tpExpandButton = null;
m_tpDisplayModesStateGroupRef = null;

m_overlayClosingStoryboard = null;
m_overlayOpeningStoryboard = null;

// Clear our previous template parts.
m_tpLayoutRoot = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public CommandBarOverflowPresenter()
m_useFullWidth = false;
m_shouldOpenUp = false;

#if HAS_UNO && XAMARIN // Uno specific: Set StackPanel as default ItemsPanel for CommandBarOverflowPresenter
ItemsPanel = new ItemsPanelTemplate(() => new StackPanel());
#if HAS_UNO // Uno specific: Set StackPanel as default ItemsPanel for CommandBarOverflowPresenter
ItemsPanel = new ItemsPanelTemplate(() => new StackPanel() { HorizontalAlignment = HorizontalAlignment.Stretch });
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public bool AlwaysExpanded
private readonly Dictionary<int, IDisposable> m_secondaryToggleButtonUncheckedRevokerByIndexMap = new();
private readonly Dictionary<int, IDisposable[]> m_propertyChangedRevokersByIndexMap = new();

private FlyoutPresenter? m_presenter = null;
private FlyoutPresenter? m_presenter;

private bool m_isClosingAfterCloseAnimation = false;
private bool m_isClosingAfterCloseAnimation;
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ void closeFlyoutFunc(object sender, object args)
button.Click += closeFlyoutFunc;
var clickRevoker = new SerialDisposable();
clickRevoker.Disposable = Disposable.Create(() => button.Click -= closeFlyoutFunc);
m_secondaryButtonClickRevokerByIndexMap[i] = clickRevoker;
}
else if (toggleButton is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ partial class TextCommandBarFlyout
private List<IDisposable> m_proofingMenuToggleItemClickRevokers = new();
private DispatcherHelper m_dispatcherHelper;

private bool m_isSettingToggleButtonState = false;
private bool m_isSettingToggleButtonState;
}

0 comments on commit c5086b3

Please sign in to comment.