Skip to content

Commit

Permalink
Improve featured image flow (#23962)
Browse files Browse the repository at this point in the history
  • Loading branch information
kean authored Jan 9, 2025
2 parents f5ff6d2 + f44329d commit cd13f63
Show file tree
Hide file tree
Showing 30 changed files with 864 additions and 1,057 deletions.
2 changes: 1 addition & 1 deletion Modules/Sources/AsyncImageKit/Views/AsyncImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extension GIFImageView {
}
}

private func prepareForReuse() {
public func prepareForReuse() {
if isAnimatingGIF {
prepareForReuse()
} else {
Expand Down
20 changes: 20 additions & 0 deletions Modules/Sources/WordPressUI/Extensions/SwiftUI+Extensions.swift
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?
}
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* [*] Enable fast deceleration for filters on the Discover tab [#23954]
* [*] Disable universal links support for QR code login. You can only scan the codes using the app now. [#23953]
* [*] Add scroll-to-top button to Reader streams [#23957]

* [*] Add a quick way to replace a featured image for a post [#23962]

25.6
-----
Expand Down
1 change: 0 additions & 1 deletion WordPress/Classes/System/WordPress-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#import "PostServiceOptions.h"
#import "PostSettingsViewController.h"
#import "PostSettingsViewController_Internal.h"
#import "WPProgressTableViewCell.h"
#import "PostTag.h"
#import "PostTagService.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension HomeSiteHeaderViewController {
mediaMenu.makeCameraAction(delegate: presenter),
mediaMenu.makeImagePlaygroundAction(delegate: presenter),
mediaMenu.makeSiteMediaAction(blog: blog, delegate: presenter)
]
].compactMap { $0 }
if FeatureFlag.siteIconCreator.enabled {
actions.append(UIAction(
title: SiteIconAlertStrings.Actions.createWithEmoji,
Expand Down
27 changes: 0 additions & 27 deletions WordPress/Classes/ViewRelated/Cells/PostFeaturedImageCell.swift

This file was deleted.

15 changes: 0 additions & 15 deletions WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.h

This file was deleted.

124 changes: 0 additions & 124 deletions WordPress/Classes/ViewRelated/Cells/WPProgressTableViewCell.m

This file was deleted.

9 changes: 0 additions & 9 deletions WordPress/Classes/ViewRelated/Cells/WPTableViewActivityCell.h

This file was deleted.

5 changes: 0 additions & 5 deletions WordPress/Classes/ViewRelated/Cells/WPTableViewActivityCell.m

This file was deleted.

36 changes: 0 additions & 36 deletions WordPress/Classes/ViewRelated/Cells/WPTableViewActivityCell.xib

This file was deleted.

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)
}
}
}
Loading

0 comments on commit cd13f63

Please sign in to comment.