Skip to content

Commit 0129a95

Browse files
Merge pull request #19184 from wordpress-mobile/issue/19183-pages-list-freeze
[Pages List] Fix app freeze when loading page with GIF as its featured image
2 parents e5c5153 + 2968549 commit 0129a95

6 files changed

Lines changed: 23 additions & 7 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
20.6
22
-----
33
* [*] [Jetpack-only] Recommend App: you can now share the Jetpack app with your friends. [#19174]
4+
* [*] Pages List: Fixed an issue where the app would freeze when opening the pages list if one of the featured images is a GIF. [#19184]
45

56

67
20.5

WordPress/Classes/Networking/MediaHost+Blog.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ extension MediaHost {
99
}
1010

1111
init(with blog: Blog, failure: (BlogError) -> ()) {
12+
let isAtomic = blog.isAtomic()
13+
self.init(with: blog, isAtomic: isAtomic, failure: failure)
14+
}
15+
16+
init(with blog: Blog, isAtomic: Bool, failure: (BlogError) -> ()) {
1217
self.init(isAccessibleThroughWPCom: blog.isAccessibleThroughWPCom(),
1318
isPrivate: blog.isPrivate(),
14-
isAtomic: blog.isAtomic(),
19+
isAtomic: isAtomic,
1520
siteID: blog.dotComID?.intValue,
1621
username: blog.usernameForSite,
1722
authToken: blog.authToken,

WordPress/Classes/Utility/Media/ImageLoader.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,24 @@ import AutomatticTracks
314314
// MARK: - Loading Media object
315315

316316
extension ImageLoader {
317-
@objc(loadImageFromMedia:preferredSize:placeholder:success:error:)
317+
@objc(loadImageFromMedia:preferredSize:placeholder:isBlogAtomic:success:error:)
318318
/// Load an image from the given Media object. If it's a gif, it will animate it.
319319
/// For any other type of media, this will load the corresponding static image.
320320
///
321321
/// - Parameters:
322322
/// - media: The media object
323323
/// - placeholder: A placeholder to show while the image is loading.
324324
/// - size: The preferred size of the image to load.
325+
/// - isBlogAtomic: Whether the blog associated to the media item is Atomic or not
325326
/// - success: A closure to be called if the image was loaded successfully.
326327
/// - error: A closure to be called if there was an error loading the image.
327328
///
328-
func loadImage(media: Media, preferredSize size: CGSize = .zero, placeholder: UIImage?, success: ImageLoaderSuccessBlock?, error: ImageLoaderFailureBlock?) {
329+
func loadImage(media: Media,
330+
preferredSize size: CGSize = .zero,
331+
placeholder: UIImage?,
332+
isBlogAtomic: Bool,
333+
success: ImageLoaderSuccessBlock?,
334+
error: ImageLoaderFailureBlock?) {
329335
guard let mediaId = media.mediaID?.stringValue else {
330336
let error = createError(description: "The Media id doesn't exist")
331337
callErrorHandler(with: error)
@@ -342,7 +348,7 @@ extension ImageLoader {
342348
if let fetchedMedia = fetchedMedia,
343349
let fetchedMediaId = fetchedMedia.mediaID?.stringValue, fetchedMediaId == mediaId {
344350
DispatchQueue.main.async {
345-
self?.loadImage(media: fetchedMedia, preferredSize: size, placeholder: placeholder, success: success, error: error)
351+
self?.loadImage(media: fetchedMedia, preferredSize: size, placeholder: placeholder, isBlogAtomic: isBlogAtomic, success: success, error: error)
346352
}
347353
} else {
348354
self?.callErrorHandler(with: fetchedMediaError)
@@ -357,7 +363,7 @@ extension ImageLoader {
357363
}
358364

359365
if url.isGif {
360-
let host = MediaHost(with: media.blog) { error in
366+
let host = MediaHost(with: media.blog, isAtomic: isBlogAtomic) { error in
361367
// We'll log the error, so we know it's there, but we won't halt execution.
362368
WordPressAppDelegate.crashLogging?.logError(error)
363369
}

WordPress/Classes/ViewRelated/Cells/MediaItemTableViewCells.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ struct MediaImageRow: ImmuTableRow {
216216
}
217217

218218
private func loadImageFor(_ cell: MediaItemImageTableViewCell) {
219-
cell.imageLoader.loadImage(media: media, placeholder: placeholderImage, success: nil) { (error) in
219+
let isBlogAtomic = media.blog.isAtomic()
220+
cell.imageLoader.loadImage(media: media, placeholder: placeholderImage, isBlogAtomic: isBlogAtomic, success: nil) { (error) in
220221
self.show(error)
221222
}
222223
}

WordPress/Classes/ViewRelated/Pages/PageListTableViewCell.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,13 @@ - (void)configureFeaturedImage
193193
BOOL hideFeaturedImage = page.featuredImage == nil;
194194
self.featuredImageView.hidden = hideFeaturedImage;
195195
self.labelsContainerTrailing.active = !hideFeaturedImage;
196+
BOOL isBlogAtomic = [page.featuredImage.blog isAtomic];
196197

197198
if (!hideFeaturedImage) {
198199
[self.featuredImageLoader loadImageFromMedia:page.featuredImage
199200
preferredSize:CGSizeMake(FeaturedImageSize, FeaturedImageSize)
200201
placeholder:nil
202+
isBlogAtomic:isBlogAtomic
201203
success:nil
202204
error:^(NSError *error) {
203205
DDLogError(@"Failed to load the media: %@", error);

WordPress/Classes/ViewRelated/Reader/WPImageViewController.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ - (void)loadImageFromMedia
281281
self.imageView.image = self.image;
282282
self.isLoadingImage = YES;
283283
__weak __typeof__(self) weakSelf = self;
284-
[self.imageLoader loadImageFromMedia:self.media preferredSize:CGSizeZero placeholder:self.image success:^{
284+
BOOL isBlogAtomic = [self.media.blog isAtomic];
285+
[self.imageLoader loadImageFromMedia:self.media preferredSize:CGSizeZero placeholder:self.image isBlogAtomic:isBlogAtomic success:^{
285286
weakSelf.isLoadingImage = NO;
286287
weakSelf.image = weakSelf.imageView.image;
287288
[weakSelf updateImageView];

0 commit comments

Comments
 (0)