Skip to content

Commit

Permalink
Collection - fix crash when tapping on a collection story with syndic…
Browse files Browse the repository at this point in the history
…ated article (#1069)

* fix(collections): prevent crash on adding the syndicated indicator due to an empty but not nil publisher

* fix(collections): improve comments
  • Loading branch information
Gio2018 committed Sep 3, 2024
1 parent cb76eca commit e42a616
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ extension CollectionStoryViewModel: ItemCellViewModel {
}

var domain: String? {
collectionStory.publisher
if let publisher = collectionStory.publisher, !publisher.isEmpty {
return publisher
}
return collectionStory.item?.bestDomain
}

var timeToRead: String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public extension NSMutableAttributedString {

private func calculateLineHeight(for image: UIImage) -> CGFloat {
var imageLineHeight: CGFloat = 0
if let font = self.attribute(.font, at: 0, effectiveRange: nil) as? UIFont {
// we need to check if the string is empty, otherwise the attirbute(_:, _:, _:) method will
// raise an exception whatever is the index, causing the app to crash
if !self.string.isEmpty, let font = self.attribute(.font, at: 0, effectiveRange: nil) as? UIFont {
/// See image to explain calculation here https://stackoverflow.com/questions/26105803/center-nstextattachment-image-next-to-single-line-uilabel
imageLineHeight = (font.capHeight - image.size.height) / 2
}
Expand Down

0 comments on commit e42a616

Please sign in to comment.