@@ -33,55 +33,12 @@ public IconCacheBase()
3333 public async Task < Image > IconFromSvg ( string svgName , Size size , string additionalCacheKey = "" , Color ? colorOverride = null ) =>
3434 new ( )
3535 {
36- Source = await SourceFromSvg ( svgName , size , additionalCacheKey , colorOverride ) ,
36+ Source = await ImageSourceFromSvg ( svgName , size , additionalCacheKey , colorOverride ) ,
3737 } ;
3838
39- public Task < ImageSource > SourceFromSvg ( string svgName , double squareSize = 22d , string additionalCacheKey = "" , Color ? colorOverride = null ) => SourceFromSvg ( svgName , new Size ( squareSize , squareSize ) , additionalCacheKey , colorOverride ) ;
39+ public Task < ImageSource > ImageSourceFromRawSvg ( string svgName , string svgValue , double squareSize = 22d , string additionalCacheKey = "" , Color ? colorOverride = null ) => ImageSourceFromRawSvg ( svgName , svgValue , new Size ( squareSize , squareSize ) , additionalCacheKey , colorOverride ) ;
4040
41- public async Task < ImageSource > SourceFromSvg ( string svgName , Size size , string additionalCacheKey = "" , Color ? colorOverride = null )
42- {
43- string key = CreateIconKey ( svgName , size , additionalCacheKey , colorOverride ) ;
44-
45- try
46- {
47- await _iconLock . WaitAsync ( ) . ConfigureAwait ( false ) ;
48-
49- if ( _resolvedIcons . ContainsKey ( key ) )
50- {
51- return new FileImageSource { File = _resolvedIcons [ key ] } ;
52- }
53-
54- string ? diskCachedImage = GetImagePathFromDiskCache ( key ) ;
55-
56- if ( ! string . IsNullOrEmpty ( diskCachedImage ) )
57- {
58- _resolvedIcons [ key ] = diskCachedImage ;
59- return new FileImageSource { File = diskCachedImage } ;
60- }
61-
62- await GenerateImageFromEmbedded ( key , svgName , size , colorOverride ) . ConfigureAwait ( false ) ;
63-
64- diskCachedImage = GetImagePathFromDiskCache ( key ) ;
65-
66- _resolvedIcons [ key ] = diskCachedImage ;
67-
68- return new FileImageSource { File = diskCachedImage } ;
69- }
70- catch ( Exception ex )
71- {
72- Console . WriteLine ( $ "[SVG Exception]\t { ex } ") ;
73-
74- return new FileImageSource ( ) ;
75- }
76- finally
77- {
78- _iconLock . Release ( ) ;
79- }
80- }
81-
82- public Task < ImageSource > SourceFromRawSvg ( string svgName , string svgValue , double squareSize = 22d , string additionalCacheKey = "" , Color ? colorOverride = null ) => SourceFromRawSvg ( svgName , svgValue , new Size ( squareSize , squareSize ) , additionalCacheKey , colorOverride ) ;
83-
84- public async Task < ImageSource > SourceFromRawSvg ( string svgName , string svgValue , Size size , string additionalCacheKey = "" , Color ? colorOverride = null )
41+ public async Task < ImageSource > ImageSourceFromRawSvg ( string svgName , string svgValue , Size size , string additionalCacheKey = "" , Color ? colorOverride = null )
8542 {
8643 try
8744 {
@@ -91,15 +48,15 @@ public async Task<ImageSource> SourceFromRawSvg(string svgName, string svgValue,
9148
9249 if ( _resolvedIcons . ContainsKey ( key ) )
9350 {
94- return new FileImageSource { File = _resolvedIcons [ key ] } ;
51+ return GetPlatformImageSource ( _resolvedIcons [ key ] ) ;
9552 }
9653
9754 string ? diskCachedImage = GetImagePathFromDiskCache ( key ) ;
9855
9956 if ( ! string . IsNullOrEmpty ( diskCachedImage ) )
10057 {
10158 _resolvedIcons [ key ] = diskCachedImage ;
102- return new FileImageSource { File = diskCachedImage } ;
59+ return GetPlatformImageSource ( diskCachedImage ) ;
10360 }
10461
10562 await GenerateImageFromRaw ( key , svgValue , size , colorOverride ) . ConfigureAwait ( false ) ;
@@ -108,18 +65,18 @@ public async Task<ImageSource> SourceFromRawSvg(string svgName, string svgValue,
10865
10966 _resolvedIcons [ key ] = diskCachedImage ;
11067
111- return new FileImageSource { File = diskCachedImage } ;
68+ return GetPlatformImageSource ( diskCachedImage ) ;
11269 }
11370 finally
11471 {
11572 _iconLock . Release ( ) ;
11673 }
11774 }
11875
119- public Task < FileImageSource > FileImageSourceFromSvg ( string svgName , double squareSize = 22d , string additionalCacheKey = "" , Color ? colorOverride = null ) =>
120- FileImageSourceFromSvg ( svgName , new Size ( squareSize , squareSize ) , additionalCacheKey , colorOverride ) ;
76+ public Task < ImageSource > ImageSourceFromSvg ( string svgName , double squareSize = 22d , string additionalCacheKey = "" , Color ? colorOverride = null ) =>
77+ ImageSourceFromSvg ( svgName , new Size ( squareSize , squareSize ) , additionalCacheKey , colorOverride ) ;
12178
122- public async Task < FileImageSource > FileImageSourceFromSvg ( string svgName , Size size , string additionalCacheKey = "" , Color ? colorOverride = null )
79+ public async Task < ImageSource > ImageSourceFromSvg ( string svgName , Size size , string additionalCacheKey = "" , Color ? colorOverride = null )
12380 {
12481 try
12582 {
@@ -129,15 +86,15 @@ public async Task<FileImageSource> FileImageSourceFromSvg(string svgName, Size s
12986
13087 if ( _resolvedIcons . ContainsKey ( key ) )
13188 {
132- return new FileImageSource { File = _resolvedIcons [ key ] } ;
89+ return GetPlatformImageSource ( _resolvedIcons [ key ] ) ;
13390 }
13491
13592 string ? diskCachedImage = GetImagePathFromDiskCache ( key ) ;
13693
13794 if ( ! string . IsNullOrEmpty ( diskCachedImage ) )
13895 {
13996 _resolvedIcons [ key ] = diskCachedImage ;
140- return new FileImageSource { File = diskCachedImage } ;
97+ return GetPlatformImageSource ( diskCachedImage ) ;
14198 }
14299
143100 await GenerateImageFromEmbedded ( key , svgName , size , colorOverride ) . ConfigureAwait ( false ) ;
@@ -146,25 +103,30 @@ public async Task<FileImageSource> FileImageSourceFromSvg(string svgName, Size s
146103
147104 _resolvedIcons [ key ] = diskCachedImage ;
148105
149- if ( DeviceInfo . Current . Platform == DevicePlatform . iOS )
150- {
151- return new FileImageSource { File = diskCachedImage } ;
152- }
153-
154- return new FileImageSource { File = diskCachedImage } ;
106+ return GetPlatformImageSource ( diskCachedImage ) ;
155107 }
156108 catch ( Exception ex )
157109 {
158110 Console . WriteLine ( $ "[SVG Exception]\t { ex } ") ;
159111
160- return new FileImageSource ( ) ;
112+ return GetPlatformImageSource ( ) ;
161113 }
162114 finally
163115 {
164116 _iconLock . Release ( ) ;
165117 }
166118 }
167119
120+ private ImageSource GetPlatformImageSource ( string ? file = null )
121+ {
122+ if ( DeviceInfo . Current . Platform == DevicePlatform . Android )
123+ {
124+ return new NoCacheFileImageSource { File = file } ;
125+ }
126+
127+ return new FileImageSource { File = file } ;
128+ }
129+
168130 private string ? GetImagePathFromDiskCache ( string key )
169131 {
170132 if ( ! Directory . Exists ( PlatformInfo . IconCacheDirectory ) )
0 commit comments