Skip to content

Commit

Permalink
chore: Do not generalize listening to brushes
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Feb 8, 2024
1 parent 0845300 commit bd09142
Showing 1 changed file with 1 addition and 52 deletions.
53 changes: 1 addition & 52 deletions src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#if __SKIA__
using System;
using System.Collections.Generic;
using System.Text;
using Windows.Foundation;
using Microsoft.UI.Xaml;
using Uno.UI;
using Uno.Disposables;

namespace Uno.UI.Xaml.Controls;
Expand All @@ -16,8 +12,6 @@ internal partial class BorderLayerRenderer
{
private readonly FrameworkElement _owner;
private readonly IBorderInfoProvider _borderInfoProvider;
private readonly SerialDisposable _borderBrushSubscription = new();
private readonly SerialDisposable _backgroundBrushSubscription = new();

private BorderLayerState _currentState;

Expand All @@ -43,59 +37,14 @@ internal void Update()
{
if (_owner.IsLoaded)
{
// Subscribe to brushes to observe their changes.
if (_currentState.BorderBrush != _borderInfoProvider.BorderBrush)
{
_borderBrushSubscription.Disposable = null;
if (_borderInfoProvider.BorderBrush is { } borderBrush)
{
borderBrush.InvalidateRender += OnBorderBrushChanged;
_borderBrushSubscription.Disposable = Disposable.Create(() => borderBrush.InvalidateRender -= OnBorderBrushChanged);
}
}

if (_currentState.Background != _borderInfoProvider.Background)
{
_backgroundBrushSubscription.Disposable = null;
if (_borderInfoProvider.Background is { } backgroundBrush)
{
backgroundBrush.InvalidateRender += OnBackgroundBrushChanged;
_backgroundBrushSubscription.Disposable = Disposable.Create(() => backgroundBrush.InvalidateRender -= OnBackgroundBrushChanged);
}
}

UpdatePlatform();
}
}

private void OnBorderBrushChanged()
{
// Force the border to be recreated during update.
_currentState.BorderBrush = null;
Update();
}

private void OnBackgroundBrushChanged()
{
// Force the background to be recreated during update.
_currentState.Background = null;
Update();
}

/// <summary>
/// Removes added layers and subscriptions.
/// </summary>
internal void Clear()
{
UnsubscribeBrushChanges();
ClearPlatform();
}

private void UnsubscribeBrushChanges()
{
_borderBrushSubscription.Disposable = null;
_backgroundBrushSubscription.Disposable = null;
}
internal void Clear() => ClearPlatform();

partial void UpdatePlatform();

Expand Down

0 comments on commit bd09142

Please sign in to comment.