Skip to content

Commit

Permalink
fix: Propagate focus properties from Flyout to Popup host
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Aug 26, 2021
1 parent b37e604 commit 7cac6bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ public void TextBox_BeforeTextChanging()

[Test]
[AutoRetry]
[ActivePlatforms(Platform.iOS, Platform.Browser)] // Android is disabled https://github.com/unoplatform/uno/issues/1630
public void TextBox_Disable()
{
Run("UITests.Shared.Windows_UI_Xaml_Controls.TextBoxTests.TextBox_Disabled");
Expand Down
38 changes: 21 additions & 17 deletions src/Uno.UI/UI/Xaml/Controls/Flyout/FlyoutBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void EnsurePopupCreated()
IsLightDismissEnabled = _isLightDismissEnabled,
};

SynchronizeTemplatedParent();
SynchronizePropertyToPopup(Popup.TemplatedParentProperty, TemplatedParent);

_popup.Opened += OnPopupOpened;
_popup.Closed += OnPopupClosed;
Expand All @@ -66,7 +66,9 @@ private void EnsurePopupCreated()

InitializePopupPanel();

SynchronizeDataContext();
SynchronizePropertyToPopup(Popup.DataContextProperty, DataContext);
SynchronizePropertyToPopup(Popup.AllowFocusOnInteractionProperty, AllowFocusOnInteraction);
SynchronizePropertyToPopup(Popup.AllowFocusWhenDisabledProperty, AllowFocusWhenDisabled);
}
}

Expand Down Expand Up @@ -178,9 +180,12 @@ public bool AllowFocusWhenDisabled
/// <summary>
/// Identifies the AllowFocusWhenDisabled dependency property.
/// </summary>
[GeneratedDependencyProperty(DefaultValue = false, Options = FrameworkPropertyMetadataOptions.Inherits)]
[GeneratedDependencyProperty(DefaultValue = false, Options = FrameworkPropertyMetadataOptions.Inherits, ChangedCallback = true)]
public static DependencyProperty AllowFocusWhenDisabledProperty { get; } = CreateAllowFocusWhenDisabledProperty();

private void OnAllowFocusWhenDisabledChanged(bool oldValue, bool newValue) =>
SynchronizePropertyToPopup(Popup.AllowFocusWhenDisabledProperty, AllowFocusWhenDisabled);

/// <summary>
/// Gets or sets a value that indicates whether the element automatically gets focus when the user interacts with it.
/// </summary>
Expand All @@ -193,9 +198,12 @@ public bool AllowFocusOnInteraction
/// <summary>
/// Identifies for the AllowFocusOnInteraction dependency property.
/// </summary>
[GeneratedDependencyProperty(DefaultValue = true, Options = FrameworkPropertyMetadataOptions.Inherits)]
[GeneratedDependencyProperty(DefaultValue = true, Options = FrameworkPropertyMetadataOptions.Inherits, ChangedCallback = true)]
public static DependencyProperty AllowFocusOnInteractionProperty { get; } = CreateAllowFocusOnInteractionProperty();

private void OnAllowFocusOnInteractionChanged(bool oldValue, bool newValue) =>
SynchronizePropertyToPopup(Popup.AllowFocusOnInteractionProperty, AllowFocusOnInteraction);

public FrameworkElement Target { get; private set; }

internal FlyoutShowOptions ShowOptions => _showOptions;
Expand Down Expand Up @@ -322,23 +330,19 @@ protected internal virtual void Open()

partial void SetPopupPositionPartial(UIElement placementTarget, Point? positionInTarget);

partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e)
{
SynchronizeDataContext();
}
partial void OnDataContextChangedPartial(DependencyPropertyChangedEventArgs e) =>
SynchronizePropertyToPopup(Popup.DataContextProperty, DataContext);

private void SynchronizeDataContext() =>
// This is present to force the dataContext to be passed to the popup of the flyout since it is not directly a child in the visual tree of the flyout.
_popup?.SetValue(Popup.DataContextProperty, this.DataContext, precedence: DependencyPropertyValuePrecedences.Local);

partial void OnTemplatedParentChangedPartial(DependencyPropertyChangedEventArgs e)
=> SynchronizeTemplatedParent();

private void SynchronizeTemplatedParent()
private void SynchronizePropertyToPopup(DependencyProperty property, object value)
{
_popup?.SetValue(Popup.TemplatedParentProperty, TemplatedParent, precedence: DependencyPropertyValuePrecedences.Local);
// This is present to force properties to be propagated to the popup of the flyout
// since it is not directly a child in the visual tree of the flyout.
_popup?.SetValue(property, value, precedence: DependencyPropertyValuePrecedences.Local);
}

partial void OnTemplatedParentChangedPartial(DependencyPropertyChangedEventArgs e) =>
SynchronizePropertyToPopup(Popup.TemplatedParentProperty, TemplatedParent);

public static FlyoutBase GetAttachedFlyout(FrameworkElement element)
{
return (FlyoutBase)element.GetValue(AttachedFlyoutProperty);
Expand Down

0 comments on commit 7cac6bc

Please sign in to comment.