Skip to content

Commit

Permalink
Merge pull request #21681 from wordpress-mobile/task/remove-native-ph…
Browse files Browse the repository at this point in the history
…oto-picker-feature-flag

Remove .nativePhotoPicker feature flag
  • Loading branch information
kean authored Oct 13, 2023
2 parents 3f12287 + b5a1209 commit 06107c9
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 1,057 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [*] Fix a crash when the blog's blogging prompt settings contain invalid JSON [#21677]
* [*] Block Editor: Split formatted text on triple Enter [https://github.com/WordPress/gutenberg/pull/53354]
* [*] Block Editor: Quote block: Ensure border is visible with block-based themes in dark [https://github.com/WordPress/gutenberg/pull/54964]
* [*] (Internal) Remove .nativePhotoPicker feature flag and the disabled code [#21681](https://github.com/wordpress-mobile/WordPress-iOS/pull/21681)

23.4
-----
Expand Down
16 changes: 16 additions & 0 deletions WordPress/Classes/Services/Stories/DisabledVideoOverlay.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import UIKit

/// An overlay for videos that exceed allowed duration
class DisabledVideoOverlay: UIView {

static let overlayTransparency: CGFloat = 0.8

init() {
super.init(frame: .zero)
backgroundColor = .gray.withAlphaComponent(Self.overlayTransparency)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
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 @@ -108,7 +108,6 @@
#import "WPWebViewController.h"
#import "WPTabBarController.h"
#import "WPUserAgent.h"
#import "WPAndDeviceMediaLibraryDataSource.h"
#import "WPLogger.h"
#import "WPException.h"

Expand Down
5 changes: 0 additions & 5 deletions WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ enum FeatureFlag: Int, CaseIterable {
case commentModerationUpdate
case compliancePopover
case domainFocus
case nativePhotoPicker
case readerImprovements // pcdRpT-3Eb-p2
case mediaModernization

Expand Down Expand Up @@ -43,8 +42,6 @@ enum FeatureFlag: Int, CaseIterable {
return true
case .domainFocus:
return true
case .nativePhotoPicker:
return true
case .readerImprovements:
return false
case .mediaModernization:
Expand Down Expand Up @@ -91,8 +88,6 @@ extension FeatureFlag {
return "Compliance Popover"
case .domainFocus:
return "Domain Focus"
case .nativePhotoPicker:
return "Native Photo Picker"
case .readerImprovements:
return "Reader Improvements v1"
case .mediaModernization:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,11 @@ extension SitePickerViewController {

let presenter = makeSiteIconPresenter()
let mediaMenu = MediaPickerMenu(viewController: self, filter: .images)
var actions: [UIAction] = []
if FeatureFlag.nativePhotoPicker.enabled {
actions += [
mediaMenu.makePhotosAction(delegate: presenter),
mediaMenu.makeCameraAction(delegate: presenter),
mediaMenu.makeMediaAction(blog: blog, delegate: presenter)
]
} else {
actions.append(UIAction(
title: SiteIconAlertStrings.Actions.changeSiteIcon,
image: UIImage(systemName: "photo.on.rectangle"),
handler: { [weak self] _ in
guard let self else { return }
presenter.presentPickerFrom(self)
}
))
}
var actions = [
mediaMenu.makePhotosAction(delegate: presenter),
mediaMenu.makeCameraAction(delegate: presenter),
mediaMenu.makeMediaAction(blog: blog, delegate: presenter)
]
if FeatureFlag.siteIconCreator.enabled {
actions.append(UIAction(
title: SiteIconAlertStrings.Actions.createWithEmoji,
Expand Down Expand Up @@ -210,8 +198,6 @@ extension SitePickerViewController {
static let title = NSLocalizedString("Update Site Icon", comment: "Title for sheet displayed allowing user to update their site icon")

enum Actions {
static let changeSiteIcon = NSLocalizedString("Change Site Icon", comment: "Change site icon button")
static let chooseImage = NSLocalizedString("Choose Image From My Device", comment: "Button allowing the user to choose an image from their device to use as their site icon")
static let createWithEmoji = NSLocalizedString("Create With Emoji", comment: "Button allowing the user to create a site icon by choosing an emoji character")
static let removeSiteIcon = NSLocalizedString("Remove Site Icon", comment: "Remove site icon button")
static let cancel = NSLocalizedString("Cancel", comment: "Cancel button")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,6 @@ final class SiteIconPickerPresenter: NSObject {

// MARK: - Private Properties

fileprivate let noResultsView = NoResultsViewController.controller()
fileprivate var mediaLibraryChangeObserverKey: NSObjectProtocol? = nil

/// Media Library Data Source
///
fileprivate lazy var mediaLibraryDataSource: WPAndDeviceMediaLibraryDataSource = {
return WPAndDeviceMediaLibraryDataSource(blog: self.blog)
}()

/// Media Picker View Controller
///
fileprivate lazy var mediaPickerViewController: WPNavigationMediaPickerViewController = {
let options = WPMediaPickerOptions()
options.showMostRecentFirst = true
options.filter = [.image]
options.allowMultipleSelection = false
options.showSearchBar = true
options.badgedUTTypes = [UTType.gif.identifier]
options.preferredStatusBarStyle = WPStyleGuide.preferredStatusBarStyle

let pickerViewController = WPNavigationMediaPickerViewController(options: options)

pickerViewController.dataSource = self.mediaLibraryDataSource
pickerViewController.delegate = self
pickerViewController.modalPresentationStyle = .formSheet

return pickerViewController
}()

private var dataSource: AnyObject?
private var mediaCapturePresenter: AnyObject?

Expand All @@ -61,21 +32,9 @@ final class SiteIconPickerPresenter: NSObject {
///
@objc init(blog: Blog) {
self.blog = blog
noResultsView.configureForNoAssets(userCanUploadMedia: false)
super.init()
}

deinit {
unregisterChangeObserver()
}

/// Presents a new WPMediaPickerViewController instance.
///
@objc func presentPickerFrom(_ viewController: UIViewController) {
viewController.present(mediaPickerViewController, animated: true)
registerChangeObserver(forPicker: mediaPickerViewController.mediaPicker)
}

// MARK: - Private Methods

fileprivate func showLoadingMessage() {
Expand All @@ -91,7 +50,7 @@ final class SiteIconPickerPresenter: NSObject {

/// Shows a new ImageCropViewController for the given image.
///
func showImageCropViewController(_ image: UIImage, presentingViewController: UIViewController? = nil) {
func showImageCropViewController(_ image: UIImage, presentingViewController: UIViewController) {
DispatchQueue.main.async {
SVProgressHUD.dismiss()
let imageCropViewController = ImageCropViewController(image: image)
Expand Down Expand Up @@ -135,54 +94,13 @@ final class SiteIconPickerPresenter: NSObject {
}
}
}
if let presentingViewController {
imageCropViewController.shouldShowCancelButton = true
imageCropViewController.onCancel = { [weak presentingViewController] in
// Dismiss the crop controller but not the picker
presentingViewController?.dismiss(animated: true)
}
let navigationController = UINavigationController(rootViewController: imageCropViewController)
presentingViewController.present(navigationController, animated: true)
} else {
self.mediaPickerViewController.show(after: imageCropViewController)
}
}
}

fileprivate func registerChangeObserver(forPicker picker: WPMediaPickerViewController) {
assert(mediaLibraryChangeObserverKey == nil)
mediaLibraryChangeObserverKey = mediaLibraryDataSource.registerChangeObserverBlock({ [weak self] _, _, _, _, _ in

self?.updateSearchBar(mediaPicker: picker)

let isNotSearching = self?.mediaLibraryDataSource.searchQuery?.count ?? 0 != 0
let hasNoAssets = self?.mediaLibraryDataSource.numberOfAssets() == 0

if isNotSearching && hasNoAssets {
self?.noResultsView.removeFromView()
self?.noResultsView.configureForNoAssets(userCanUploadMedia: false)
}
})
}

fileprivate func unregisterChangeObserver() {
if let mediaLibraryChangeObserverKey = mediaLibraryChangeObserverKey {
mediaLibraryDataSource.unregisterChangeObserver(mediaLibraryChangeObserverKey)
}
mediaLibraryChangeObserverKey = nil
}

fileprivate func updateSearchBar(mediaPicker: WPMediaPickerViewController) {
let isSearching = mediaLibraryDataSource.searchQuery?.count ?? 0 != 0
let hasAssets = mediaLibraryDataSource.numberOfAssets() > 0

if mediaLibraryDataSource.dataSourceType == .mediaLibrary && (isSearching || hasAssets) {
mediaPicker.showSearchBar()
if let searchBar = mediaPicker.searchBar {
WPStyleGuide.configureSearchBar(searchBar)
imageCropViewController.shouldShowCancelButton = true
imageCropViewController.onCancel = { [weak presentingViewController] in
// Dismiss the crop controller but not the picker
presentingViewController?.dismiss(animated: true)
}
} else {
mediaPicker.hideSearchBar()
let navigationController = UINavigationController(rootViewController: imageCropViewController)
presentingViewController.present(navigationController, animated: true)
}
}
}
Expand Down Expand Up @@ -220,88 +138,34 @@ extension SiteIconPickerPresenter: ImagePickerControllerDelegate {
}
}

extension SiteIconPickerPresenter: MediaPickerViewControllerDelegate {}

extension SiteIconPickerPresenter: WPMediaPickerViewControllerDelegate {

func mediaPickerControllerWillBeginLoadingData(_ picker: WPMediaPickerViewController) {
updateSearchBar(mediaPicker: picker)
noResultsView.configureForFetching()
}

func mediaPickerControllerDidEndLoadingData(_ picker: WPMediaPickerViewController) {
noResultsView.removeFromView()
noResultsView.configureForNoAssets(userCanUploadMedia: false)
updateSearchBar(mediaPicker: picker)
}

func mediaPickerController(_ picker: WPMediaPickerViewController, didUpdateSearchWithAssetCount assetCount: Int) {
noResultsView.removeFromView()

if (mediaLibraryDataSource.searchQuery?.count ?? 0) > 0 {
noResultsView.configureForNoSearchResult()
}
}

func mediaPickerController(_ picker: WPMediaPickerViewController, shouldShow asset: WPMediaAsset) -> Bool {
return asset.isKind(of: PHAsset.self)
}
extension SiteIconPickerPresenter: MediaPickerViewControllerDelegate {

func mediaPickerControllerDidCancel(_ picker: WPMediaPickerViewController) {
mediaLibraryDataSource.searchCancelled()
onCompletion?(nil, nil)
}

/// Retrieves the chosen image and triggers the ImageCropViewController display.
///
func mediaPickerController(_ picker: WPMediaPickerViewController, didFinishPicking assets: [WPMediaAsset]) {
dataSource = nil
mediaLibraryDataSource.searchCancelled()
if assets.isEmpty {

guard let asset = assets.first else {
return
}
guard let media = asset as? Media else {
assertionFailure("Unsupported asset: \(asset)")
return
}

let asset = assets.first

WPAnalytics.track(.siteSettingsSiteIconGalleryPicked)

switch asset {
case let phAsset as PHAsset:
showLoadingMessage()
originalMedia = nil
let exporter = MediaAssetExporter(asset: phAsset)
exporter.imageOptions = MediaImageExporter.Options()

exporter.export(onCompletion: { [weak self](assetExport) in
guard let image = UIImage(contentsOfFile: assetExport.url.path) else {
self?.showErrorLoadingImageMessage()
return
}
self?.showImageCropViewController(image)

}, onError: { [weak self](error) in
showLoadingMessage()
originalMedia = media
MediaThumbnailCoordinator.shared.thumbnail(for: media, with: CGSize.zero, onCompletion: { [weak self] (image, error) in
guard let image = image else {
self?.showErrorLoadingImageMessage()
})
case let media as Media:
showLoadingMessage()
originalMedia = media
MediaThumbnailCoordinator.shared.thumbnail(for: media, with: CGSize.zero, onCompletion: { [weak self] (image, error) in
guard let image = image else {
self?.showErrorLoadingImageMessage()
return
}
if FeatureFlag.nativePhotoPicker.enabled {
self?.showImageCropViewController(image, presentingViewController: picker)
} else {
self?.showImageCropViewController(image)
}
})
default:
break
}
}

func emptyViewController(forMediaPickerController picker: WPMediaPickerViewController) -> UIViewController? {
return noResultsView
return
}
self?.showImageCropViewController(image, presentingViewController: picker)
})
}
}
Loading

0 comments on commit 06107c9

Please sign in to comment.