From 36668f450b155c97da958dc5788c9149efaae7f8 Mon Sep 17 00:00:00 2001 From: Corey Davis Date: Mon, 12 Apr 2021 10:25:43 -0600 Subject: [PATCH] [BUG] Fix crashing on NaN value (#382) --- Sources/Extensions/CALayer+Extensions.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Extensions/CALayer+Extensions.swift b/Sources/Extensions/CALayer+Extensions.swift index ddb4f3ef..7fa88c05 100644 --- a/Sources/Extensions/CALayer+Extensions.swift +++ b/Sources/Extensions/CALayer+Extensions.swift @@ -125,8 +125,12 @@ extension CALayer { private func calculateNumLines(for config: SkeletonMultilinesLayerConfig) -> Int { let definedNumberOfLines = config.lines let requiredSpaceForEachLine = config.lineHeight + config.multilineSpacing - let calculatedNumberOfLines = Int(round(CGFloat(bounds.height - config.paddingInsets.top - config.paddingInsets.bottom) / CGFloat(requiredSpaceForEachLine))) - + let neededLines = round(CGFloat(bounds.height - config.paddingInsets.top - config.paddingInsets.bottom) / CGFloat(requiredSpaceForEachLine)) + guard neededLines.isNormal else { + return 0 + } + + let calculatedNumberOfLines = Int(neededLines) guard calculatedNumberOfLines > 0 else { return 1 }