mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Make iOS drops more accurate
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user