-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add Image Playground Support #23688
Merged
Merged
Add Image Playground Support #23688
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
323cc9e
Add ImagePlayground support in Gutenberg
kean 559f8ff
Integrate ImagePlayground in GutenberG
kean b81d074
Move ImagePlayground code to MediaPickerMenu
kean 0c958c8
Integrate SiteIcon picker
kean 0be8adf
Integrate in PostSettingsViewController
kean 6ac0bfe
Integrate in Media Picker
kean 0d3297d
Update WordPress/Classes/ViewRelated/Media/MediaPicker/MediaPickerMen…
kean 03ff41c
Update release notes
kean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,4 +181,5 @@ enum MediaSource { | |
case camera | ||
case mediaEditor | ||
case tenor | ||
case imagePlayground | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
WordPress/Classes/ViewRelated/Media/MediaPicker/MediaPickerMenu+ImagePlayground.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import UIKit | ||
import ImagePlayground | ||
|
||
extension MediaPickerMenu { | ||
static var isImagePlaygroundAvailable: Bool { | ||
guard #available(iOS 18.1, *) else { | ||
return false | ||
} | ||
return ImagePlaygroundViewController.isAvailable | ||
} | ||
|
||
static var imagePlaygroundLocalizedTitle: String { | ||
Strings.imagePlayground | ||
} | ||
|
||
func makeImagePlaygroundAction(delegate: ImagePlaygroundPickerDelegate) -> UIAction { | ||
UIAction( | ||
title: Strings.imagePlayground, | ||
image: UIImage(systemName: "apple.image.playground"), | ||
attributes: [], | ||
handler: { _ in showImagePlayground(delegate: delegate) } | ||
) | ||
} | ||
|
||
func showImagePlayground(delegate: ImagePlaygroundPickerDelegate) { | ||
guard let presentingViewController else { return } | ||
|
||
guard #available(iOS 18.1, *) else { | ||
return wpAssertionFailure("Not available on this platform. Use `isImagePlaygroundAvailable`.") | ||
} | ||
|
||
let controller = _ImagePlaygroundController() | ||
controller.delegate = delegate | ||
|
||
let imagePlaygroundVC = ImagePlaygroundViewController() | ||
imagePlaygroundVC.delegate = controller | ||
objc_setAssociatedObject(imagePlaygroundVC, &MediaPickerMenu.strongDelegateKey, controller, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) | ||
|
||
presentingViewController.present(imagePlaygroundVC, animated: true) | ||
} | ||
|
||
/// ImagePlayground returns heic images that are not supported by many WordPress | ||
/// sites. The only exporter that currently supports transcoding images is | ||
/// ``ItemProviderMediaExporter``, which is why we use it and which is why | ||
/// we fallback to "public.heic" (should never happen as these URLs have | ||
/// proper extensions). | ||
static func makeItemProvider(with imageURL: URL) -> NSItemProvider { | ||
let provider = NSItemProvider() | ||
let typeIdentifier = imageURL.typeIdentifier ?? "public.heic" | ||
provider.registerFileRepresentation(forTypeIdentifier: typeIdentifier, visibility: .all) { completion in | ||
completion(imageURL, false, nil) | ||
return nil | ||
} | ||
return provider | ||
} | ||
|
||
private static var strongDelegateKey: UInt8 = 0 | ||
} | ||
|
||
// Uses the following workaround https://mastodon.social/@_inside/113640137011009924 | ||
// to make it compatible with a mixed Objective-C and Swift target. | ||
private final class _ImagePlaygroundController: NSObject { | ||
weak var delegate: ImagePlaygroundPickerDelegate? | ||
} | ||
|
||
@available(iOS 18.1, *) | ||
extension _ImagePlaygroundController: ImagePlaygroundViewController.Delegate { | ||
func imagePlaygroundViewController(_ imagePlaygroundViewController: ImagePlaygroundViewController, didCreateImageAt imageURL: URL) { | ||
delegate?.imagePlaygroundViewController(imagePlaygroundViewController, didCreateImageAt: imageURL) | ||
} | ||
|
||
func imagePlaygroundViewControllerDidCancel(_ imagePlaygroundViewController: ImagePlaygroundViewController) { | ||
delegate?.imagePlaygroundViewControllerDidCancel(imagePlaygroundViewController) | ||
} | ||
} | ||
|
||
protocol ImagePlaygroundPickerDelegate: AnyObject { | ||
func imagePlaygroundViewController(_ viewController: UIViewController, didCreateImageAt imageURL: URL) | ||
func imagePlaygroundViewControllerDidCancel(_ viewController: UIViewController) | ||
} | ||
|
||
extension ImagePlaygroundPickerDelegate { | ||
func imagePlaygroundViewControllerDidCancel(_ viewController: UIViewController) { | ||
viewController.presentingViewController?.dismiss(animated: true) | ||
} | ||
} | ||
|
||
private enum Strings { | ||
static let imagePlayground = NSLocalizedString("mediaPicker.imagePlayground", value: "Image Playground", comment: "A name of the action in the context menu") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to double-check, should
controller
orimagePlaygroundVC
be stored here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
controller
is the value that needs to be retained.ImagePlaygroundViewController
is kept in memory by UIKit due to being presented on screen.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, this line should be ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
value
to be retained is a third parameter. The test is that the delegate gets called.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈 Of course... Not sure how I misread that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget the signature literally every time I use it 😆