diff --git a/iOS/MasterFeed/MasterFeedViewController+Drop.swift b/iOS/MasterFeed/MasterFeedViewController+Drop.swift index afaf62a16..92eca2791 100644 --- a/iOS/MasterFeed/MasterFeedViewController+Drop.swift +++ b/iOS/MasterFeed/MasterFeedViewController+Drop.swift @@ -26,8 +26,12 @@ extension MasterFeedViewController: UITableViewDropDelegate { return UITableViewDropProposal(operation: .forbidden) } - if destNode.representedObject is Folder && session.location(in: destCell).y >= 0 { - return UITableViewDropProposal(operation: .move, intent: .insertIntoDestinationIndexPath) + if destNode.representedObject is Folder { + if session.location(in: destCell).y >= 0 { + return UITableViewDropProposal(operation: .move, intent: .insertIntoDestinationIndexPath) + } else { + return UITableViewDropProposal(operation: .move, intent: .unspecified) + } } else { return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) } diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 649825a4f..1dbc79ffb 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -327,8 +327,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { // If this is a folder and isn't expanded or doesn't have any entries, let the users drop on it if destNode.representedObject is Folder && (destNode.numberOfChildNodes == 0 || !destNode.isExpanded) { - let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0 - return IndexPath(row: destIndexPath.row + movementAdjustment, section: destIndexPath.section) + return proposedDestinationIndexPath } // If we are dragging around in the same container, just return the original source @@ -353,12 +352,14 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } else { sortedNodes.remove(at: index) - + if index >= sortedNodes.count { let lastSortedIndexPath = dataSource.indexPath(for: sortedNodes[sortedNodes.count - 1])! - return IndexPath(row: lastSortedIndexPath.row + 1, section: lastSortedIndexPath.section) + let movementAdjustment = sourceIndexPath > destIndexPath ? 1 : 0 + return IndexPath(row: lastSortedIndexPath.row + movementAdjustment, section: lastSortedIndexPath.section) } else { - return dataSource.indexPath(for: sortedNodes[index])! + let movementAdjustment = sourceIndexPath < destIndexPath ? 1 : 0 + return dataSource.indexPath(for: sortedNodes[index - movementAdjustment])! } }