mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 17:29:23 +00:00
Stop caching text measurements made at nonpositive widths since these are obviously wrong.
This commit is contained in:
1 parent
9256a6858a
commit
2dc650d449
4 files changed
+39
No files matched your search
@@ -51,6 +51,7 @@
|
||||
843E2F1B2CF2B8C500ED170F /* RSWeb in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 843E2F192CF2B8C500ED170F /* RSWeb */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
|
||||
843E2F1D2CF2B8D300ED170F /* RSWeb in Frameworks */ = {isa = PBXBuildFile; productRef = 843E2F1C2CF2B8D300ED170F /* RSWeb */; };
|
||||
84719F4C2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/ActivityItemSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84719F4B2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/ActivityItemSourceTests.swift */; };
|
||||
84719F4E2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84719F4D2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift */; };
|
||||
848E84CD2DB749440023F3BA /* RSCore in Frameworks */ = {isa = PBXBuildFile; productRef = 848E84CC2DB749440023F3BA /* RSCore */; };
|
||||
848E84CE2DB749440023F3BA /* RSCore in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 848E84CC2DB749440023F3BA /* RSCore */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
|
||||
848E84D02DB749440023F3BA /* RSCoreResources in Frameworks */ = {isa = PBXBuildFile; productRef = 848E84CF2DB749440023F3BA /* RSCoreResources */; };
|
||||
@@ -285,6 +286,7 @@
|
||||
844E47DC2E7DC72A0061A51A /* CODE_OF_CONDUCT.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CODE_OF_CONDUCT.md; sourceTree = "<group>"; };
|
||||
845B14A51FC2299E0013CF92 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
|
||||
84719F4B2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/ActivityItemSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tests/NetNewsWire-iOSTests/ActivityItemSourceTests.swift"; sourceTree = SOURCE_ROOT; };
|
||||
84719F4D2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Tests/NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift"; sourceTree = SOURCE_ROOT; };
|
||||
848CEF1E2DB74B56002B35B5 /* NetNewsWire-iOS.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "NetNewsWire-iOS.xctestplan"; sourceTree = "<group>"; };
|
||||
848E84C92DB743FF0023F3BA /* NetNewsWire-CI.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "NetNewsWire-CI.xctestplan"; sourceTree = "<group>"; };
|
||||
848E84CA2DB743FF0023F3BA /* NetNewsWire.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = NetNewsWire.xctestplan; sourceTree = "<group>"; };
|
||||
@@ -346,6 +348,7 @@
|
||||
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||
membershipExceptions = (
|
||||
"NetNewsWire-iOSTests/ActivityItemSourceTests.swift",
|
||||
"NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift",
|
||||
);
|
||||
target = 849C64701ED37A5D003D8FC0 /* NetNewsWireTests */;
|
||||
};
|
||||
@@ -566,6 +569,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
84719F4B2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/ActivityItemSourceTests.swift */,
|
||||
84719F4D2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift */,
|
||||
);
|
||||
name = "Recovered References";
|
||||
sourceTree = "<group>";
|
||||
@@ -1161,6 +1165,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
84719F4C2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/ActivityItemSourceTests.swift in Sources */,
|
||||
84719F4E2EE01A1100EEF332 /* Tests/NetNewsWire-iOSTests/MultilineUILabelSizerTests.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// MultilineUILabelSizerTests.swift
|
||||
// NetNewsWire-iOSTests
|
||||
//
|
||||
// Created by Brent Simmons on 8/6/26.
|
||||
//
|
||||
|
||||
import Testing
|
||||
import UIKit
|
||||
@testable import NetNewsWire
|
||||
|
||||
@MainActor @Suite struct MultilineUILabelSizerTests {
|
||||
|
||||
@Test func negativeWidthMeasurementIsNotCached() {
|
||||
MultilineUILabelSizer.emptyCache()
|
||||
|
||||
let string = "A title long enough that it must wrap onto more than one line at two hundred points wide."
|
||||
let font = UIFont.systemFont(ofSize: 17)
|
||||
|
||||
// A garbage-width measurement must return zero and must not be cached.
|
||||
let negativeWidthSize = MultilineUILabelSizer.size(for: string, font: font, numberOfLines: 3, width: -88)
|
||||
#expect(negativeWidthSize.size.height == 0)
|
||||
|
||||
// The same string at a real width must still wrap.
|
||||
let sized = MultilineUILabelSizer.size(for: string, font: font, numberOfLines: 3, width: 200)
|
||||
#expect(sized.numberOfLinesUsed > 1)
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,9 @@ final class MainTimelineCell: UICollectionViewCell {
|
||||
}
|
||||
|
||||
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
guard layoutAttributes.frame.width > 0 else {
|
||||
return layoutAttributes
|
||||
}
|
||||
let layout = updatedLayout(width: layoutAttributes.frame.width)
|
||||
layoutAttributes.frame.size.height = layout.height
|
||||
return layoutAttributes
|
||||
|
||||
@@ -71,6 +71,9 @@ private extension MultilineUILabelSizer {
|
||||
}
|
||||
|
||||
func height(for string: String, width: Int) -> Int {
|
||||
guard width > 0 else {
|
||||
return 0
|
||||
}
|
||||
if cache[string] == nil {
|
||||
cache[string] = WidthHeightCache()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user