Repository: Juanpe/SkeletonView
File: Sources/Extensions/CALayer+Extensions.swift (Swift)

Code before:
                                   paddingInsets: paddingInsets,
                                   alignment: config.alignment,
                                   isRTL: config.isRTL
            )
        }
    }

    private func calculatedWidthForLine(at index: Int, totalLines: Int, lastLineFillPercent: Int, paddingInsets: UIEdgeInsets) -> CGFloat {
        var width = bounds.width - paddingInsets.left - paddingInsets.right
        if index == totalLines - 1 && totalLines != 1 {
            width = width * CGFloat(lastLineFillPercent) / 100
        }
        return width
    }

    func updateLayerFrame(for index: Int, totalLines: Int, size: CGSize, multilineSpacing: CGFloat, paddingInsets: UIEdgeInsets, alignment: NSTextAlignment, isRTL: Bool) {
        let spaceRequiredForEachLine = size.height + multilineSpacing
        let newFrame = CGRect(x: paddingInsets.left,
                              y: CGFloat(index) * spaceRequiredForEachLine + paddingInsets.top,
                              width: size.width,
                              height: size.height)

        frame = flipRectForRTLIfNeeded(newFrame, isRTL: isRTL)

        // Align last line according to layer text alignment if not RTL
        if !isRTL && index == totalLines - 1 && totalLines != 1 {
            frame = alignLastLineRect(newFrame, alignment: alignment)
        }
    }
    
    private func calculateNumLines(for config: SkeletonMultilinesLayerConfig) -> Int {
        let definedNumberOfLines = config.lines
        let requiredSpaceForEachLine = config.lineHeight + config.multilineSpacing
        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
        }
        
        if definedNumberOfLines > 0, definedNumberOfLines <= calculatedNumberOfLines {
            return definedNumberOfLines
        }
        
        return calculatedNumberOfLines
    }

    private func alignLastLineRect(_ rect: CGRect, alignment: NSTextAlignment) -> CGRect {

Review comment (bug):
Hey @Juanpe 
I'm not sure this is the correct approach. Don't you think that `textAlignment` should be a priority regarding the position of the rectangles? If we define the alignment as `left`, `right`, `center`, it should be so. But if the alignment is `natural`, then it should reflect the current `RTL` state. ([reference](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/SupportingRight-To-LeftLanguages/SupportingRight-To-LeftLanguages.html))

I don't know if this would bring any undesired friction to what you already have and the RTL feature itself... So please let me know what you think would be best! 🙇🏼‍♀️

Code after:
                                   paddingInsets: paddingInsets,
                                   alignment: config.alignment,
                                   isRTL: config.isRTL
            )
        }
    }

    private func calculatedWidthForLine(at index: Int, totalLines: Int, lastLineFillPercent: Int, paddingInsets: UIEdgeInsets) -> CGFloat {
        var width = bounds.width - paddingInsets.left - paddingInsets.right
        if index == totalLines - 1 && totalLines != 1 {
            width = width * CGFloat(lastLineFillPercent) / 100
        }
        return width
    }

    func updateLayerFrame(for index: Int, totalLines: Int, size: CGSize, multilineSpacing: CGFloat, paddingInsets: UIEdgeInsets, alignment: NSTextAlignment, isRTL: Bool) {
        let spaceRequiredForEachLine = size.height + multilineSpacing
        let newFrame = CGRect(x: paddingInsets.left,
                              y: CGFloat(index) * spaceRequiredForEachLine + paddingInsets.top,
                              width: size.width,
                              height: size.height)

        if index == totalLines - 1 && totalLines != 1 {
            frame = alignLayerFrame(newFrame, alignment: alignment, isRTL: isRTL)
        } else {
            frame = newFrame
        }
    }
    
    private func calculateNumLines(for config: SkeletonMultilinesLayerConfig) -> Int {
        let definedNumberOfLines = config.lines
        let requiredSpaceForEachLine = config.lineHeight + config.multilineSpacing
        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
        }
        
        if definedNumberOfLines > 0, definedNumberOfLines <= calculatedNumberOfLines {
            return definedNumberOfLines
        }
        
        return calculatedNumberOfLines
    }

    private func alignLayerFrame(_ rect: CGRect, alignment: NSTextAlignment, isRTL: Bool) -> CGRect {
        var newRect = rect