Skip to content

Adjust RadialGradientBrush base type to match UWP - #7170

Closed
Youssef1313 wants to merge 6 commits into
unoplatform:masterfrom
Youssef1313:radialgradientbrush-inh
Closed

Youssef1313 wants to merge 6 commits into
unoplatform:masterfrom
Youssef1313:radialgradientbrush-inh

Conversation

@Youssef1313

@Youssef1313 Youssef1313 commented Sep 22, 2021 •

Copy link
Copy Markdown
Member

GitHub Issue (If applicable): Part of #2240

PR Type

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@gitpod-io

gitpod-io Bot commented Sep 22, 2021

Copy link
Copy Markdown

@Youssef1313
Youssef1313 force-pushed the radialgradientbrush-inh branch 3 times, most recently from 7455264 to 2418575 Compare September 22, 2021 13:01
BREAKING CHANGE: `RadialGradientBrush` no longer derives from `GradientBrush`. It now derives from `XamlCompositionBrushBase`.
@Youssef1313
Youssef1313 force-pushed the radialgradientbrush-inh branch from 2418575 to 37cb9b2 Compare September 22, 2021 13:06
@Youssef1313 Youssef1313 changed the title DRAFT - DO NOT REVIEW: Adjust RadialGradientBrush base type to match UWP Adjust RadialGradientBrush base type to match UWP Sep 22, 2021
@Youssef1313
Youssef1313 marked this pull request as ready for review September 22, 2021 13:06
@Youssef1313
Youssef1313 requested a review from a team September 22, 2021 13:06
@Youssef1313

Copy link
Copy Markdown
Member Author

@jeromelaban Will I get the "found UI Test snapshots differences" comment from @nventive-devops if this broke something or I need to validate screenshots manually from CI artifacts?

Comment on lines +277 to +287
else if (newValue is RadialGradientBrush rgb)
{
_borderBrushColorChanged.Disposable = rgb.RegisterDisposablePropertyChangedCallback(
RadialGradientBrush.FallbackColorProperty,
(s, colorArg) => OnBorderBrushChangedPartial()
);
_borderBrushOpacityChanged.Disposable = rgb.RegisterDisposablePropertyChangedCallback(
RadialGradientBrush.OpacityProperty,
(s, _) => OnBorderBrushChangedPartial()
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to refactor this one day... that's definitely not a good pattern and Border knows too much about specific brushes...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carldebilly Agreed. This should somehow be moved to each Brush-specific class. Will look into that as a follow-up

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dr1rrb will be pleased :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate this kind of "type enumeration". WinUI is build using inheritance, we have to follow that pattern and take advantage of it when possible by moving that kind of logic in the implementation itself.

Comment thread src/Uno.UI/UI/Xaml/Media/Brush.skia.cs Resolved
Comment on lines +1 to +12
using Microsoft.UI.Xaml.Media;

namespace Windows.UI.Xaml.Media
{
/// <summary>
/// This interface defines common functionality between <see cref="GradientBrush"/> and <see cref="RadialGradientBrush"/>
/// since, in UWP, <see cref="RadialGradientBrush"/> doesn't derive from <see cref="GradientBrush"/>
/// </summary>
internal partial interface IGradientBrush
{
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally here I would prefer to define a private type _Layer per platform and use it in a single file interface, I find this much more readable / maintainable / converging:

Suggested change
using Microsoft.UI.Xaml.Media;
namespace Windows.UI.Xaml.Media
{
/// <summary>
/// This interface defines common functionality between <see cref="GradientBrush"/> and <see cref="RadialGradientBrush"/>
/// since, in UWP, <see cref="RadialGradientBrush"/> doesn't derive from <see cref="GradientBrush"/>
/// </summary>
internal partial interface IGradientBrush
{
}
}
#if __IOS__ || __MACOS__
using _Layer = UIKit.CALayer;
#elif __ANDROID__
using _Layer = Shader;
#elif __WASM__
using _Layer = SvgElement;
#endif
using Microsoft.UI.Xaml.Media;
namespace Windows.UI.Xaml.Media
{
/// <summary>
/// This interface defines common functionality between <see cref="GradientBrush"/> and <see cref="RadialGradientBrush"/>
/// since, in UWP, <see cref="RadialGradientBrush"/> doesn't derive from <see cref="GradientBrush"/>
/// </summary>
internal partial interface IGradientBrush
{
_Shader GetShader(Windows.Foundation.Rect destinationRect);
}
}

Thought @jeromelaban , @carldebilly @davidjohnoliver ?

@Youssef1313 Youssef1313 Sep 27, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dr1rrb I wanted the method name to match the terminology of each platform (ie, GetShader for Android, GetLayer for iOS & macOS, ToCssString and ToSvgElement on Wasm). But open to change that.

cc @jeromelaban @carldebilly @davidjohnoliver for opinions.

@carldebilly carldebilly Oct 19, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The principle of unifying the name on all platforms is cool... but since the interface & signatures are different for each, I fail to see the value of such unification.

TBH I have no strong opinion about this.

@Youssef1313
Youssef1313 requested a review from dr1rrb September 27, 2021 18:18
@Youssef1313

Copy link
Copy Markdown
Member Author

@ebariche Can you take a look please?

@Youssef1313

Copy link
Copy Markdown
Member Author

@ebariche It looks like we have missed this PR for API alignments.

@jeromelaban

Copy link
Copy Markdown
Member

@Youssef1313 it does not look like it's breaking, unless I missed something. Let's retarget it to master and see from there.

@jeromelaban
jeromelaban changed the base branch from feature/api-alignments to master January 20, 2022 13:50
{
[ContentProperty(Name = nameof(GradientStops))]
public sealed partial class RadialGradientBrush : GradientBrush
public sealed partial class RadialGradientBrush : XamlCompositionBrushBase, IGradientBrush

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeromelaban I think changing the base type here is breaking.

return AssignAndObserveSolidColorBrush(colorBrush, compositor, brushSetter);
}
else if (brush is GradientBrush gradientBrush)
else if (brush is GradientBrush gradientBrush) // TOOD: RadialGradient

@ebariche ebariche Jan 20, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something is missing here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ebariche Indeed. RadialGradientBrush used to fall into AssignAndObserveGradientBrush. Now it falls under AssignAndObserveXamlCompositionBrush.

I think we need to confirm if this regresses any scenario on Skia, and fix it.

@MartinZikmund

Copy link
Copy Markdown
Member

Superseded by #12142

@Youssef1313
Youssef1313 deleted the radialgradientbrush-inh branch May 3, 2023 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants