Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying global styles to shadows #20203

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Jan 28, 2024

Description of Change

I have implemented 2 solutions for this. I don't know which one is better, so please let me know and I will keep the one you prefer.

Issues Fixed

Fixes #19560

Screen.Recording.2024-01-28.at.01.51.32.mov

@kubaflo kubaflo requested a review from a team as a code owner January 28, 2024 00:59
@ghost ghost added the community ✨ Community Contribution label Jan 28, 2024
@ghost
Copy link

ghost commented Jan 28, 2024

Hey there @kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@jsuarezruiz jsuarezruiz added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label Jan 29, 2024
@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@cmartinezcxm
Copy link

Hey @kubaflo Thanks for the suggested PR, could you finish the merge of this?

@jsuarezruiz
Copy link
Contributor

@kubaflo Could you rebase to fix the conflict?, thnx!

@kubaflo kubaflo force-pushed the styles-for-shadows-fix branch from d80ea59 to 8058667 Compare June 11, 2024 15:24
@kubaflo
Copy link
Contributor Author

kubaflo commented Jun 11, 2024

@jsuarezruiz rebased, and, thanks to it, only one change was needed to make it work :)

@@ -19,6 +19,13 @@ public class Shadow : Element, IShadow

Paint IShadow.Paint => Brush;

internal MergedStyle _mergedStyle;

public Shadow()
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't look like the right fix. The problem probably comes from the Shadow isn't properly parented.
(parenting code was probably removed to 'fix' a memory leak, but we have a PR avoiding that leak)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@StephaneDelcroix I tried a solution with setting the parent visual element as a parent here:

void NotifyBackgroundChanges()
{
var background = Background;
if (background is ImmutableBrush)
return;
if (background != null)
{
SetInheritedBindingContext(background, BindingContext);
_backgroundChanged ??= (sender, e) => OnPropertyChanged(nameof(Background));
_backgroundProxy ??= new();
_backgroundProxy.Subscribe(background, _backgroundChanged);
OnParentResourcesChanged(this.GetMergedResources());
((IElementDefinition)this).AddResourcesChangedListener(background.OnParentResourcesChanged);
}
}

but it didn't work :/

it's why I did the same thing as, for example, Span does

internal readonly MergedStyle _mergedStyle;
/// <include file="../../docs/Microsoft.Maui.Controls/Span.xml" path="//Member[@MemberName='.ctor']/Docs/*" />
public Span()
{
_mergedStyle = new MergedStyle(GetType(), this);
}

@jsuarezruiz
Copy link
Contributor

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shadow does not honour Styles
4 participants