Skip to content

Commit

Permalink
fix: [Skia] Fix layout when RevealBrush is used
Browse files Browse the repository at this point in the history
Fall back on FallbackColor when RevealBrush is assigned, instead of trying to use unimplemented CompositionBrush property which throws an exception.
  • Loading branch information
davidjohnoliver committed Sep 3, 2021
1 parent 4a85f10 commit 9f5e1a8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using static Private.Infrastructure.TestServices;

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Media
{
[TestClass]
[RunsOnUIThread]
public class Given_RevealBrush
{
[TestMethod]
public async Task When_RevealBrush_Assigned()
{
// Basic smoke test - RevealBrush is currently unimplemented, but it shouldn't break the layout

var siblingBorder = new Border { Width = 43, Height = 22 };
var gridWithRevealBackground = new Grid
{
Width = 57,
Height = 34,
Background = new RevealBackgroundBrush() { Color = Colors.Brown, FallbackColor = Colors.Brown },
};
var parentSP = new StackPanel
{
Children =
{
gridWithRevealBackground,
siblingBorder
}
};

WindowHelper.WindowContent = parentSP;
await WindowHelper.WaitForLoaded(parentSP);

await WindowHelper.WaitForEqual(57, () => gridWithRevealBackground.ActualWidth);
Assert.AreEqual(34, gridWithRevealBackground.ActualHeight);

Assert.AreEqual(43, siblingBorder.ActualWidth);
Assert.AreEqual(22, siblingBorder.ActualHeight);
}
}
}
26 changes: 18 additions & 8 deletions src/Uno.UI/UI/Xaml/Media/Brush.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ internal static IDisposable AssignAndObserveBrush(Brush brush, Compositor compos
{
return AssignAndObserveAcrylicBrush(acrylicBrush, compositor, brushSetter);
}
else if (brush is XamlCompositionBrushBase xamlCompositionBrushBase)
else if (brush is XamlCompositionBrushBase unimplementedCompositionBrush)
{
return AssignAndObserveXamlCompositionBrush(xamlCompositionBrushBase, compositor, brushSetter);
return AssignAndObserveXamlCompositionBrush(unimplementedCompositionBrush, compositor, brushSetter);
}
else
{
Expand Down Expand Up @@ -245,17 +245,27 @@ private static IDisposable AssignAndObserveAcrylicBrush(AcrylicBrush acrylicBrus
return disposables;
}

/// <summary>
/// Apply fallback colour for unimplemented <see cref="XamlCompositionBrushBase"/> types. For implemented types a more specific method
/// should be supplied.
/// </summary>
private static IDisposable AssignAndObserveXamlCompositionBrush(XamlCompositionBrushBase brush, Compositor compositor, BrushSetterHandler brushSetter)
{
var disposables = new CompositeDisposable();

var compositionBrush = brush.CompositionBrush;
var compositionBrush = compositor.CreateColorBrush(brush.FallbackColorWithOpacity);

//brush.RegisterDisposablePropertyChangedCallback(
// XamlCompositionBrushBase.CompositionBrushProperty,
// (s, e) => brushSetter(((CompositionBrush)e.NewValue))
//)
//.DisposeWith(disposables);
brush.RegisterDisposablePropertyChangedCallback(
AcrylicBrush.FallbackColorProperty,
(s, colorArg) => compositionBrush.Color = brush.FallbackColorWithOpacity
)
.DisposeWith(disposables);

brush.RegisterDisposablePropertyChangedCallback(
AcrylicBrush.OpacityProperty,
(s, colorArg) => compositionBrush.Color = brush.FallbackColorWithOpacity
)
.DisposeWith(disposables);

brushSetter(compositionBrush);

Expand Down

0 comments on commit 9f5e1a8

Please sign in to comment.