-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve featured image flow (#23962)
- Loading branch information
Showing
30 changed files
with
864 additions
and
1,057 deletions.
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
20 changes: 20 additions & 0 deletions
20
Modules/Sources/WordPressUI/Extensions/SwiftUI+Extensions.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 |
---|---|---|
@@ -1,5 +1,25 @@ | ||
import UIKit | ||
import SwiftUI | ||
|
||
public extension EdgeInsets { | ||
static let zero = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0) | ||
} | ||
|
||
private struct PresentingViewControllerKey: EnvironmentKey { | ||
static let defaultValue = WeakEnvironmentValueWrapper<UIViewController>() | ||
} | ||
|
||
extension EnvironmentValues { | ||
public var presentingViewController: UIViewController? { | ||
get { | ||
self[PresentingViewControllerKey.self].value ?? UIViewController.topViewController | ||
} | ||
set { | ||
self[PresentingViewControllerKey.self].value = newValue | ||
} | ||
} | ||
} | ||
|
||
private final class WeakEnvironmentValueWrapper<T: AnyObject> { | ||
weak var value: T? | ||
} |
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
27 changes: 0 additions & 27 deletions
27
WordPress/Classes/ViewRelated/Cells/PostFeaturedImageCell.swift
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.h
This file was deleted.
Oops, something went wrong.
124 changes: 0 additions & 124 deletions
124
WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.m
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
WordPress/Classes/ViewRelated/Cells/WPTableViewActivityCell.h
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
WordPress/Classes/ViewRelated/Cells/WPTableViewActivityCell.m
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
WordPress/Classes/ViewRelated/Cells/WPTableViewActivityCell.xib
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
WordPress/Classes/ViewRelated/Media/MediaPicker/Helpers/MediaPickerMenuController.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,62 @@ | ||
import Photos | ||
import PhotosUI | ||
|
||
final class MediaPickerMenuController: NSObject { | ||
var onSelection: ((MediaPickerSelection) -> Void)? | ||
|
||
fileprivate func didSelect(_ items: [MediaPickerItem], source: String) { | ||
let selection = MediaPickerSelection(items: items, source: source) | ||
DispatchQueue.main.async { | ||
self.onSelection?(selection) | ||
} | ||
} | ||
} | ||
|
||
extension MediaPickerMenuController: PHPickerViewControllerDelegate { | ||
public func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { | ||
picker.presentingViewController?.dismiss(animated: true) | ||
if !results.isEmpty { | ||
self.didSelect(results.map(MediaPickerItem.pickerResult), source: "apple_photos") | ||
} | ||
} | ||
} | ||
|
||
extension MediaPickerMenuController: ImagePickerControllerDelegate { | ||
func imagePicker(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { | ||
picker.presentingViewController?.dismiss(animated: true) | ||
if let image = info[.originalImage] as? UIImage { | ||
self.didSelect([.image(image)], source: "camera") | ||
} | ||
} | ||
} | ||
|
||
extension MediaPickerMenuController: SiteMediaPickerViewControllerDelegate { | ||
func siteMediaPickerViewController(_ viewController: SiteMediaPickerViewController, didFinishWithSelection selection: [Media]) { | ||
viewController.presentingViewController?.dismiss(animated: true) | ||
if !selection.isEmpty { | ||
self.didSelect(selection.map(MediaPickerItem.media), source: "site_media") | ||
} | ||
} | ||
} | ||
|
||
extension MediaPickerMenuController: ImagePlaygroundPickerDelegate { | ||
func imagePlaygroundViewController(_ viewController: UIViewController, didCreateImageAt imageURL: URL) { | ||
|
||
viewController.presentingViewController?.dismiss(animated: true) | ||
if let data = try? Data(contentsOf: imageURL), let image = UIImage(data: data) { | ||
self.didSelect([.image(image)], source: "image_playground") | ||
} else { | ||
wpAssertionFailure("failed to read the image created by ImagePlayground") | ||
} | ||
} | ||
} | ||
|
||
extension MediaPickerMenuController: ExternalMediaPickerViewDelegate { | ||
func externalMediaPickerViewController(_ viewController: ExternalMediaPickerViewController, didFinishWithSelection selection: [ExternalMediaAsset]) { | ||
viewController.presentingViewController?.dismiss(animated: true) | ||
if !selection.isEmpty { | ||
let source = viewController.source == .tenor ? "free_gifs" : "free_photos" | ||
self.didSelect(selection.map(MediaPickerItem.external), source: source) | ||
} | ||
} | ||
} |
Oops, something went wrong.