@@ -275,9 +275,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
275
275
self . imageModel. placeholderView? . isHidden = false
276
276
self . imageHandler. failureBlock ? ( error ?? NSError ( ) )
277
277
}
278
- // Finished loading
279
- configureView ( view, context: context)
280
- layoutView ( view, context: context)
278
+ // Finished loading, async
279
+ finishUpdateView ( view, context: context, image: image)
281
280
}
282
281
}
283
282
@@ -310,6 +309,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
310
309
#endif
311
310
context. coordinator. imageLoading. imageName = name
312
311
view. wrapped. image = image
312
+ // Finished loading, sync
313
+ finishUpdateView ( view, context: context, image: image)
313
314
}
314
315
315
316
private func updateViewForData( _ data: Data ? , view: AnimatedImageViewWrapper , context: Context ) {
@@ -323,6 +324,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
323
324
}
324
325
context. coordinator. imageLoading. imageData = data
325
326
view. wrapped. image = image
327
+ // Finished loading, sync
328
+ finishUpdateView ( view, context: context, image: image)
326
329
}
327
330
328
331
private func updateViewForURL( _ url: URL ? , view: AnimatedImageViewWrapper , context: Context ) {
@@ -347,6 +350,8 @@ public struct AnimatedImage : PlatformViewRepresentable {
347
350
setupIndicator ( view, context: context)
348
351
loadImage ( view, context: context)
349
352
}
353
+ // Finished loading, sync
354
+ finishUpdateView ( view, context: context, image: view. wrapped. image)
350
355
}
351
356
352
357
func updateView( _ view: AnimatedImageViewWrapper , context: Context ) {
@@ -364,9 +369,6 @@ public struct AnimatedImage : PlatformViewRepresentable {
364
369
break // impossible
365
370
}
366
371
367
- // Finished loading
368
- configureView ( view, context: context)
369
- layoutView ( view, context: context)
370
372
if let viewUpdateBlock = imageHandler. viewUpdateBlock {
371
373
viewUpdateBlock ( view. wrapped, context)
372
374
}
@@ -384,6 +386,17 @@ public struct AnimatedImage : PlatformViewRepresentable {
384
386
}
385
387
}
386
388
389
+ func finishUpdateView( _ view: AnimatedImageViewWrapper , context: Context , image: PlatformImage ? ) {
390
+ // Finished loading
391
+ if let imageSize = image? . size {
392
+ view. imageSize = imageSize
393
+ } else {
394
+ view. imageSize = nil
395
+ }
396
+ configureView ( view, context: context)
397
+ layoutView ( view, context: context)
398
+ }
399
+
387
400
func layoutView( _ view: AnimatedImageViewWrapper , context: Context ) {
388
401
// AspectRatio && ContentMode
389
402
#if os(macOS)
0 commit comments