Skip to content

Commit 9e61ff3

Browse files
authored
Fix crash when text is empty (#483)
1 parent 204b871 commit 9e61ff3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

SkeletonViewCore/Sources/Internal/SkeletonExtensions/SkeletonTextNode.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ extension UILabel: SkeletonTextNode {
106106
}
107107

108108
var fontLineHeight: CGFloat? {
109-
if let attributes = attributedText?.attributes(at: 0, effectiveRange: nil),
110-
let fontAttribute = attributes.first(where: { $0.key == .font }) {
111-
return fontAttribute.value as? CGFloat ?? font.lineHeight
109+
if let attributedText = attributedText,
110+
attributedText.length > 0 {
111+
let attributes = attributedText.attributes(at: 0, effectiveRange: nil)
112+
let fontAttribute = attributes.first(where: { $0.key == .font })
113+
return fontAttribute?.value as? CGFloat ?? font.lineHeight
112114
} else {
113115
return font.lineHeight
114116
}
@@ -179,9 +181,11 @@ extension UITextView: SkeletonTextNode {
179181
}
180182

181183
var fontLineHeight: CGFloat? {
182-
if let attributes = attributedText?.attributes(at: 0, effectiveRange: nil),
183-
let fontAttribute = attributes.first(where: { $0.key == .font }) {
184-
return fontAttribute.value as? CGFloat ?? font?.lineHeight
184+
if let attributedText = attributedText,
185+
attributedText.length > 0 {
186+
let attributes = attributedText.attributes(at: 0, effectiveRange: nil)
187+
let fontAttribute = attributes.first(where: { $0.key == .font })
188+
return fontAttribute?.value as? CGFloat ?? font?.lineHeight
185189
} else {
186190
return font?.lineHeight
187191
}

0 commit comments

Comments
 (0)