forked from shadowfacts/Tusker
Present asset picker as popover in regular horizontal size class
This commit is contained in:
parent
b5fa0bceab
commit
1a11dd2a69
|
@ -49,6 +49,21 @@ class AssetCollectionViewController: UICollectionViewController {
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
// use the safe area layout guide instead of letting it automatically use the safe area insets
|
||||||
|
// because otherwise, when presented in a popover with the arrow on the left or right side,
|
||||||
|
// the collection view content will be cut off by the width of the arrow because the popover
|
||||||
|
// doesn't respect safe area insets
|
||||||
|
collectionView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
view.safeAreaLayoutGuide.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor),
|
||||||
|
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalTo: collectionView.trailingAnchor),
|
||||||
|
// top ignores safe area because when presented in the sheet container, it simplifies the top content offset
|
||||||
|
view.topAnchor.constraint(equalTo: collectionView.topAnchor),
|
||||||
|
// bottom ignores safe area because we want cells to underflow bottom of the screen on notched iPhones
|
||||||
|
view.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor),
|
||||||
|
])
|
||||||
|
view.backgroundColor = .systemBackground
|
||||||
|
|
||||||
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
|
||||||
|
|
||||||
collectionView.alwaysBounceVertical = true
|
collectionView.alwaysBounceVertical = true
|
||||||
|
|
|
@ -303,10 +303,20 @@ class ComposeAttachmentsViewController: UITableViewController {
|
||||||
// MARK: Interaction
|
// MARK: Interaction
|
||||||
|
|
||||||
func addAttachmentPressed() {
|
func addAttachmentPressed() {
|
||||||
|
if traitCollection.horizontalSizeClass == .compact {
|
||||||
let sheetContainer = AssetPickerSheetContainerViewController()
|
let sheetContainer = AssetPickerSheetContainerViewController()
|
||||||
sheetContainer.assetPicker.assetPickerDelegate = self
|
sheetContainer.assetPicker.assetPickerDelegate = self
|
||||||
present(sheetContainer, animated: true)
|
present(sheetContainer, animated: true)
|
||||||
//setOverrideTraitCollection(UITraitCollection(userInterfaceLevel: .elevated), forChild: sheetContainer)
|
} else {
|
||||||
|
let picker = AssetPickerViewController()
|
||||||
|
picker.assetPickerDelegate = self
|
||||||
|
picker.overrideUserInterfaceStyle = .dark
|
||||||
|
picker.modalPresentationStyle = .popover
|
||||||
|
present(picker, animated: true)
|
||||||
|
if let presentationController = picker.presentationController as? UIPopoverPresentationController {
|
||||||
|
presentationController.sourceView = tableView.cellForRow(at: IndexPath(row: 0, section: 1))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue