Fix popup shadow bug

This commit is contained in:
chinboy
2025-03-03 08:36:32 +08:00
parent e3b716b04a
commit 7b6bc01f96
7 changed files with 57 additions and 55 deletions
+1 -1
View File
@@ -571,11 +571,11 @@ public class Button : AvaloniaButton,
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
SetupEffectiveBorderThickness();
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, BorderThicknessProperty,
SharedTokenKey.BorderThickness,
BindingPriority.Template,
new RenderScaleAwareThicknessConfigure(this)));
SetupEffectiveBorderThickness();
}
private void SetupEffectiveBorderThickness()
+19 -6
View File
@@ -192,7 +192,7 @@ public class FlyoutHost : Control,
{
base.OnAttachedToLogicalTree(e);
_tokenBindingsDisposable = new CompositeDisposable();
SetupFlyoutProperties();
this.AddTokenBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, MarginToAnchorProperty, SharedTokenKey.MarginXXS));
BindUtils.RelayBind(this, AnchorTargetProperty, _flyoutStateHelper, FlyoutStateHelper.AnchorTargetProperty);
@@ -202,11 +202,7 @@ public class FlyoutHost : Control,
BindUtils.RelayBind(this, MouseLeaveDelayProperty, _flyoutStateHelper,
FlyoutStateHelper.MouseLeaveDelayProperty);
BindUtils.RelayBind(this, TriggerProperty, _flyoutStateHelper, FlyoutStateHelper.TriggerTypeProperty);
if (AnchorTarget is not null)
{
AnchorTarget.SetLogicalParent(this);
VisualChildren.Add(AnchorTarget);
}
SetupFlyoutProperties();
}
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
@@ -255,6 +251,23 @@ public class FlyoutHost : Control,
}
}
}
if (change.Property == AnchorTargetProperty)
{
var oldAnchorTarget = change.GetOldValue<Control?>();
var newAnchorTarget = change.GetNewValue<Control?>();
if (oldAnchorTarget != null)
{
LogicalChildren.Remove(oldAnchorTarget);
VisualChildren.Remove(oldAnchorTarget);
}
if (newAnchorTarget != null)
{
LogicalChildren.Add(newAnchorTarget);
VisualChildren.Add(newAnchorTarget);
}
}
}
public void ShowFlyout(bool immediately)
@@ -369,9 +369,10 @@ public class NotificationCard : ContentControl,
if (this.IsAttachedToLogicalTree())
{
if (this.IsAttachedToLogicalTree())
if (e.Property == NotificationTypeProperty)
{
UpdateNotificationType();
SetupNotificationIcon();
}
else if (e.Property == ContentProperty)
{
@@ -380,10 +381,6 @@ public class NotificationCard : ContentControl,
SetupContent();
}
}
else if (e.Property == NotificationTypeProperty)
{
SetupNotificationIcon();
}
}
if (e.Property == IsClosedProperty)
+3 -3
View File
@@ -485,8 +485,8 @@ public class Popup : AvaloniaPopup,
if (!IsMotionEnabled)
{
_shadowLayer?.Open();
Open();
_shadowLayer?.Open();
opened?.Invoke();
return;
}
@@ -613,10 +613,10 @@ public class Popup : AvaloniaPopup,
motionActor.SceneParent = topLevel;
Dispatcher.UIThread.Post(() =>
{
_shadowLayer?.Close();
MotionInvoker.InvokeInPopupLayer(motionActor, motion, () =>
{
_shadowLayer?.Close();
popupRoot.Opacity = 0;
popupRoot.Hide();
}, () =>
{
_closeAnimating = false;
+27 -26
View File
@@ -148,33 +148,8 @@ internal class PopupShadowLayer : AvaloniaObject, IShadowDecorator
var popupHost = OverlayPopupHost.CreatePopupHost(_target.PlacementTarget ?? _target.GetVisualParent()!, DependencyResolver.Instance);
popupHost.Topmost = false;
NotifyPopupHostCreated(popupHost);
if (popupHost is PopupRoot popupRoot)
{
popupRoot.SetWindowIgnoreMouseEvents(true);
if (popupRoot.PlatformImpl?.PopupPositioner is ManagedPopupPositioner managedPopupPositioner)
{
_managedPopupPositionerPopup = managedPopupPositioner.GetManagedPopupPositionerPopup();
}
}
var handlerCleanup = new CompositeDisposable(7);
if (Child == null && _target.Child != null)
{
// 尝试手动
CreateShadowRenderer();
}
else
{
ConfigureShadowRenderer();
}
popupHost.SetChild(Child);
((ILogical)popupHost).SetLogicalParent(_target);
UpdateLayoutHostPositionAndSize(popupHost);
if (popupHost is PopupRoot topLevelPopup)
{
topLevelPopup
@@ -216,6 +191,32 @@ internal class PopupShadowLayer : AvaloniaObject, IShadowDecorator
});
_openState = new ShadowLayerPopupOpenState(popupHost, cleanupPopup);
NotifyPopupHostCreated(popupHost);
if (popupHost is PopupRoot popupRoot)
{
popupRoot.SetWindowIgnoreMouseEvents(true);
if (popupRoot.PlatformImpl?.PopupPositioner is ManagedPopupPositioner managedPopupPositioner)
{
_managedPopupPositionerPopup = managedPopupPositioner.GetManagedPopupPositionerPopup();
}
}
if (Child == null && _target.Child != null)
{
// 尝试手动
CreateShadowRenderer();
}
else
{
ConfigureShadowRenderer();
}
((ILogical)popupHost).SetLogicalParent(_target);
popupHost.SetChild(Child);
UpdateLayoutHostPositionAndSize(popupHost);
popupHost.Show();
if (targetPopupRoot != null)
@@ -1,14 +1,11 @@
using System.Reactive.Disposables;
using AtomUI.IconPkg;
using AtomUI.Theme;
using AtomUI.Theme.Data;
using AtomUI.Theme.Styling;
using AtomUI.Theme.Utils;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Interactivity;
using Avalonia.LogicalTree;
@@ -82,7 +82,7 @@ internal class PopupConfirmContainerTheme : BaseControlTheme
wrapperLayout.Children.Add(iconContentPresenter);
wrapperLayout.Children.Add(contentLayout);
var titleTextBlock = new SingleLineText()
var titleTextBlock = new SingleLineText
{
Name = TitlePart,
VerticalAlignment = VerticalAlignment.Center,
@@ -105,14 +105,14 @@ internal class PopupConfirmContainerTheme : BaseControlTheme
return wrapperLayout;
}
private StackPanel BuildButtons(PopupConfirmContainer popupConfirmContainer, INameScope scope)
private Panel BuildButtons(PopupConfirmContainer popupConfirmContainer, INameScope scope)
{
var buttonLayout = new StackPanel
{
Name = ButtonLayoutPart,
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Bottom
VerticalAlignment = VerticalAlignment.Bottom,
};
DockPanel.SetDock(buttonLayout, Dock.Bottom);
@@ -120,9 +120,6 @@ internal class PopupConfirmContainerTheme : BaseControlTheme
{
Name = CancelButtonPart,
SizeType = SizeType.Small,
HorizontalAlignment = HorizontalAlignment.Right,
Width = double.NaN,
Height = double.NaN
};
cancelButton.RegisterInNameScope(scope);
@@ -135,11 +132,8 @@ internal class PopupConfirmContainerTheme : BaseControlTheme
var okButton = new Button
{
Name = OkButtonPart,
SizeType = SizeType.Small,
HorizontalAlignment = HorizontalAlignment.Right,
Width = double.NaN,
Height = double.NaN
Name = OkButtonPart,
SizeType = SizeType.Small,
};
okButton.RegisterInNameScope(scope);