Repository navigation
refactor: Refactor brushes - #12896
Conversation
3caa435 to
ba26db0
Compare
|
/azp run |
|
No commit pushedDate could be found for PR 12896 in repo unoplatform/uno |
ba26db0 to
23bcb9e
Compare
2880830 to
8739409
Compare
ca0131a to
0015c9b
Compare
|
Looks good to me! |
|
Only thing I just realized now - could we introduce some race condition in case the brush is unsubscribed during GC / Java finalizer? As we could be removing handler from the event at the same time as adding another one on the UI thread, theoretically? @jeromelaban |
|
Test failure on iOS: The actual color is still bluish, meaning the GradientStop change propagated correctly. But I don't know why iOS diverges so much from blue. Anyway, that doesn't look like an issue with this PR, so I'll adjust tolerance for iOS. |
| Action onInvalidateRender = () => backgroundLayer.FillColor = Brush.GetFallbackColor(background); | ||
| background.InvalidateRender += onInvalidateRender; | ||
| onInvalidateRender(); | ||
| new DisposableAction(() => background.InvalidateRender -= onInvalidateRender) |
There was a problem hiding this comment.
@Youssef1313 disposables.Add(() => background.InvalidateRender -= onInvalidateRender) should be available available to use.
There was a problem hiding this comment.
@jeromelaban It should be the same functionality? or is there any difference?
Martin will be refactoring BorderLayerRenderer anyway.
| ~Panel() | ||
| { | ||
| _backgroundBrushChangedProxy?.Unsubscribe(); | ||
| _borderBrushChangedProxy?.Unsubscribe(); | ||
| } |
There was a problem hiding this comment.
@Youssef1313 I don't think this is necessary. The proxy itself should be collected and that should be enough for the unsubscription to happen.
There was a problem hiding this comment.
The brushes hold a reference to the proxy via the event subscription. So long living brushes will cause proxies to leak unless the control calls Unsubscribe.
| protected override void JavaFinalize() | ||
| { | ||
| _backgroundBrushChangedProxy?.Unsubscribe(); | ||
| _borderBrushChangedProxy?.Unsubscribe(); | ||
| base.JavaFinalize(); | ||
| } |
There was a problem hiding this comment.
@Youssef1313 Same here, if javafinalize is called, the .NET GC should be invoked soon after.
There was a problem hiding this comment.
I added this to make sure we don't access a disposed object between collecting the native object and the managed object
GitHub Issue (If applicable): closes #12601. Partially addresses #8891
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
Copilot Summary
🤖 Generated by Copilot at 16c26cf
This pull request refactors various controls and classes to use the weak event proxy pattern for subscribing to brush changes, which improves memory management and performance. It also adds a new test class for the GradientBrush feature and a new base class for implementing the weak event proxy pattern. It deletes two unused files and fixes some minor issues with image brushes.
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Runresults.Other information
Internal Issue (If applicable):