Skip to content

Commit

Permalink
Merge pull request #17670 from wordpress-mobile/fix/gm4371
Browse files Browse the repository at this point in the history
Filter media types when presenting the Media Picker for Mobile Gutenberg
  • Loading branch information
twstokes authored Jan 18, 2022
2 parents 327aee9 + c42ecd7 commit f135e14
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
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
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)
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
}
}

0 comments on commit f135e14

Please sign in to comment.