Skip to content

Commit 2bbd4d8

Browse files
committed
Merge branch 'develop'
2 parents b973c1a + aa99d9e commit 2bbd4d8

File tree

7 files changed

+84
-85
lines changed

7 files changed

+84
-85
lines changed

AuroraControlsMaui/Chip.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ protected override void Detached()
564564
{
565565
_backgroundPath?.Dispose();
566566
_leadingSvg?.Dispose();
567+
_leadingSvg = null;
567568
_trailingSvg?.Dispose();
569+
_trailingSvg = null;
568570
base.Detached();
569571
}
570572

AuroraControlsMaui/PlatformUnderlayDrawable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void OnPaintSurface(object? sender, SKPaintSurfaceEventArgs e)
164164
}
165165

166166
#elif ANDROID
167-
private SKCanvasView _canvas;
167+
private SKCanvasView? _canvas;
168168

169169
private Android.Widget.Button _commandButton;
170170

@@ -594,7 +594,7 @@ private void DrawUnderlay(IUnderlayDrawable underlayDrawable, View element, Rect
594594
}
595595

596596
double hasValueAnimationPercentage =
597-
underlayDrawable.AlwaysShowPlaceholder
597+
underlayDrawable.AlwaysShowPlaceholder || isError
598598
? 1d
599599
: underlayDrawable.HasValueAnimationPercentage;
600600

AuroraControlsMaui/SegmentedControl.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public enum SegmentedControlStyle
443443

444444
public class Segment : BindableObject, IDisposable
445445
{
446-
private SKSvg _svg;
446+
private SKSvg? _svg;
447447

448448
private bool _disposedValue;
449449

@@ -482,7 +482,7 @@ public string EmbeddedImageName
482482
set => SetValue(EmbeddedImageNameProperty, value);
483483
}
484484

485-
public SKSvg SVG => _svg;
485+
public SKSvg? SVG => _svg;
486486

487487
public static readonly BindableProperty ValueProperty =
488488
BindableProperty.Create(nameof(Value), typeof(object), typeof(Segment));
@@ -532,6 +532,7 @@ protected virtual void Dispose(bool disposing)
532532
if (disposing)
533533
{
534534
_svg?.Dispose();
535+
_svg = null;
535536
}
536537

537538
_disposedValue = true;

AuroraControlsMaui/SvgImageButton.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public enum SvgImageButtonBackgroundShape
1818
public class SvgImageButton : AuroraViewBase
1919
#pragma warning restore CA1001
2020
{
21-
private readonly object _pictureLock = new();
21+
private readonly Lock _pictureLock = new();
2222

2323
private SKRect _touchArea;
24-
private SKSvg _svg;
25-
26-
private string _pictureName;
24+
private SKSvg? _svg;
2725

2826
private SKPoint _lastTouchLocation;
2927
private double _animationPercentage = 0d;
@@ -228,7 +226,11 @@ protected override void Attached()
228226

229227
protected override void Detached()
230228
{
231-
_svg?.Picture?.Dispose();
229+
lock (_pictureLock)
230+
{
231+
_svg?.Picture?.Dispose();
232+
_svg = null;
233+
}
232234

233235
base.Detached();
234236
}
@@ -283,8 +285,13 @@ protected override void PaintControl(SKSurface surface, SKImageInfo info)
283285

284286
canvas.Clear();
285287

286-
if (_svg?.Picture != null)
288+
lock (_pictureLock)
287289
{
290+
if (_svg == null)
291+
{
292+
return;
293+
}
294+
288295
float svgWidth = _svg.Picture.CullRect.Width;
289296
float svgHeight = _svg.Picture.CullRect.Height;
290297

@@ -413,12 +420,6 @@ private void SetSvgResource()
413420
string embeddedImageName = EmbeddedImageName;
414421

415422
if (string.IsNullOrEmpty(embeddedImageName))
416-
{
417-
_pictureName = null;
418-
return;
419-
}
420-
421-
if (!string.IsNullOrEmpty(_pictureName) && _pictureName.Equals(embeddedImageName))
422423
{
423424
return;
424425
}
@@ -428,8 +429,9 @@ private void SetSvgResource()
428429
using var imageStream = EmbeddedResourceLoader.Load(embeddedImageName);
429430
_svg = new SKSvg();
430431
_svg.Load(imageStream);
431-
_pictureName = embeddedImageName;
432432
}
433+
434+
this.InvalidateSurface();
433435
}
434436

435437
/// <summary>

AuroraControlsMaui/SvgImageView.cs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ namespace AuroraControls;
1010
public class SvgImageView : AuroraViewBase
1111
#pragma warning restore CA1001 // Types that own disposable fields should be disposable
1212
{
13-
private readonly object _pictureLock = new();
13+
private readonly Lock _pictureLock = new();
1414

1515
private SKPaint _overlayPaint;
1616

17-
private SKSvg _svg;
18-
19-
private string _pictureName;
17+
private SKSvg? _svg;
2018

2119
/// <summary>
2220
/// The name of the embedded image to display.
@@ -105,6 +103,7 @@ protected override void Detached()
105103
{
106104
_overlayPaint?.Dispose();
107105
_svg?.Dispose();
106+
_svg = null;
108107

109108
base.Detached();
110109
}
@@ -129,8 +128,13 @@ protected override void PaintControl(SKSurface surface, SKImageInfo info)
129128

130129
canvas.Clear();
131130

132-
if (!string.IsNullOrEmpty(_pictureName) && _svg?.Picture != null)
131+
lock (_pictureLock)
133132
{
133+
if (_svg == null)
134+
{
135+
return;
136+
}
137+
134138
float scaleAmount =
135139
this.MaxImageSize == Size.Zero
136140
? Math.Min(displayArea.Width / _svg.Picture.CullRect.Width, displayArea.Height / _svg.Picture.CullRect.Height)
@@ -144,13 +148,13 @@ protected override void PaintControl(SKSurface surface, SKImageInfo info)
144148

145149
canvas.DrawPicture(_svg.Picture, ref scale);
146150

147-
if (OverlayColor != Colors.Transparent && _overlayPaint != null)
151+
if (this.OverlayColor != Colors.Transparent && _overlayPaint != null)
148152
{
149153
using (new SKAutoCanvasRestore(canvas))
150154
{
151155
_overlayPaint.BlendMode = SKBlendMode.SrcIn;
152156

153-
_overlayPaint.Color = OverlayColor.ToSKColor();
157+
_overlayPaint.Color = this.OverlayColor.ToSKColor();
154158
_overlayPaint.IsAntialias = true;
155159

156160
canvas.DrawPaint(_overlayPaint);
@@ -166,23 +170,13 @@ private void SetSvgResource()
166170
{
167171
string embeddedImageName = EmbeddedImageName;
168172

169-
if (string.IsNullOrEmpty(embeddedImageName))
170-
{
171-
_pictureName = null;
172-
return;
173-
}
174-
175-
if (!string.IsNullOrEmpty(_pictureName) && _pictureName.Equals(embeddedImageName))
176-
{
177-
return;
178-
}
179-
180173
lock (_pictureLock)
181174
{
182175
using var imageStream = EmbeddedResourceLoader.Load(embeddedImageName);
183176
_svg = new SKSvg();
184177
_svg.Load(imageStream);
185-
_pictureName = embeddedImageName;
186178
}
179+
180+
this.InvalidateSurface();
187181
}
188182
}

AuroraControlsMaui/Tile.cs

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Tile : AuroraViewBase
1414

1515
private readonly string _rippleAnimationName, _tapAnimationName;
1616

17-
private readonly object _pictureLock = new();
17+
private readonly Lock _pictureLock = new();
1818

1919
private SKPoint _lastTouchLocation;
2020
private double _rippleAnimationPercentage, _tapAnimationPercentage;
@@ -24,9 +24,7 @@ public class Tile : AuroraViewBase
2424
private SKPaint _fontPaint;
2525
private SKPaint _overlayPaint;
2626

27-
private SKSvg _svg;
28-
29-
private string _pictureName;
27+
private SKSvg? _svg;
3028

3129
private bool _tapped;
3230

@@ -420,6 +418,7 @@ protected override void Detached()
420418
_fontPaint?.Dispose();
421419
_overlayPaint?.Dispose();
422420
_svg?.Dispose();
421+
_svg = null;
423422

424423
base.Detached();
425424
}
@@ -545,49 +544,52 @@ protected override void PaintControl(SKSurface surface, SKImageInfo info)
545544
}
546545
}
547546

548-
if (!string.IsNullOrEmpty(_pictureName))
547+
lock (_pictureLock)
549548
{
550-
// TODO: The text measurement here seems not right
551-
var contentRect = new SKRect(
552-
rect.Left + (float)(this.ContentPadding.Left * _scale),
553-
rect.Top + (float)(this.ContentPadding.Top * _scale),
554-
rect.Right - (float)(this.ContentPadding.Right * _scale),
555-
rect.Bottom - textBounds.Height - (float)(this.ContentPadding.Bottom * _scale));
549+
if (_svg != null)
550+
{
551+
// TODO: The text measurement here seems not right
552+
var contentRect = new SKRect(
553+
rect.Left + (float)(this.ContentPadding.Left * _scale),
554+
rect.Top + (float)(this.ContentPadding.Top * _scale),
555+
rect.Right - (float)(this.ContentPadding.Right * _scale),
556+
rect.Bottom - textBounds.Height - (float)(this.ContentPadding.Bottom * _scale));
556557

557-
var imageSize = contentRect.AspectFit(_svg.Picture.CullRect.Size);
558+
var imageSize = contentRect.AspectFit(_svg.Picture.CullRect.Size);
558559

559-
float scaleAmount =
560-
this.MaxImageSize == Size.Zero
561-
? Math.Min(imageSize.Width / _svg.Picture.CullRect.Width, imageSize.Height / _svg.Picture.CullRect.Height)
562-
: 1f;
560+
float scaleAmount =
561+
this.MaxImageSize == Size.Zero
562+
? Math.Min(imageSize.Width / _svg.Picture.CullRect.Width, imageSize.Height / _svg.Picture.CullRect.Height)
563+
: 1f;
563564

564-
var svgScale = SKMatrix.CreateScale(scaleAmount, scaleAmount);
565+
var svgScale = SKMatrix.CreateScale(scaleAmount, scaleAmount);
565566

566-
var translation =
567-
this.MaxImageSize == Size.Zero
568-
? SKMatrix.CreateTranslation(imageSize.Left, imageSize.Top)
569-
: SKMatrix.CreateTranslation(imageSize.MidX - (_svg.Picture.CullRect.Width / 2f), imageSize.MidY - (_svg.Picture.CullRect.Height / 2f));
567+
var translation =
568+
this.MaxImageSize == Size.Zero
569+
? SKMatrix.CreateTranslation(imageSize.Left, imageSize.Top)
570+
: SKMatrix.CreateTranslation(imageSize.MidX - (_svg.Picture.CullRect.Width / 2f), imageSize.MidY - (_svg.Picture.CullRect.Height / 2f));
570571

571-
svgScale = svgScale.PostConcat(translation);
572+
svgScale = svgScale.PostConcat(translation);
572573

573-
if (this.OverlayColor != Colors.Transparent)
574-
{
575-
using (new SKAutoCanvasRestore(canvas))
574+
if (this.OverlayColor != Colors.Transparent)
575+
{
576+
using (new SKAutoCanvasRestore(canvas))
577+
{
578+
_overlayPaint.BlendMode = SKBlendMode.SrcATop;
579+
_overlayPaint.IsAntialias = true;
580+
_overlayPaint.Color = this.OverlayColor.ToSKColor();
581+
582+
canvas.SaveLayer(null);
583+
canvas.Clear();
584+
canvas.DrawPicture(_svg.Picture, ref svgScale);
585+
canvas.DrawPaint(_overlayPaint);
586+
}
587+
}
588+
else
576589
{
577-
_overlayPaint.BlendMode = SKBlendMode.SrcATop;
578-
_overlayPaint.IsAntialias = true;
579-
_overlayPaint.Color = this.OverlayColor.ToSKColor();
580-
581-
canvas.SaveLayer(null);
582-
canvas.Clear();
583590
canvas.DrawPicture(_svg.Picture, ref svgScale);
584-
canvas.DrawPaint(_overlayPaint);
585591
}
586592
}
587-
else
588-
{
589-
canvas.DrawPicture(_svg.Picture, ref svgScale);
590-
}
591593
}
592594
}
593595

@@ -725,23 +727,13 @@ private void SetSvgResource()
725727
{
726728
string embeddedImageName = EmbeddedImageName;
727729

728-
if (string.IsNullOrEmpty(embeddedImageName))
729-
{
730-
_pictureName = null;
731-
return;
732-
}
733-
734-
if (!string.IsNullOrEmpty(_pictureName) && _pictureName.Equals(embeddedImageName))
735-
{
736-
return;
737-
}
738-
739730
lock (_pictureLock)
740731
{
741732
using var imageStream = EmbeddedResourceLoader.Load(embeddedImageName);
742733
_svg = new SKSvg();
743734
_svg.Load(imageStream);
744-
_pictureName = embeddedImageName;
745735
}
736+
737+
this.InvalidateSurface();
746738
}
747739
}

AuroraControlsMaui/UnderlayDrawableElement.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ public static class UnderlayDrawableElement
3636
BindableProperty.Create(nameof(IUnderlayDrawable.HasValueAnimationPercentage), typeof(double), typeof(IUnderlayDrawable), 0.0d);
3737

3838
public static readonly BindableProperty IsErrorProperty =
39-
BindableProperty.Create(nameof(IUnderlayDrawable.IsError), typeof(bool), typeof(IUnderlayDrawable), false);
39+
BindableProperty.Create(nameof(IUnderlayDrawable.IsError), typeof(bool), typeof(IUnderlayDrawable), false,
40+
propertyChanged:
41+
static (bindable, oldValue, newValue) =>
42+
{
43+
if (bindable is IUnderlayDrawable ud && oldValue is bool oldv && newValue is bool newv && !oldv && newv)
44+
{
45+
ud.HasValueAnimationPercentage = 1.0d;
46+
}
47+
});
4048

4149
public static readonly BindableProperty ErrorTextProperty =
4250
BindableProperty.Create(nameof(IUnderlayDrawable.ErrorText), typeof(string), typeof(IUnderlayDrawable));

0 commit comments

Comments
 (0)