Skip to content

Commit

Permalink
fix: Propagate focus property changes from PopupBase to Child
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 30, 2021
1 parent 7cac6bc commit 9f8b3af
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/Popup/PopupBase.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uno.UI;
using Windows.Foundation;
using Windows.UI.Xaml.Input;
using Uno.Extensions;
using Uno.UI.DataBinding;
using Windows.UI.Xaml.Media;
using Uno.UI;
#if XAMARIN_IOS
using CoreGraphics;
using UIKit;
Expand All @@ -31,6 +26,17 @@ public partial class PopupBase : FrameworkElement, IPopup
/// </summary>
internal IDynamicPopupLayouter CustomLayouter { get; set; }

internal override void OnPropertyChanged2(DependencyPropertyChangedEventArgs args)
{
if (args.Property == AllowFocusOnInteractionProperty ||
args.Property == AllowFocusWhenDisabledProperty)
{
PropagateFocusProperties();
}

base.OnPropertyChanged2(args);
}

private protected override void OnUnloaded()
{
IsOpen = false;
Expand Down Expand Up @@ -71,10 +77,13 @@ partial void OnChildChangedPartial(UIElement oldChild, UIElement newChild)
{
provider.Store.ClearValue(provider.Store.DataContextProperty, DependencyPropertyValuePrecedences.Local);
provider.Store.ClearValue(provider.Store.TemplatedParentProperty, DependencyPropertyValuePrecedences.Local);
provider.Store.ClearValue(AllowFocusOnInteractionProperty, DependencyPropertyValuePrecedences.Local);
provider.Store.ClearValue(AllowFocusWhenDisabledProperty, DependencyPropertyValuePrecedences.Local);
}

UpdateDataContext(null);
UpdateTemplatedParent();
PropagateFocusProperties();

if (oldChild is FrameworkElement ocfe)
{
Expand Down Expand Up @@ -142,6 +151,15 @@ private void UpdateTemplatedParent()
}
}

private void PropagateFocusProperties()
{
if (Child is IDependencyObjectStoreProvider provider)
{
provider.Store.SetValue(AllowFocusOnInteractionProperty, AllowFocusOnInteraction, DependencyPropertyValuePrecedences.Local);
provider.Store.SetValue(AllowFocusWhenDisabledProperty, AllowFocusWhenDisabled, DependencyPropertyValuePrecedences.Local);
}
}

/// <summary>
/// A layouter responsible to layout the content of a popup at the right place
/// </summary>
Expand Down

0 comments on commit 9f8b3af

Please sign in to comment.