@@ -14,7 +14,7 @@ public class Tile : AuroraViewBase
14
14
15
15
private readonly string _rippleAnimationName , _tapAnimationName ;
16
16
17
- private readonly object _pictureLock = new ( ) ;
17
+ private readonly Lock _pictureLock = new ( ) ;
18
18
19
19
private SKPoint _lastTouchLocation ;
20
20
private double _rippleAnimationPercentage , _tapAnimationPercentage ;
@@ -24,9 +24,7 @@ public class Tile : AuroraViewBase
24
24
private SKPaint _fontPaint ;
25
25
private SKPaint _overlayPaint ;
26
26
27
- private SKSvg _svg ;
28
-
29
- private string _pictureName ;
27
+ private SKSvg ? _svg ;
30
28
31
29
private bool _tapped ;
32
30
@@ -420,6 +418,7 @@ protected override void Detached()
420
418
_fontPaint ? . Dispose ( ) ;
421
419
_overlayPaint ? . Dispose ( ) ;
422
420
_svg ? . Dispose ( ) ;
421
+ _svg = null ;
423
422
424
423
base . Detached ( ) ;
425
424
}
@@ -545,49 +544,52 @@ protected override void PaintControl(SKSurface surface, SKImageInfo info)
545
544
}
546
545
}
547
546
548
- if ( ! string . IsNullOrEmpty ( _pictureName ) )
547
+ lock ( _pictureLock )
549
548
{
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 ) ) ;
556
557
557
- var imageSize = contentRect . AspectFit ( _svg . Picture . CullRect . Size ) ;
558
+ var imageSize = contentRect . AspectFit ( _svg . Picture . CullRect . Size ) ;
558
559
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 ;
563
564
564
- var svgScale = SKMatrix . CreateScale ( scaleAmount , scaleAmount ) ;
565
+ var svgScale = SKMatrix . CreateScale ( scaleAmount , scaleAmount ) ;
565
566
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 ) ) ;
570
571
571
- svgScale = svgScale . PostConcat ( translation ) ;
572
+ svgScale = svgScale . PostConcat ( translation ) ;
572
573
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
576
589
{
577
- _overlayPaint . BlendMode = SKBlendMode . SrcATop ;
578
- _overlayPaint . IsAntialias = true ;
579
- _overlayPaint . Color = this . OverlayColor . ToSKColor ( ) ;
580
-
581
- canvas . SaveLayer ( null ) ;
582
- canvas . Clear ( ) ;
583
590
canvas . DrawPicture ( _svg . Picture , ref svgScale ) ;
584
- canvas . DrawPaint ( _overlayPaint ) ;
585
591
}
586
592
}
587
- else
588
- {
589
- canvas . DrawPicture ( _svg . Picture , ref svgScale ) ;
590
- }
591
593
}
592
594
}
593
595
@@ -725,23 +727,13 @@ private void SetSvgResource()
725
727
{
726
728
string embeddedImageName = EmbeddedImageName ;
727
729
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
-
739
730
lock ( _pictureLock )
740
731
{
741
732
using var imageStream = EmbeddedResourceLoader . Load ( embeddedImageName ) ;
742
733
_svg = new SKSvg ( ) ;
743
734
_svg . Load ( imageStream ) ;
744
- _pictureName = embeddedImageName ;
745
735
}
736
+
737
+ this . InvalidateSurface ( ) ;
746
738
}
747
739
}
0 commit comments