Skip to content

Fix incorrect size of thumbnails in media picker#21204

Merged
kean merged 2 commits intotrunkfrom
fix/incorrect-scale-of-media-picker-thumbnails
Jul 31, 2023
Merged

Fix incorrect size of thumbnails in media picker#21204
kean merged 2 commits intotrunkfrom
fix/incorrect-scale-of-media-picker-thumbnails

Conversation

@kean
Copy link
Copy Markdown
Contributor

@kean kean commented Jul 29, 2023

Fixes #21197 (see for more info on the root cause)

To test:

  • Verify that the images in the Media Picker are loading and have adequate retina resolution

Important

MediaThumbnailService stores thumbnails on disk. You'll need to re-install the app or clear the caches in other ways to verify the size reduction.

We can make one more improvement: the app downloads full GIFs but displays only the first frame. We can change the app to download only the first frame. It will dramatically reduce the download size even further. But I'm not sure how yet.

Measurements

Memory (Rest) Memory (Peak) Time to Download Demo
Before 365 MB 569 MB 15 sec recording-01.mp4
After 99 MB 148 MB 4 sec recording-02.mp4

The measurements indicate how much memory just the picker uses (not including the rest of the app footprint). It was tested in the simulator. The results on the device may be different.

This test scenario is a bit exaggerated because I have multiple GIFs in this library, but the size reduction apply equally to all images.

Notes

The method to fetch the thumbnails that I modified is used with non-zero size only from here:

@implementation Media(WPMediaAsset)

- (WPMediaRequestID)imageWithSize:(CGSize)size completionHandler:(WPMediaImageBlock)completionHandler
{
    [MediaThumbnailCoordinator.shared thumbnailFor:self with:size onCompletion:^(UIImage *image, NSError *error) {

This imageWithSize is in turn is called only from WPMediaCollectionViewCell and it passes the size in pixels:

CGFloat scale = [[UIScreen mainScreen] scale];
CGSize requestSize = CGSizeApplyAffineTransform(self.frame.size, CGAffineTransformMakeScale(scale, scale));

Regression Notes

  1. Potential unintended areas of impact: Media Picker
  2. What I did to test those areas of impact (or what existing automated tests I relied on): manual
  3. What automated tests I added (or what prevented me from doing so): n/a

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@kean kean requested review from guarani and staskus July 29, 2023 00:13
@kean kean added this to the Pending milestone Jul 29, 2023
@kean kean changed the title Fix incorrect scale of thumbnails in media picker (4-9 times larger than needed) Fix incorrect size of thumbnails in media picker (4-9 times larger than needed) Jul 29, 2023
@kean kean changed the title Fix incorrect size of thumbnails in media picker (4-9 times larger than needed) Fix incorrect size of thumbnails in media picker Jul 29, 2023
@kean
Copy link
Copy Markdown
Contributor Author

kean commented Jul 29, 2023

The order of the assets is not stable, btw. It'll be great to fix that too.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Jul 29, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21204-d221382
Version22.9
Bundle IDorg.wordpress.alpha
Commitd221382
App Center BuildWPiOS - One-Offs #6544
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented Jul 29, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21204-d221382
Version22.9
Bundle IDcom.jetpack.alpha
Commitd221382
App Center Buildjetpack-installable-builds #5575
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Copy Markdown
Contributor

@staskus staskus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, looks good! 👍

@kean kean enabled auto-merge July 31, 2023 15:00
@kean kean merged commit 743ec61 into trunk Jul 31, 2023
@kean kean deleted the fix/incorrect-scale-of-media-picker-thumbnails branch July 31, 2023 15:29
@kean kean modified the milestones: Pending, 23.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Media picker multiplies thumbnail size by UIScreen.scale twice

3 participants