Skip to content

Commit

Permalink
fix(elevatedview): UpdateElevation timing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 committed Nov 13, 2020
1 parent 9617999 commit df3b6e5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
27 changes: 25 additions & 2 deletions src/Uno.UI.Toolkit/ElevatedView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ protected override void OnApplyTemplate()
_border = GetTemplateChild("PART_Border") as Border;
_shadowHost = GetTemplateChild("PART_ShadowHost") as Panel;

#if __IOS__ || __MACOS__
if (_border != null)
{
_border.BoundsPathUpdated += (s, e) => UpdateElevation();
}
#endif

UpdateElevation();
}

Expand Down Expand Up @@ -109,7 +116,15 @@ public object ElevatedContent

#if !NETFX_CORE
public new static DependencyProperty BackgroundProperty { get ; } = DependencyProperty.Register(
"Background", typeof(Brush), typeof(ElevatedView), new FrameworkPropertyMetadata(default(Brush), OnChanged));
"Background",
typeof(Brush),
typeof(ElevatedView),
#if __IOS__ || __MACOS__
new FrameworkPropertyMetadata(default(Brush))
#else
new FrameworkPropertyMetadata(default(Brush), OnChanged)
#endif
);

public new Brush Background
{
Expand All @@ -118,7 +133,15 @@ public object ElevatedContent
}

public static DependencyProperty CornerRadiusProperty { get ; } = DependencyProperty.Register(
"CornerRadius", typeof(CornerRadius), typeof(ElevatedView), new FrameworkPropertyMetadata(default(CornerRadius), OnChanged));
"CornerRadius",
typeof(CornerRadius),
typeof(ElevatedView),
#if __IOS__ || __MACOS__
new FrameworkPropertyMetadata(default(CornerRadius))
#else
new FrameworkPropertyMetadata(default(CornerRadius), OnChanged)
#endif
);

public CornerRadius CornerRadius
{
Expand Down
15 changes: 7 additions & 8 deletions src/Uno.UI/UI/Xaml/Controls/Border/Border.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ private void UpdateBorderLayer(_Image backgroundImage = null)
(Background as ImageBrush)?.ImageSource?.TryOpenSync(out backgroundImage);
}

BoundsPath = _borderRenderer.UpdateLayer(
this,
Background,
BorderThickness,
BorderBrush,
CornerRadius,
backgroundImage
);
if (_borderRenderer.UpdateLayer(this, Background, BorderThickness, BorderBrush, CornerRadius, backgroundImage)
is CGPath updated) // UpdateLayer may return null if there is no update
{
BoundsPath = updated;
BoundsPathUpdated?.Invoke(this, default);
}
}

this.SetNeedsDisplay();
Expand Down Expand Up @@ -114,6 +112,7 @@ partial void OnCornerRadiusUpdatedPartial(CornerRadius oldValue, CornerRadius ne
bool ICustomClippingElement.AllowClippingToLayoutSlot => CornerRadius == CornerRadius.None && (!(Child is UIElement ue) || ue.RenderTransform == null);
bool ICustomClippingElement.ForceClippingToLayoutSlot => false;

internal event EventHandler BoundsPathUpdated;
internal CGPath BoundsPath { get; private set; }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ internal class BorderLayerRenderer
/// <param name="borderBrush">The border brush</param>
/// <param name="cornerRadius">The corner radius</param>
/// <param name="backgroundImage">The background image in case of a ImageBrush background</param>
/// <returns>An updated BoundsPath if the layer has been created or updated; null if there is no change.</returns>
public CGPath UpdateLayer(
_View owner,
Brush background,
Thickness borderThickness,
Brush borderBrush,
CornerRadius cornerRadius,
_Image backgroundImage)
_Image backgroundImage)
{
// Bounds is captured to avoid calling twice calls below.
var bounds = owner.Bounds;
Expand Down

0 comments on commit df3b6e5

Please sign in to comment.