Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve share sheet #576

Merged
merged 9 commits into from
Nov 27, 2024
Merged

Improve share sheet #576

merged 9 commits into from
Nov 27, 2024

Conversation

pinarol
Copy link
Contributor

@pinarol pinarol commented Nov 27, 2024

An improvement on #566

Description

I noticed that if we first write the image to a file and then share that file's URL, then there are more relevant options in the share sheet:

Also, updated the share sheet's initial height as same as QE's initial height (in horizontal mode it's not exactly same but it's close). So we see small or no height adjustment done by the system while share sheet is being opened.

Another thing is, I changed the word "download" as "share" in the error message.

Last but not least, I share the jpegData as there's a noticeable time difference between sharing pngData and jpegData. I set the compression quality to 1 (highest), and the shared image's quality seems good to me.

Testing Steps

(It can be good to compare with the previous version.)
Demo app > QE > avatar [...] menu > share

@pinarol pinarol self-assigned this Nov 27, 2024
@pinarol pinarol added enhance New feature or request [Feature] Gravatar-QuickEditor Gravatar Quick Editor [Priority] Medium labels Nov 27, 2024
@pinarol pinarol marked this pull request as ready for review November 27, 2024 11:35
@pinarol pinarol requested a review from etoledom November 27, 2024 11:35
@wpmobilebot
Copy link

wpmobilebot commented Nov 27, 2024

Gravatar Prototype Build📲 You can test the changes from this Pull Request in Gravatar Prototype Build by scanning the QR code below to install the corresponding build.
App NameGravatar Prototype Build Gravatar Prototype Build
Build Number1793
Version1.0
Bundle IDcom.automattic.gravatar-sdk-demo-uikit.prototype-build
Commit4801fd3
App Center BuildGravatar SDK Demo - UIKit #422
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@pinarol pinarol force-pushed the wppinar/improve-share-sheet branch from eabc511 to 2faafb9 Compare November 27, 2024 12:30
Copy link
Contributor

@etoledom etoledom left a comment

Choose a reason for hiding this comment

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

Working great 🎉

Just a small option to consider on comments, but not a blocker 👍

Comment on lines 134 to 146

func fetchAndSaveToFile(avatar: AvatarImageModel) async -> URL? {
guard let image = await fetchOriginalSizeAvatar(for: avatar),
let imageData = image.jpegData(compressionQuality: 1) else { return nil }
let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("image.jpg")
do {
try imageData.write(to: fileURL)
return fileURL
} catch {
toastManager.showToast(Localized.avatarShareFail, type: .error)
}
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally is good to have these functions which explicitaly do two things to have them split, even if they are two small functions like:

let image =  fetchFullImage(of: avatar)`
let imageFileURL = image.saveToFile()

Maybe in this way we can also show the share sheet even if writing to storage fails 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah totally makes sense to have a separate UIImage extension method like saveToFile(). I'll add it.

Maybe in this way we can also show the share sheet even if writing to storage fails

This is doable but I would consider this as an edge case. For sake of keeping our logic simple, I'd say let's just share the file for now.

@pinarol pinarol merged commit 6590fd5 into trunk Nov 27, 2024
9 checks passed
@pinarol pinarol deleted the wppinar/improve-share-sheet branch November 27, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance New feature or request [Feature] Gravatar-QuickEditor Gravatar Quick Editor [Priority] Medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants