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

Filter media types when presenting the Media Picker for Mobile Gutenberg #17670

Merged
merged 4 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* [**] Accessibility: VoiceOver improvements on Activity Log and Schedule Post calendars [#17756, #17761]
* [*] Weekly Roundup: Fix a crash which was preventing weekly roundup notifications from appearing [#17765]
* [*] Self-hosted login: Improved error messages. [#17724]
* [*] Block editor: Fixed an issue where video thumbnails could show when selecting images, and vice versa. [#17670]

19.0
-----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation
import CoreServices
import WPMediaPicker
import UIKit
ttahmouch marked this conversation as resolved.
Show resolved Hide resolved
import Photos
import WordPressShared
import WPMediaPicker
import Gutenberg

public typealias GutenbergMediaPickerHelperCallback = ([WPMediaAsset]?) -> Void
Expand Down Expand Up @@ -32,18 +34,6 @@ class GutenbergMediaPickerHelper: NSObject {
///
fileprivate lazy var devicePhotoLibraryDataSource = WPPHAssetDataSource()

fileprivate lazy var mediaPickerOptions: WPMediaPickerOptions = {
let options = WPMediaPickerOptions()
options.showMostRecentFirst = true
options.filter = [.image]
options.allowCaptureOfMedia = false
options.showSearchBar = true
options.badgedUTTypes = [String(kUTTypeGIF)]
options.allowMultipleSelection = false
options.preferredStatusBarStyle = WPStyleGuide.preferredStatusBarStyle
return options
}()

var didPickMediaCallback: GutenbergMediaPickerHelperCallback?

init(context: UIViewController, post: AbstractPost) {
Expand All @@ -59,7 +49,8 @@ class GutenbergMediaPickerHelper: NSObject {

didPickMediaCallback = callback

let picker = WPNavigationMediaPickerViewController()
let mediaPickerOptions = WPMediaPickerOptions.withDefaults(filter: filter, allowMultipleSelection: allowMultipleSelection)
let picker = WPNavigationMediaPickerViewController(options: mediaPickerOptions)
ttahmouch marked this conversation as resolved.
Show resolved Hide resolved
navigationPicker = picker
switch dataSourceType {
case .device:
Expand All @@ -73,8 +64,6 @@ class GutenbergMediaPickerHelper: NSObject {
}

picker.selectionActionTitle = Constants.mediaPickerInsertText
mediaPickerOptions.filter = filter
mediaPickerOptions.allowMultipleSelection = allowMultipleSelection
picker.mediaPicker.options = mediaPickerOptions
picker.delegate = self
picker.mediaPicker.registerClass(forReusableCellOverlayViews: DisabledVideoOverlay.self)
Expand All @@ -91,7 +80,7 @@ class GutenbergMediaPickerHelper: NSObject {

private lazy var cameraPicker: WPMediaPickerViewController = {
let cameraPicker = WPMediaPickerViewController()
cameraPicker.options = mediaPickerOptions
cameraPicker.options = WPMediaPickerOptions.withDefaults()
cameraPicker.mediaPickerDelegate = self
cameraPicker.dataSource = WPPHAssetDataSource.sharedInstance()
return cameraPicker
Expand Down Expand Up @@ -252,3 +241,26 @@ extension GutenbergMediaPickerHelper {
})
}
}

fileprivate extension WPMediaPickerOptions {
static func withDefaults(
showMostRecentFirst: Bool = true,
filter: WPMediaType = [.image],
allowCaptureOfMedia: Bool = false,
showSearchBar: Bool = true,
badgedUTTypes: Set<String> = [String(kUTTypeGIF)],
allowMultipleSelection: Bool = false,
preferredStatusBarStyle: UIStatusBarStyle = WPStyleGuide.preferredStatusBarStyle
) -> WPMediaPickerOptions {
let options = WPMediaPickerOptions()
options.showMostRecentFirst = showMostRecentFirst
options.filter = filter
options.allowCaptureOfMedia = allowCaptureOfMedia
options.showSearchBar = showSearchBar
options.badgedUTTypes = badgedUTTypes
options.allowMultipleSelection = allowMultipleSelection
options.preferredStatusBarStyle = preferredStatusBarStyle

return options
}
}