Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a12228bb8 | ||
|
|
58ee0c440a |
No files matched your search
@@ -14,6 +14,8 @@
|
||||
2C33C48623E2C475005F963B /* Notification Service Extension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2C33C47F23E2C475005F963B /* Notification Service Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
370D26AF248A3D7A00121797 /* NCCellMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 370D26AE248A3D7A00121797 /* NCCellMain.swift */; };
|
||||
63563FE53573412998852DD3 /* NCAlbumsPersistenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439616AAA50F4360A761E5EF /* NCAlbumsPersistenceTests.swift */; };
|
||||
70967D76817BB55B836156BD /* NCContextMenuPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F958BC42108713CC43709E /* NCContextMenuPreviewView.swift */; };
|
||||
7D8EFACC97AC59574BF53CB1 /* NCContextMenuPreviewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EC51B7CB9E5737B61D27C6F /* NCContextMenuPreviewTests.swift */; };
|
||||
A12720261001000000000001 /* NCBackgroundUploadExtensionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F793E7C230417C7100F011FE /* NCBackgroundUploadExtensionManager.swift */; };
|
||||
A1E2EE010000000000000002 /* NCEndToEndKeySet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1E2EE010000000000000001 /* NCEndToEndKeySet.swift */; };
|
||||
A1E2EE010000000000000003 /* NCEndToEndKeySet.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1E2EE010000000000000001 /* NCEndToEndKeySet.swift */; };
|
||||
@@ -1337,6 +1339,8 @@
|
||||
370D26AE248A3D7A00121797 /* NCCellMain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCCellMain.swift; sourceTree = "<group>"; };
|
||||
439616AAA50F4360A761E5EF /* NCAlbumsPersistenceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCAlbumsPersistenceTests.swift; sourceTree = "<group>"; };
|
||||
4B74B947E07444CC9CFE0A6C /* NCDocumentEditorSupportTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCDocumentEditorSupportTests.swift; sourceTree = "<group>"; };
|
||||
4EC51B7CB9E5737B61D27C6F /* NCContextMenuPreviewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuPreviewTests.swift; sourceTree = "<group>"; };
|
||||
70F958BC42108713CC43709E /* NCContextMenuPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuPreviewView.swift; sourceTree = "<group>"; };
|
||||
8932E90EC4278026D86CCCC9 /* NCContextMenuComment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCContextMenuComment.swift; sourceTree = "<group>"; };
|
||||
A1E2EE010000000000000001 /* NCEndToEndKeySet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndKeySet.swift; sourceTree = "<group>"; };
|
||||
A1E2EE010000000000000009 /* NCEndToEndKeySetArchiveTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndKeySetArchiveTests.swift; sourceTree = "<group>"; };
|
||||
@@ -2358,6 +2362,7 @@
|
||||
AF93471127E2341B002537EE /* NCContextMenuShare.swift */,
|
||||
F75D19E225EFE09000D74598 /* NCContextMenuTrash.swift */,
|
||||
F710D2012405826100A6033D /* NCContextMenuViewer.swift */,
|
||||
70F958BC42108713CC43709E /* NCContextMenuPreviewView.swift */,
|
||||
);
|
||||
path = Menu;
|
||||
sourceTree = "<group>";
|
||||
@@ -2401,6 +2406,7 @@
|
||||
439616AAA50F4360A761E5EF /* NCAlbumsPersistenceTests.swift */,
|
||||
C0DECA012F65000100C0D001 /* NCCameraRollTests.swift */,
|
||||
4B74B947E07444CC9CFE0A6C /* NCDocumentEditorSupportTests.swift */,
|
||||
4EC51B7CB9E5737B61D27C6F /* NCContextMenuPreviewTests.swift */,
|
||||
);
|
||||
path = NextcloudUnitTests;
|
||||
sourceTree = "<group>";
|
||||
@@ -4868,6 +4874,7 @@
|
||||
22BA14432CF44BDBA2E6C291 /* NCDocumentEditorSupportTests.swift in Sources */,
|
||||
F372087D2BAB4C0F006B5430 /* TestConstants.swift in Sources */,
|
||||
F78E2D6C29AF02DB0024D4F3 /* Database.swift in Sources */,
|
||||
7D8EFACC97AC59574BF53CB1 /* NCContextMenuPreviewTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -5661,6 +5668,7 @@
|
||||
F711A4DC2AF92CAE00095DD8 /* NCUtility+Date.swift in Sources */,
|
||||
F7BDC1D5300F440A00C5D9FA /* NCManageDatabase+MediaPreviewBackfill.swift in Sources */,
|
||||
AF4BF61E27562B3F0081CEEF /* NCManageDatabase+Activity.swift in Sources */,
|
||||
70967D76817BB55B836156BD /* NCContextMenuPreviewView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// SPDX-FileCopyrightText: Nextcloud GmbH
|
||||
// SPDX-FileCopyrightText: 2026 Milen Pivchev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import Testing
|
||||
import UIKit
|
||||
@testable import Nextcloud
|
||||
|
||||
@Suite("Context menu full name preview")
|
||||
@MainActor
|
||||
struct NCContextMenuPreviewTests {
|
||||
private let listSize = CGSize(width: 390, height: 60)
|
||||
private let gridSize = CGSize(width: 120, height: 180)
|
||||
private let longName = String(repeating: "ExportBlock-52f1c0de-", count: 8) + "Part-1.zip"
|
||||
|
||||
@Test("List cell keeps its height when the name already fits")
|
||||
func listShortName() throws {
|
||||
let cell = try makeListCell(fileName: "Report.pdf")
|
||||
|
||||
cell.showFullName()
|
||||
|
||||
#expect(cell.bounds.height == listSize.height)
|
||||
#expect(cell.labelTitle.text == "Report.pdf")
|
||||
#expect(cell.labelExtension.isHidden)
|
||||
}
|
||||
|
||||
@Test("List cell grows so a long name shows in full")
|
||||
func listLongName() throws {
|
||||
let cell = try makeListCell(fileName: longName)
|
||||
|
||||
cell.showFullName()
|
||||
|
||||
#expect(cell.bounds.height > listSize.height)
|
||||
#expect(cell.labelTitle.text == longName)
|
||||
#expect(cell.bounds.contains(cell.labelTitle.convert(cell.labelTitle.bounds, to: cell).insetBy(dx: 1, dy: 1)))
|
||||
}
|
||||
|
||||
@Test("Grid cell grows below the image so a long name shows in full")
|
||||
func gridLongName() throws {
|
||||
let cell = try makeGridCell(fileName: longName)
|
||||
cell.layoutIfNeeded()
|
||||
let imageSize = cell.imageItem.bounds.size
|
||||
|
||||
cell.showFullName()
|
||||
|
||||
#expect(cell.bounds.height > gridSize.height)
|
||||
#expect(cell.imageItem.bounds.size == imageSize)
|
||||
#expect(cell.labelTitle.text == longName)
|
||||
#expect(cell.bounds.contains(cell.labelTitle.convert(cell.labelTitle.bounds, to: cell).insetBy(dx: 1, dy: 1)))
|
||||
}
|
||||
|
||||
@Test("Every bidi attack from the bidi-safe filename tests keeps the standard preview", arguments: [
|
||||
"malware\u{202E}fdp.exe", // RLO
|
||||
"invoice\u{2067}cod.exe", // RLI
|
||||
"report\u{202D}exe.pdf", // LRO
|
||||
"\u{202E}\u{2066}safe_document\u{2069}cod.exe", // RLO + LRI + PDI
|
||||
"image\u{2066}exe.jpg\u{2069}.png", // LRI + PDI
|
||||
"notes\u{2068}exe.bat", // FSI
|
||||
"folder\u{202E}exe.txt" // RLO in a folder name
|
||||
])
|
||||
func bidiAttacksAreProblematic(name: String) {
|
||||
#expect(NCContextMenuPreviewView.isProblematic(name))
|
||||
}
|
||||
|
||||
@Test("Names one label could reorder or break keep the standard preview", arguments: [
|
||||
"report\u{2069}\u{202E}fdp..exe", // stray PDI + RLO
|
||||
"file\u{200F}.exe", // RLM
|
||||
"file\u{061C}.exe", // ALM
|
||||
"Invoice\u{2029}\u{200F}payment.pdf.exe", // paragraph separator + RLM
|
||||
"photo\n.exe", // newline
|
||||
"שלום.txt", // Hebrew
|
||||
"تقرير.pdf", // Arabic
|
||||
"invoice \u{05D0}.pdf.exe" // Hebrew letter in a Latin name
|
||||
])
|
||||
func reorderingNamesAreProblematic(name: String) {
|
||||
#expect(NCContextMenuPreviewView.isProblematic(name))
|
||||
}
|
||||
|
||||
@Test("Plain names get the full name preview", arguments: [
|
||||
"photo.jpg",
|
||||
"document.pdf",
|
||||
"archive.tar.gz",
|
||||
"README",
|
||||
".gitignore",
|
||||
"My Folder.backup",
|
||||
"ExportBlock-52f1c0de-a8b9-4c3d-9e2f-774cebeb-Part-1",
|
||||
"Résumé – final (2).docx",
|
||||
"😀 party.png",
|
||||
"日本語のファイル名.txt"
|
||||
])
|
||||
func plainNamesAreNotProblematic(name: String) {
|
||||
#expect(!NCContextMenuPreviewView.isProblematic(name))
|
||||
}
|
||||
|
||||
private func makeListCell(fileName: String) throws -> NCListCell {
|
||||
let cell = try makeCell(NCListCell.self, size: listSize)
|
||||
cell.setBidiSafeFilename(fileName, isDirectory: false, titleLabel: cell.labelTitle, extensionLabel: cell.labelExtension)
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
private func makeGridCell(fileName: String) throws -> NCGridCell {
|
||||
let cell = try makeCell(NCGridCell.self, size: gridSize)
|
||||
cell.setBidiSafeFilename(fileName, isDirectory: false, titleLabel: cell.labelTitle, extensionLabel: cell.labelExtension)
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
private func makeCell<Cell: UICollectionViewCell>(_ type: Cell.Type, size: CGSize) throws -> Cell {
|
||||
let nib = UINib(nibName: String(describing: type), bundle: Bundle(for: type))
|
||||
let cell = try #require(nib.instantiate(withOwner: nil).first as? Cell)
|
||||
cell.frame = CGRect(origin: .zero, size: size)
|
||||
|
||||
return cell
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP
|
||||
@IBOutlet weak var imageVisualEffect: UIVisualEffectView!
|
||||
@IBOutlet weak var iconsStackView: UIStackView!
|
||||
|
||||
@IBOutlet weak var imageItemBottomConstraint: NSLayoutConstraint!
|
||||
@IBOutlet weak var titleHeightConstraint: NSLayoutConstraint!
|
||||
|
||||
weak var delegate: NCGridCellDelegate?
|
||||
|
||||
// Cell Protocol
|
||||
@@ -185,6 +188,35 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP
|
||||
labelSubinfo.text = NCUtilityFileSystem().transformedSize(size)
|
||||
}
|
||||
|
||||
/// Wraps the whole name instead of truncating it and grows the cell below the image to fit, for the context menu preview.
|
||||
/// Only for names `NCContextMenuPreviewView.isProblematic` lets through: one label shows those in order.
|
||||
func showFullName() {
|
||||
let title = NSMutableAttributedString(attributedString: labelTitle.attributedText ?? NSAttributedString())
|
||||
|
||||
if !labelExtension.isHidden {
|
||||
title.append(NSAttributedString(string: labelExtension.text ?? "", attributes: [
|
||||
.font: labelExtension.font as UIFont,
|
||||
.foregroundColor: labelExtension.textColor as UIColor
|
||||
]))
|
||||
}
|
||||
|
||||
labelTitle.attributedText = title
|
||||
labelTitle.numberOfLines = 0
|
||||
labelTitle.lineBreakMode = .byWordWrapping
|
||||
labelExtension.isHidden = true
|
||||
layoutIfNeeded()
|
||||
|
||||
guard labelTitle.bounds.width > 0 else { return }
|
||||
|
||||
let titleHeight = ceil(labelTitle.sizeThatFits(CGSize(width: labelTitle.bounds.width, height: .greatestFiniteMagnitude)).height)
|
||||
let extraHeight = max(0, titleHeight - titleHeightConstraint.constant)
|
||||
|
||||
titleHeightConstraint.constant += extraHeight
|
||||
imageItemBottomConstraint.constant += extraHeight
|
||||
frame.size.height += extraHeight
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
func setAccessibility(label: String, value: String) {
|
||||
accessibilityLabel = label
|
||||
accessibilityValue = value
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
<outlet property="iconsStackView" destination="dYL-ap-9lA" id="IKa-gM-1zT"/>
|
||||
<outlet property="imageFavorite" destination="AYs-f2-vve" id="UeH-R7-bZr"/>
|
||||
<outlet property="imageItem" destination="5Ci-V1-hf5" id="xky-Nw-NUb"/>
|
||||
<outlet property="imageItemBottomConstraint" destination="eEC-eB-alE" id="gIb-Bc-Ot1"/>
|
||||
<outlet property="imageLocal" destination="81G-wH-fjN" id="bqj-wQ-CBV"/>
|
||||
<outlet property="imageSelect" destination="DHy-Up-3Bh" id="mo9-rP-P4I"/>
|
||||
<outlet property="imageStatus" destination="a0p-rj-jnV" id="6Dg-tf-evd"/>
|
||||
@@ -144,6 +145,7 @@
|
||||
<outlet property="labelInfo" destination="2po-8g-XeS" id="FJ4-wI-9cW"/>
|
||||
<outlet property="labelSubinfo" destination="12P-pO-DHO" id="K6d-7r-FGh"/>
|
||||
<outlet property="labelTitle" destination="eU3-lY-fKr" id="0P7-yM-Asb"/>
|
||||
<outlet property="titleHeightConstraint" destination="Soj-7j-hoM" id="gTh-Hc-Ot2"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="65.599999999999994" y="479.46026986506752"/>
|
||||
</collectionViewCell>
|
||||
|
||||
@@ -265,6 +265,36 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellMainP
|
||||
labelSubinfo.text = NCUtilityFileSystem().transformedSize(size)
|
||||
}
|
||||
|
||||
/// Wraps the whole name instead of truncating it and grows the cell to fit, for the context menu preview.
|
||||
/// Only for names `NCContextMenuPreviewView.isProblematic` lets through: one label shows those in order.
|
||||
func showFullName() {
|
||||
layoutIfNeeded()
|
||||
|
||||
let lineHeight = labelTitle.bounds.height
|
||||
let title = NSMutableAttributedString(attributedString: labelTitle.attributedText ?? NSAttributedString())
|
||||
|
||||
if !labelExtension.isHidden {
|
||||
title.append(NSAttributedString(string: labelExtension.text ?? "", attributes: [
|
||||
.font: labelExtension.font as UIFont,
|
||||
.foregroundColor: labelExtension.textColor as UIColor
|
||||
]))
|
||||
}
|
||||
|
||||
labelTitle.attributedText = title
|
||||
labelTitle.numberOfLines = 0
|
||||
labelTitle.lineBreakMode = .byWordWrapping
|
||||
labelExtension.isHidden = true
|
||||
separator.isHidden = true
|
||||
layoutIfNeeded()
|
||||
|
||||
guard labelTitle.bounds.width > 0 else { return }
|
||||
|
||||
let titleHeight = labelTitle.sizeThatFits(CGSize(width: labelTitle.bounds.width, height: .greatestFiniteMagnitude)).height
|
||||
|
||||
frame.size.height += max(0, ceil(titleHeight - lineHeight))
|
||||
layoutIfNeeded()
|
||||
}
|
||||
|
||||
func setAccessibility(label: String, value: String) {
|
||||
accessibilityLabel = label
|
||||
accessibilityValue = value
|
||||
|
||||
+95
-13
@@ -164,27 +164,17 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
guard let metadata = self.dataSource.getMetadata(indexPath: indexPath),
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? {
|
||||
guard let indexPath = indexPaths.first,
|
||||
let metadata = self.dataSource.getMetadata(indexPath: indexPath),
|
||||
metadata.classFile != NKTypeClassFile.url.rawValue,
|
||||
!isEditMode
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
let identifier = indexPath as NSCopying
|
||||
var image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: global.previewExt1024, userId: metadata.userId, urlBase: metadata.urlBase)
|
||||
let cell = collectionView.cellForItem(at: indexPath)
|
||||
|
||||
if image == nil {
|
||||
if cell is NCListCell {
|
||||
image = (cell as? NCListCell)?.imageItem.image
|
||||
} else if cell is NCGridCell {
|
||||
image = (cell as? NCGridCell)?.imageItem.image
|
||||
} else if cell is NCPhotoCell {
|
||||
image = (cell as? NCPhotoCell)?.imageItem.image
|
||||
}
|
||||
}
|
||||
|
||||
return UIContextMenuConfiguration(identifier: identifier, previewProvider: {
|
||||
return nil
|
||||
}, actionProvider: { _ in
|
||||
@@ -193,6 +183,59 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
|
||||
})
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, highlightPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? {
|
||||
contextMenuPreview = nil
|
||||
|
||||
// A problematic name keeps the standard preview, where the extension has its own label.
|
||||
guard let cell = collectionView.cellForItem(at: indexPath),
|
||||
let metadata = dataSource.getMetadata(indexPath: indexPath),
|
||||
!NCContextMenuPreviewView.isProblematic(metadata.fileNameView),
|
||||
let copies = cellCopies(of: cell, at: indexPath, metadata: metadata)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
let preview = NCContextMenuPreviewView(sourceCell: cell, rowCell: copies.row, fullNameCell: copies.fullName, rowAlignment: cell is NCGridCell ? .top : .center)
|
||||
let parameters = UIPreviewParameters()
|
||||
|
||||
// Keeps the room for the whole name invisible until the menu opens.
|
||||
parameters.backgroundColor = .clear
|
||||
parameters.shadowPath = preview.rowShadowPath
|
||||
|
||||
// Places the row copy exactly over the pressed cell.
|
||||
let center = CGPoint(x: cell.center.x, y: cell.frame.minY - preview.rowFrame.minY + preview.bounds.midY)
|
||||
let targetedPreview = UITargetedPreview(view: preview, parameters: parameters, target: UIPreviewTarget(container: collectionView, center: center))
|
||||
|
||||
contextMenuPreview = targetedPreview
|
||||
|
||||
return targetedPreview
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, contextMenuConfiguration configuration: UIContextMenuConfiguration, dismissalPreviewForItemAt indexPath: IndexPath) -> UITargetedPreview? {
|
||||
contextMenuPreview
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, willDisplayContextMenu configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
|
||||
contextMenuPreviewView?.setFullNameVisible(true, alongside: animator)
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, willEndContextMenuInteraction configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
|
||||
contextMenuPreviewView?.setFullNameVisible(false, alongside: animator)
|
||||
|
||||
guard let animator else {
|
||||
contextMenuPreview = nil
|
||||
return
|
||||
}
|
||||
|
||||
let endingPreview = contextMenuPreview
|
||||
|
||||
// A new press may have stored its own preview before this dismissal finished.
|
||||
animator.addCompletion { [weak self] in
|
||||
if self?.contextMenuPreview === endingPreview {
|
||||
self?.contextMenuPreview = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func collectionView(_ collectionView: UICollectionView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
|
||||
animator.addCompletion {
|
||||
if let indexPath = configuration.identifier as? IndexPath {
|
||||
@@ -200,4 +243,43 @@ extension NCCollectionViewCommon: UICollectionViewDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var contextMenuPreviewView: NCContextMenuPreviewView? {
|
||||
contextMenuPreview?.view as? NCContextMenuPreviewView
|
||||
}
|
||||
|
||||
/// Copies of the item's list or grid cell, one as is and one wrapping its whole name; `nil` for photo cells, which show no name.
|
||||
private func cellCopies(of cell: UICollectionViewCell, at indexPath: IndexPath, metadata: tableMetadata) -> (row: UICollectionViewCell, fullName: UICollectionViewCell)? {
|
||||
guard cell is NCListCell || cell is NCGridCell else { return nil }
|
||||
|
||||
let nib = UINib(nibName: cell is NCListCell ? "NCListCell" : "NCGridCell", bundle: nil)
|
||||
let existsImagePreview = utilityFileSystem.fileProviderStorageImageExists(metadata.ocId, etag: metadata.etag, userId: metadata.userId, urlBase: metadata.urlBase)
|
||||
|
||||
func copy(showingFullName: Bool) -> UICollectionViewCell? {
|
||||
guard let copy = nib.instantiate(withOwner: nil).first as? UICollectionViewCell else { return nil }
|
||||
|
||||
copy.frame = cell.bounds
|
||||
copy.backgroundColor = collectionView.backgroundColor
|
||||
|
||||
if let listCopy = copy as? NCListCell {
|
||||
_ = listCell(cell: listCopy, indexPath: indexPath, metadata: metadata, existsImagePreview: existsImagePreview)
|
||||
|
||||
if showingFullName {
|
||||
listCopy.showFullName()
|
||||
}
|
||||
} else if let gridCopy = copy as? NCGridCell {
|
||||
_ = gridCell(cell: gridCopy, indexPath: indexPath, metadata: metadata, existsImagePreview: existsImagePreview)
|
||||
|
||||
if showingFullName {
|
||||
gridCopy.showFullName()
|
||||
}
|
||||
}
|
||||
|
||||
return copy
|
||||
}
|
||||
|
||||
guard let row = copy(showingFullName: false), let fullName = copy(showingFullName: true) else { return nil }
|
||||
|
||||
return (row, fullName)
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,10 @@ class NCCollectionViewCommon: UIViewController, NCAccountSettingsModelDelegate,
|
||||
internal var currentMenuObjectId: String?
|
||||
internal var currentMenuPoint: CGPoint = .zero
|
||||
|
||||
// Context Menu
|
||||
//
|
||||
internal var contextMenuPreview: UITargetedPreview?
|
||||
|
||||
// Search
|
||||
//
|
||||
internal var isSearchingMode: Bool = false
|
||||
|
||||
@@ -10,7 +10,7 @@ import NextcloudKit
|
||||
import LucidBanner
|
||||
|
||||
/// A context menu used in ``NCCollectionViewCommon`` and ``NCMedia``
|
||||
/// See ``NCCollectionViewCommon/collectionView(_:contextMenuConfigurationForItemAt:point:)``,
|
||||
/// See ``NCCollectionViewCommon/collectionView(_:contextMenuConfigurationForItemsAt:point:)``,
|
||||
/// ``NCCollectionViewCommon/openContextMenu(with:button:sender:)``, ``NCMedia/collectionView(_:contextMenuConfigurationForItemAt:point:)`` for usage details.
|
||||
@MainActor
|
||||
class NCContextMenuMain: NSObject {
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// SPDX-FileCopyrightText: Nextcloud GmbH
|
||||
// SPDX-FileCopyrightText: 2026 Milen Pivchev
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import UIKit
|
||||
import CoreText
|
||||
|
||||
/// Context menu preview that covers the pressed cell with a copy of it, then reveals its whole name once the menu opens.
|
||||
/// It is sized for the whole name from the start, since UIKit fixes a targeted preview's size when the press begins.
|
||||
class NCContextMenuPreviewView: UIView {
|
||||
enum RowAlignment {
|
||||
/// The name grows downward, keeping a grid tile's image in place.
|
||||
case top
|
||||
/// The name grows above and below the row, keeping a list row's icon and buttons in place.
|
||||
case center
|
||||
}
|
||||
|
||||
private static let fallbackCornerRadius: CGFloat = 10
|
||||
|
||||
private let rowCell: UIView
|
||||
private let fullNameCell: UIView
|
||||
private weak var sourceCell: UIView?
|
||||
|
||||
/// Where the pressed cell sits within the preview.
|
||||
var rowFrame: CGRect {
|
||||
rowCell.frame
|
||||
}
|
||||
|
||||
/// The shadow of the row alone, so nothing shows around it until the name expands.
|
||||
var rowShadowPath: UIBezierPath {
|
||||
UIBezierPath(roundedRect: rowCell.frame, cornerRadius: Self.fallbackCornerRadius)
|
||||
}
|
||||
|
||||
init(sourceCell: UIView, rowCell: UIView, fullNameCell: UIView, rowAlignment: RowAlignment) {
|
||||
self.sourceCell = sourceCell
|
||||
self.rowCell = rowCell
|
||||
self.fullNameCell = fullNameCell
|
||||
|
||||
super.init(frame: fullNameCell.bounds)
|
||||
|
||||
if rowAlignment == .center {
|
||||
rowCell.frame.origin.y = (bounds.height - rowCell.bounds.height) / 2
|
||||
}
|
||||
|
||||
fullNameCell.alpha = 0
|
||||
rowCell.layer.masksToBounds = true
|
||||
addSubview(fullNameCell)
|
||||
addSubview(rowCell)
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
roundRowCorners()
|
||||
}
|
||||
|
||||
/// Crossfades to the whole name, hiding the pressed cell since UIKit may move the preview away from it; reversed on dismissal.
|
||||
func setFullNameVisible(_ visible: Bool, alongside animator: UIContextMenuInteractionAnimating?) {
|
||||
let update = {
|
||||
self.rowCell.alpha = visible ? 0 : 1
|
||||
self.fullNameCell.alpha = visible ? 1 : 0
|
||||
}
|
||||
|
||||
if visible {
|
||||
roundRowCorners()
|
||||
sourceCell?.isHidden = true
|
||||
}
|
||||
|
||||
guard let animator else {
|
||||
update()
|
||||
sourceCell?.isHidden = visible
|
||||
return
|
||||
}
|
||||
|
||||
animator.addAnimations(update)
|
||||
animator.addCompletion { [weak self] in
|
||||
self?.sourceCell?.isHidden = visible
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether one label could show `fileName` out of its stored order, so the extension might no longer read last:
|
||||
/// a control, format or line separator character, or any right-to-left run. Such a name keeps the standard
|
||||
/// preview, whose separate extension label stops bidi tricks from disguising the extension.
|
||||
static func isProblematic(_ fileName: String) -> Bool {
|
||||
let hasHiddenOrBreakingCharacters = fileName.unicodeScalars.contains {
|
||||
switch $0.properties.generalCategory {
|
||||
case .control, .format, .lineSeparator, .paragraphSeparator:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
guard !hasHiddenOrBreakingCharacters else { return true }
|
||||
|
||||
let line = CTLineCreateWithAttributedString(NSAttributedString(string: fileName))
|
||||
let runs = CTLineGetGlyphRuns(line) as? [CTRun] ?? []
|
||||
|
||||
return runs.contains { CTRunGetStatus($0).contains(.rightToLeft) }
|
||||
}
|
||||
|
||||
/// UIKit rounds only the platter's outer corners; the row copy sits inside it, so round its corners alike.
|
||||
private func roundRowCorners() {
|
||||
var platterLayer: CALayer?
|
||||
var ancestor = superview
|
||||
|
||||
while let view = ancestor, platterLayer == nil {
|
||||
if view.layer.cornerRadius > 0 {
|
||||
platterLayer = view.layer
|
||||
}
|
||||
|
||||
ancestor = view.superview
|
||||
}
|
||||
|
||||
rowCell.layer.cornerRadius = platterLayer?.cornerRadius ?? Self.fallbackCornerRadius
|
||||
rowCell.layer.cornerCurve = platterLayer?.cornerCurve ?? .continuous
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user