From 63aa71c3181fdfde39ab97b823ec407d5045901a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 11 Jan 2019 16:52:56 -0500 Subject: [PATCH] Respond to CR. --- .../ViewControllers/PhotoLibrary/PhotoLibrary.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift index d30f57fa1..14d79b05f 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift @@ -48,19 +48,22 @@ class PhotoPickerAssetItem: PhotoGridItem { func asyncThumbnail(completion: @escaping (UIImage?) -> Void) -> UIImage? { var syncImageResult: UIImage? - var hasCompleted = false + var hasLoadedImage = false // Surprisingly, iOS will opportunistically run the completion block sync if the image is - // already available + // already available. photoCollectionContents.requestThumbnail(for: self.asset, thumbnailSize: photoMediaSize.thumbnailSize) { image, _ in DispatchMainThreadSafe({ syncImageResult = image // Once we've _successfully_ completed (e.g. invoked the completion with - // a non-nil image), don't invoke the completion again. - if !hasCompleted { + // a non-nil image), don't invoke the completion again with a nil argument. + if !hasLoadedImage || image != nil { completion(image) - hasCompleted = image != nil + + if image != nil { + hasLoadedImage = true + } } }) }