Skip to content

Commit

Permalink
selection from viewer fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin committed May 24, 2024
1 parent b090456 commit 9671524
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions Sources/General/Models/MPModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ public struct MPModel {
return (items.compactMap({ $0.unwrapped }), index)
}

func getIndexPath(forMedia model: MPPhotoModel) -> IndexPath? {
func getIndexPath(forMedia model: MPPhotoModel, showCameraCell: Bool) -> IndexPath? {
if let index = items.firstIndex(where: { $0.unwrapped == model }) {
var itemsOffset = 5
if currentOrientationIsLandscape {
itemsOffset += 4
}
if index > itemsOffset - 1 {
return IndexPath(item: index - itemsOffset, section: 1)
if showCameraCell {
var itemsOffset = 5
if currentOrientationIsLandscape {
itemsOffset += 4
}
if index > itemsOffset - 1 {
return IndexPath(item: index - itemsOffset, section: 1)
} else {
return IndexPath(item: index, section: 0)
}
} else {
return IndexPath(item: index, section: 0)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/General/UILayer/MPViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ extension MPViewController: MediaPreviewControllerDataSource {
func photoViewerController(_ photoViewerController: MediaViewerViewController, referencedViewForPhotoModel model: MPPhotoModel) -> UIView? {
switch viewState {
case .all:
if let indexPath = dataModel.getIndexPath(forMedia: model) {
if let indexPath = dataModel.getIndexPath(forMedia: model, showCameraCell: showCameraCell) {
return collectionView.mp.cellItem(MediaPickerCell.self, for: indexPath)?.referencedView
}
case .selected:
Expand All @@ -1186,7 +1186,7 @@ extension MPViewController: MediaPreviewControllerDataSource {
// MARK: - MediaPreviewControllerDataSource
extension MPViewController: MediaPreviewControllerDelegate {
func toggleSelected(forModel model: MPPhotoModel) {
if let indexPath = dataModel.getIndexPath(forMedia: model) {
if let indexPath = dataModel.getIndexPath(forMedia: model, showCameraCell: showCameraCell) {
selectionBlock(at: indexPath)
}
}
Expand Down

0 comments on commit 9671524

Please sign in to comment.