Scale picture of the day widget to address blank widget issue #4413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Phabricator: https://phabricator.wikimedia.org/T321061
Notes
This PR addresses an issue where the POTD widget doesn't render an image. For whatever reason, some OS level change appears to have constrained what's possible to display in a widget's SwiftUI
Image
view. Previously,WidgetKit
/SwiftUI
seemed to be more forgiving of the dimensionality of images here.Originally, I had the belief that unusually large image dimensions were causing the crash because the requested image required too much memory (exceeding what's allotted by
WidgetKit
), but it actually seems to be the case that just the dimensions themselves were what was causing issues, not necessarily the image's file size itself. For example, an image with an unusually large width regardless of file size, which may have rendered without issue before, is now simply causing the widget to blank out. Through some experimentation, resizing the image to draw within 1000x1000 pixels seems to allow the images/devices I've tested to render without blanking out. The negative of this approach though, is that depending on device and widget size, the image may appear blurrier than before (because it's not considering the device's scale).It's worth noting, I continue to have really poor luck with the debugging
WidgetKit
widgets. I also have additional incomplete work that removes the Core Data dependencies to make the widget more independent (like the feature article widget), but I need to hold that work for a future PR because it's becoming more involved than I had hoped.Test Steps
Additionally if interested, you can try to manually use some previously problematic images that resulted in blank widgets to ensure they work with the new scaling logic. An example of a previous image that resulted in failure is the image featured here: https://en.wikipedia.org/api/rest_v1/feed/featured/2022/11/12. By adding it to the Widget asset catalog, then replacing
cachedImage.staticImage
,fetchedImage.image.staticImage
, andUIImage(named: "PictureOfTheYear_2019")
inPictureOfTheDayWidget.swift
with that image, you should be able to present it in the POTD widget to confirm it renders and isn't blank.