Files
NetNewsWire/iOS/MainFeed/MainFeedCollectionViewController+Drop.swift
T
Stuart Breckenridge 04f659f704 💄 Liquid Glass Redesign for NetNewsWire
💄 Add `MainFeedCollectionViewController`

💄 Add and hook up UICollectionView in Storyboard

🚧 Collection view loads temp cells

🚧 UICollectionView

- Adds capsule shape for iPad selection
- Add filter button, newItem button, settings button
- Configures the collection view based on platform
- implementsDidSelectItem at
- Clears cell background on iPad
- Adds cell textColor for iPad
- Storyboard changes

🚧 Adds unread count and favicon support

🚧 Smartfeed icons now display

🚧 iPhone cells are consistent in light/dark mode

💄 Sidebar modernised

Known bug: Sidebar text doesn’t adapt to dark/light mode changes on iPad

💄 Modern Sidebars

Fixes some accessibilty issues and adds swipe actions.

🩹 Become firstResponder

🩹 Workaround #4691

💡 Remove print statement

💄 Fixes to storyboard

- adjusts constraints on timeline header view
- launch screens now adopt look of liquid glass

Restore coordinator behaviour

⚡️ Tweaks to MainFeedCollectionViewController

- On iPhone, returning to the feeds view deselect the current feed with an animation.
- On iPhone, prefers large titles defaults to `false`
- Capsule background with smaller corner radius for iPhone added for selected status.

🩹 Fixes folder height

💄 Fix unread count vertical alignment

💄 Restores header & use UICellConfigurationState

💄 Sidebar tweaks

💄 Folders now highlight on as drop target

💄 Sidebar fixes

- Moves more code to cell configuation state
- Allows sidebar to move to larger sizes

🩹 Fixes #4694  folder expansion using keyboard

💄 Adds new cell types for the Timeline

♻️ Remove dead code and re-orders to viewWillApp

🩹 Reordering of code from viewWA to viewDA

💄 Removes unused code, tweaks layout

💄 Multiple tweaks to sidebar and timeline

💄 Add missing constraint

♿️ Puts timeline metadata in a stackview

🎨 Adds stackview function

💄 🚑️ Moves to modern UISliders

Timeline customiser now uses modern UISliders as they have tickmark functionality.

`TickMarkSlider` marked as deprecated.

💄 Make All Unread cell icon tint correctly

💄 Extend edges under opaque bars on timeline

💄 Image View Controller uses modern button style

🚚 Renames `MainTimelinePseudoFeedCell`

💄 Improve feed selection animations

🩹 Use shouldSelectItem to handle selection logic

🩹 Fix fill settings for stack view

💄 Comment out usage of MainTimelineTitleView

🔧 Remove iOS cells from macOS target

💄 Give columns some flexibility

💄 Fix chevron size and alignment

💄 Don’t prefer large navigation bar titles

They create a delay in animation on iPhone.

🩹 Fixes nav bar subtitle performance

🎨 Minor refactor

- Switch logic in cell state
- Prefer traitCollection.userInterfaceIdiom

➕ Add updated mac code for the About view

💄 NSGlassVisualEffectView for About
2025-07-23 21:58:47 +08:00

175 lines
5.9 KiB
Swift

//
// MainFeedCollectionViewController+Drop.swift
// NetNewsWire-iOS
//
// Created by Stuart Breckenridge on 14/07/2025.
// Copyright © 2025 Ranchero Software. All rights reserved.
//
import UIKit
import WebKit
import Account
import Articles
import RSCore
import RSTree
import RSWeb
import SafariServices
import UniformTypeIdentifiers
extension MainFeedCollectionViewController: UICollectionViewDropDelegate {
func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: any UICollectionViewDropCoordinator) {
guard let dragItem = coordinator.items.first?.dragItem,
let dragNode = dragItem.localObject as? Node,
let source = dragNode.parent?.representedObject as? Container,
let destIndexPath = coordinator.destinationIndexPath else {
return
}
let isFolderDrop: Bool = {
if self.coordinator.nodeFor(destIndexPath)?.representedObject is Folder, let propCell = collectionView.cellForItem(at: destIndexPath) {
return coordinator.session.location(in: propCell).y >= 0
}
return false
}()
// Based on the drop we have to determine a node to start looking for a parent container.
let destNode: Node? = {
if isFolderDrop {
return self.coordinator.nodeFor(destIndexPath)
} else {
if destIndexPath.row == 0 {
return self.coordinator.nodeFor(IndexPath(row: 0, section: destIndexPath.section))
} else if destIndexPath.row > 0 {
return self.coordinator.nodeFor(IndexPath(row: destIndexPath.row - 1, section: destIndexPath.section))
} else {
return nil
}
}
}()
// Now we start looking for the parent container
let destinationContainer: Container? = {
if let container = (destNode?.representedObject as? Container) ?? (destNode?.parent?.representedObject as? Container) {
return container
} else {
// If we got here, we are trying to drop on an empty section header. Go and find the Account for this section
return self.coordinator.rootNode.childAtIndex(destIndexPath.section)?.representedObject as? Account
}
}()
guard let destination = destinationContainer, let webFeed = dragNode.representedObject as? WebFeed else { return }
if source.account == destination.account {
moveWebFeedInAccount(feed: webFeed, sourceContainer: source, destinationContainer: destination)
} else {
moveWebFeedBetweenAccounts(feed: webFeed, sourceContainer: source, destinationContainer: destination)
}
}
func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: any UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal {
guard let destIndexPath = destinationIndexPath, destIndexPath.section > 0, collectionView.hasActiveDrag else {
return UICollectionViewDropProposal(operation: .forbidden)
}
guard let destFeed = coordinator.nodeFor(destIndexPath)?.representedObject as? Feed,
let destAccount = destFeed.account,
let destCell = collectionView.cellForItem(at: destIndexPath) else {
return UICollectionViewDropProposal(operation: .forbidden)
}
// Validate account specific behaviors...
if destAccount.behaviors.contains(.disallowFeedInMultipleFolders),
let sourceNode = session.localDragSession?.items.first?.localObject as? Node,
let sourceWebFeed = sourceNode.representedObject as? WebFeed,
sourceWebFeed.account?.accountID != destAccount.accountID && destAccount.hasWebFeed(withURL: sourceWebFeed.url) {
return UICollectionViewDropProposal(operation: .forbidden)
}
// Determine the correct drop proposal
if destFeed is Folder {
if session.location(in: destCell).y >= 0 {
return UICollectionViewDropProposal(operation: .move, intent: .insertIntoDestinationIndexPath)
} else {
return UICollectionViewDropProposal(operation: .move, intent: .unspecified)
}
} else {
return UICollectionViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
}
func collectionView(_ collectionView: UICollectionView, canHandle session: any UIDropSession) -> Bool {
return session.localDragSession != nil
}
func collectionView(_ collectionView: UICollectionView, dropSessionDidEnd session: UIDropSession) {
}
func moveWebFeedInAccount(feed: WebFeed, sourceContainer: Container, destinationContainer: Container) {
guard sourceContainer !== destinationContainer else { return }
BatchUpdate.shared.start()
sourceContainer.account?.moveWebFeed(feed, from: sourceContainer, to: destinationContainer) { result in
BatchUpdate.shared.end()
switch result {
case .success:
break
case .failure(let error):
self.presentError(error)
}
}
}
func moveWebFeedBetweenAccounts(feed: WebFeed, sourceContainer: Container, destinationContainer: Container) {
if let existingFeed = destinationContainer.account?.existingWebFeed(withURL: feed.url) {
BatchUpdate.shared.start()
destinationContainer.account?.addWebFeed(existingFeed, to: destinationContainer) { result in
switch result {
case .success:
sourceContainer.account?.removeWebFeed(feed, from: sourceContainer) { result in
BatchUpdate.shared.end()
switch result {
case .success:
break
case .failure(let error):
self.presentError(error)
}
}
case .failure(let error):
BatchUpdate.shared.end()
self.presentError(error)
}
}
} else {
BatchUpdate.shared.start()
destinationContainer.account?.createWebFeed(url: feed.url, name: feed.editedName, container: destinationContainer, validateFeed: false) { result in
switch result {
case .success:
sourceContainer.account?.removeWebFeed(feed, from: sourceContainer) { result in
BatchUpdate.shared.end()
switch result {
case .success:
break
case .failure(let error):
self.presentError(error)
}
}
case .failure(let error):
BatchUpdate.shared.end()
self.presentError(error)
}
}
}
}
}