diff --git a/Sources/General/Models/MPModel.swift b/Sources/General/Models/MPModel.swift index 75e0c44..c182ab5 100644 --- a/Sources/General/Models/MPModel.swift +++ b/Sources/General/Models/MPModel.swift @@ -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) } diff --git a/Sources/General/UILayer/MPViewController.swift b/Sources/General/UILayer/MPViewController.swift index 4783519..50c6e9e 100644 --- a/Sources/General/UILayer/MPViewController.swift +++ b/Sources/General/UILayer/MPViewController.swift @@ -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: @@ -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) } }