From 5253033eac8814e5f080dad69e01d2a6bb643acf Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 11 Nov 2022 20:48:42 -0600 Subject: [PATCH] Make iOS drops more accurate --- .../Cell/MasterFeedTableViewCell.swift | 62 +++++++++---------- .../MasterFeedViewController+Drop.swift | 49 ++++++++------- 2 files changed, 55 insertions(+), 56 deletions(-) diff --git a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift index add2381e6..eca8d43e3 100644 --- a/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift +++ b/iOS/MasterFeed/Cell/MasterFeedTableViewCell.swift @@ -15,7 +15,7 @@ protocol MasterFeedTableViewCellDelegate: AnyObject { func masterFeedTableViewCellDisclosureDidToggle(_ sender: MasterFeedTableViewCell, expanding: Bool) } -class MasterFeedTableViewCell : VibrantTableViewCell { +class MasterFeedTableViewCell : UITableViewCell { weak var delegate: MasterFeedTableViewCellDelegate? @@ -134,10 +134,6 @@ class MasterFeedTableViewCell : VibrantTableViewCell { } } - override func applyThemeProperties() { - super.applyThemeProperties() - } - override func willTransition(to state: UITableViewCell.StateMask) { super.willTransition(to: state) isShowingEditControl = state.contains(.showingEditControl) @@ -165,34 +161,34 @@ class MasterFeedTableViewCell : VibrantTableViewCell { delegate?.masterFeedTableViewCellDisclosureDidToggle(self, expanding: isDisclosureExpanded) } } - - override func updateVibrancy(animated: Bool) { - super.updateVibrancy(animated: animated) - - let iconTintColor: UIColor - if isHighlighted || isSelected { - disclosureButton?.tintColor = AppAssets.vibrantTextColor - iconTintColor = AppAssets.vibrantTextColor - } else { - disclosureButton?.tintColor = AppAssets.secondaryAccentColor - if let preferredColor = iconImage?.preferredColor { - iconTintColor = UIColor(cgColor: preferredColor) - } else { - iconTintColor = AppAssets.secondaryAccentColor - } - } - - if animated { - UIView.animate(withDuration: Self.duration) { - self.iconView.tintColor = iconTintColor - } - } else { - self.iconView.tintColor = iconTintColor - } - - updateLabelVibrancy(titleView, color: labelColor, animated: animated) - } - +// +// override func updateVibrancy(animated: Bool) { +// super.updateVibrancy(animated: animated) +// +// let iconTintColor: UIColor +// if isHighlighted || isSelected { +// disclosureButton?.tintColor = AppAssets.vibrantTextColor +// iconTintColor = AppAssets.vibrantTextColor +// } else { +// disclosureButton?.tintColor = AppAssets.secondaryAccentColor +// if let preferredColor = iconImage?.preferredColor { +// iconTintColor = UIColor(cgColor: preferredColor) +// } else { +// iconTintColor = AppAssets.secondaryAccentColor +// } +// } +// +// if animated { +// UIView.animate(withDuration: Self.duration) { +// self.iconView.tintColor = iconTintColor +// } +// } else { +// self.iconView.tintColor = iconTintColor +// } +// +// updateLabelVibrancy(titleView, color: labelColor, animated: animated) +// } +// } private extension MasterFeedTableViewCell { diff --git a/iOS/MasterFeed/MasterFeedViewController+Drop.swift b/iOS/MasterFeed/MasterFeedViewController+Drop.swift index c7f925c07..99d67911f 100644 --- a/iOS/MasterFeed/MasterFeedViewController+Drop.swift +++ b/iOS/MasterFeed/MasterFeedViewController+Drop.swift @@ -18,16 +18,15 @@ extension MasterFeedViewController: UITableViewDropDelegate { } func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal { - guard let destIndexPath = destinationIndexPath, destIndexPath.section > 0, tableView.hasActiveDrag else { + guard let destIndexPath = correctDestinationIndexPath(session: session), destIndexPath.section > 0, tableView.hasActiveDrag else { return UITableViewDropProposal(operation: .forbidden) } - + guard let destFeed = coordinator.nodeFor(destIndexPath)?.representedObject as? Feed, - let destAccount = destFeed.account, - let destCell = tableView.cellForRow(at: destIndexPath) else { - return UITableViewDropProposal(operation: .forbidden) - } - + let destAccount = destFeed.account else { + return UITableViewDropProposal(operation: .forbidden) + } + // Validate account specific behaviors... if destAccount.behaviors.contains(.disallowFeedInMultipleFolders), let sourceNode = session.localDragSession?.items.first?.localObject as? Node, @@ -38,11 +37,7 @@ extension MasterFeedViewController: UITableViewDropDelegate { // Determine the correct drop proposal if destFeed is Folder { - if session.location(in: destCell).y >= 0 { - return UITableViewDropProposal(operation: .move, intent: .insertIntoDestinationIndexPath) - } else { - return UITableViewDropProposal(operation: .move, intent: .unspecified) - } + return UITableViewDropProposal(operation: .move, intent: .insertIntoDestinationIndexPath) } else { return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) } @@ -53,21 +48,14 @@ extension MasterFeedViewController: UITableViewDropDelegate { guard let dragItem = dropCoordinator.items.first?.dragItem, let dragNode = dragItem.localObject as? Node, let source = dragNode.parent?.representedObject as? Container, - let destIndexPath = dropCoordinator.destinationIndexPath else { - return - } - - let isFolderDrop: Bool = { - if coordinator.nodeFor(destIndexPath)?.representedObject is Folder, let propCell = tableView.cellForRow(at: destIndexPath) { - return dropCoordinator.session.location(in: propCell).y >= 0 - } - return false - }() + let destIndexPath = correctDestinationIndexPath(session: dropCoordinator.session) else { + return + } // Based on the drop we have to determine a node to start looking for a parent container. let destNode: Node? = { - if isFolderDrop { + if coordinator.nodeFor(destIndexPath)?.representedObject is Folder { return coordinator.nodeFor(destIndexPath) } else { if destIndexPath.row == 0 { @@ -99,7 +87,22 @@ extension MasterFeedViewController: UITableViewDropDelegate { moveWebFeedBetweenAccounts(feed: webFeed, sourceContainer: source, destinationContainer: destination) } } + +} +private extension MasterFeedViewController { + + func correctDestinationIndexPath(session: UIDropSession) -> IndexPath? { + let location = session.location(in: tableView) + + var correctDestination: IndexPath? + tableView.performUsingPresentationValues { + correctDestination = tableView.indexPathForRow(at: location) + } + + return correctDestination + } + func moveWebFeedInAccount(feed: WebFeed, sourceContainer: Container, destinationContainer: Container) { guard sourceContainer !== destinationContainer else { return }