diff --git a/.github/workflows/xcode.yml b/.github/workflows/xcode.yml index 3331596172..3d4e0cc95e 100644 --- a/.github/workflows/xcode.yml +++ b/.github/workflows/xcode.yml @@ -37,7 +37,7 @@ jobs: - name: Setup Xcode uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0 with: - xcode-version: latest-stable + xcode-version: 16.4 - name: Run Xcode Build run: | diff --git a/iOSClient/Main/Collection Common/Cell/NCGridCell.xib b/iOSClient/Main/Collection Common/Cell/NCGridCell.xib index 2466c28b44..74b4d877fb 100644 --- a/iOSClient/Main/Collection Common/Cell/NCGridCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCGridCell.xib @@ -1,9 +1,8 @@ - + - - + @@ -61,7 +60,7 @@ - diff --git a/iOSClient/Main/Collection Common/Cell/NCListCell.swift b/iOSClient/Main/Collection Common/Cell/NCListCell.swift index 7f519d9258..243cc968d7 100755 --- a/iOSClient/Main/Collection Common/Cell/NCListCell.swift +++ b/iOSClient/Main/Collection Common/Cell/NCListCell.swift @@ -342,3 +342,76 @@ class NCListLayout: UICollectionViewFlowLayout { return proposedContentOffset } } + +class BidiFilenameLabel: UILabel { + var fullFilename: String = "" + + var isFolder: Bool = false + + var isRTL: Bool = false + + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + } + + override func layoutSubviews() { + super.layoutSubviews() + updateText() + } + + private func updateText() { + guard !fullFilename.isEmpty else { + self.text = "" + return + } + + let availableWidth = bounds.width + guard availableWidth > 0 else { return } + + let isRTL = UIView.userInterfaceLayoutDirection(for: semanticContentAttribute) == .rightToLeft + let sanitizedFilename = fullFilename.sanitizeForBidiCharacters(isFolder: isFolder, isRTL: isRTL) + + let nsFilename = sanitizedFilename as NSString + let ext = nsFilename.pathExtension + let base = nsFilename.deletingPathExtension + + let dotExt = ext.isEmpty ? "" : "." + ext + let truncatedBase = truncateBase(base: base, dotExt: dotExt, maxWidth: availableWidth, font: font ?? UIFont.systemFont(ofSize: 17)) + + self.text = sanitizedFilename.replacingOccurrences(of: base, with: truncatedBase) + } + + private func truncateBase(base: String, dotExt: String, maxWidth: CGFloat, font: UIFont) -> String { + let extWidth = (dotExt as NSString).size(withAttributes: [.font: font]).width + + if (base as NSString).size(withAttributes: [.font: font]).width + extWidth <= maxWidth { + return base + } + + let characters = Array(base) + var low = 0 + var high = characters.count + var result = "" + + while low <= high { + let mid = (low + high) / 2 + let prefixCount = mid / 2 + let suffixCount = mid - prefixCount + let finalString = String(characters.prefix(prefixCount)) + "…" + String(characters.suffix(suffixCount)) + let finalStringWidth = (finalString as NSString).size(withAttributes: [.font: font]).width + extWidth + + if finalStringWidth <= maxWidth { + result = finalString + low = mid + 1 + } else { + high = mid - 1 + } + } + + return result + } +} diff --git a/iOSClient/Main/Collection Common/Cell/NCListCell.xib b/iOSClient/Main/Collection Common/Cell/NCListCell.xib index 0d02c3cfba..27786b0e3a 100755 --- a/iOSClient/Main/Collection Common/Cell/NCListCell.xib +++ b/iOSClient/Main/Collection Common/Cell/NCListCell.xib @@ -1,9 +1,8 @@ - + - - + @@ -60,7 +59,7 @@ -